2022-03-13 13:03:45 +01:00
|
|
|
#!/usr/bin/env bash
|
2021-11-12 15:53:21 +01:00
|
|
|
|
2021-11-12 18:27:14 +01:00
|
|
|
# The purpose of this script is to setup our NAS server on a blank Armbian.
|
2021-11-12 15:53:21 +01:00
|
|
|
# This script is to be run as root.
|
|
|
|
|
|
|
|
# (Keep in mind that default root password is 1234)
|
2021-11-12 18:27:14 +01:00
|
|
|
# Flash SBC's SD with Armbian and copy this script as well as conf-sync.sh to /root
|
2021-11-12 15:53:21 +01:00
|
|
|
|
|
|
|
# YOU SHOULD REMOVE THIS SCRIPT AFTER SETUP
|
|
|
|
|
2022-06-06 14:47:29 +02:00
|
|
|
source "$run_directory/variables.conf"
|
|
|
|
|
2021-11-12 15:53:21 +01:00
|
|
|
# Functions
|
|
|
|
init() {
|
|
|
|
echo "Starting initialization"
|
2021-11-15 17:58:52 +01:00
|
|
|
echo $fqdn > /etc/hostname
|
2021-11-12 15:53:21 +01:00
|
|
|
localectl set-keymap $keymap
|
|
|
|
timedatectl set-timezone $timezone
|
|
|
|
systemctl disable apt-daily-upgrade.timer
|
|
|
|
}
|
|
|
|
|
|
|
|
install_packages() {
|
|
|
|
echo "Starting packages installation"
|
|
|
|
sed -i -e "s/$deb_apt_default_repo/$deb_apt_repo/g" /etc/apt/sources.list
|
|
|
|
apt update
|
|
|
|
apt upgrade -y
|
2022-06-06 14:47:29 +02:00
|
|
|
packages_to_install="vim tree tmux neofetch cryptsetup clevis clevis-luks clevis-systemd"
|
|
|
|
if [ "$dl_server" = "yes" ]; then
|
|
|
|
packages_to_install+=" openvpn transmission-daemon"
|
|
|
|
fi
|
|
|
|
if [ "$upnp_server" = "yes" ]; then
|
|
|
|
packages_to_install+=" minidlna"
|
|
|
|
fi
|
|
|
|
if [ "$ftp_server" = "yes" ]; then
|
|
|
|
packages_to_install+=" vsftpd"
|
|
|
|
fi
|
|
|
|
apt install -y $packages_to_install
|
2021-11-12 15:53:21 +01:00
|
|
|
}
|
|
|
|
|
2021-11-12 18:27:14 +01:00
|
|
|
add_users() {
|
|
|
|
echo "Adding users"
|
2022-06-06 14:47:29 +02:00
|
|
|
useradd -U -G sudo -m -s /bin/bash $user
|
2021-11-12 18:27:14 +01:00
|
|
|
chmod 700 /home/$user
|
2022-06-06 14:47:29 +02:00
|
|
|
echo "Let's define a password for $user as we are about to run sudo with it. It can of course be changed after setup."
|
|
|
|
passwd $user
|
2021-11-12 18:27:14 +01:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:47:29 +02:00
|
|
|
get_sync() {
|
|
|
|
echo "Getting and deploying sync configuration"
|
2021-11-12 18:27:14 +01:00
|
|
|
sudo -H -u $user mkdir $sync_directory_path
|
2022-06-06 14:47:29 +02:00
|
|
|
sudo -H -u $user git clone https://gitea.kto.black/adminconf/rcs-general.git $sync_directory_path/rcs-general
|
|
|
|
sudo -H -u $user $sync_directory_path/rcs-general/install.sh
|
|
|
|
sudo -H -u $user git clone https://gitea.kto.black/adminconf/conf-sync.git $sync_directory_path/conf-sync
|
|
|
|
sudo -H -u $user cp $sync_directory_path/conf-sync/variables.conf.template \
|
|
|
|
$sync_directory_path/conf-sync/variables.conf
|
|
|
|
sudo -H -u $user sed -i -e "s/\"desktop\"/\"server\"/g" $sync_directory_path/conf-sync/variables.conf
|
|
|
|
sudo -H -u $user $sync_directory_path/conf-sync/install.sh
|
|
|
|
sudo -H -u $user git clone https://gitea.kto.black/adminconf/nas-server.git $sync_directory_path/nas-server
|
2021-11-12 18:27:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ssh_pubkey() {
|
|
|
|
echo "Getting SSH public key"
|
|
|
|
sudo -H -u $user mkdir /home/$user/.ssh
|
|
|
|
sudo -H -u $user wget -P /home/$user/.ssh $remote_pubkey_location/$remote_pubkey
|
|
|
|
sudo -H -u $user mv /home/$user/.ssh/$remote_pubkey /home/$user/.ssh/authorized_keys
|
2021-11-12 15:53:21 +01:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:47:29 +02:00
|
|
|
set_sshd_conf() {
|
|
|
|
echo "Editing OpenSSH daemon config..."
|
|
|
|
sed -i -e "s/#PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
|
|
|
|
sed -i -e "s/PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config
|
|
|
|
}
|
|
|
|
|
2021-11-12 19:32:49 +01:00
|
|
|
set_vsftpd() {
|
2022-06-06 14:47:29 +02:00
|
|
|
if [ "$ftp_server" != "yes" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
2021-11-12 19:32:49 +01:00
|
|
|
echo "Setting vsftpd config"
|
2021-11-15 17:58:52 +01:00
|
|
|
mkdir $nas_root
|
|
|
|
chown $user:users $nas_root
|
|
|
|
echo "nascrypt /dev/sda none noauto" >> /etc/crypttab
|
2021-11-12 19:32:49 +01:00
|
|
|
sed -i -e "s/#write_enable=YES/write_enable=YES/g" /etc/vsftpd.conf
|
|
|
|
sed -i -e "s/#utf8_filesystem=YES/utf8_filesystem=YES/g" /etc/vsftpd.conf
|
|
|
|
}
|
|
|
|
|
2021-11-12 15:53:21 +01:00
|
|
|
# Only run if the user is root
|
|
|
|
if [[ $USER != 'root' ]] ; then
|
|
|
|
echo "You must run this script as root!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
run_directory_path=$(pwd)
|
|
|
|
|
|
|
|
# Set parameters
|
2022-06-06 14:47:29 +02:00
|
|
|
fqdn='hk1.jab.kto.black'
|
2021-11-12 15:53:21 +01:00
|
|
|
keymap='fr'
|
|
|
|
timezone='Europe/Paris'
|
2022-06-06 14:47:29 +02:00
|
|
|
deb_apt_default_repo='deb.debian.org' # TODO check
|
2021-11-12 15:53:21 +01:00
|
|
|
deb_apt_repo='ftp.fr.debian.org'
|
2021-11-12 18:27:14 +01:00
|
|
|
user='alex'
|
|
|
|
sync_directory_path="/home/$user/.sync"
|
|
|
|
systemd_units_path='/etc/systemd/system'
|
|
|
|
remote_pubkey_location='https://keys.kto.black'
|
|
|
|
remote_pubkey='home.pub'
|
2021-11-15 17:58:52 +01:00
|
|
|
nas_root='/srv/nas'
|
2021-11-12 15:53:21 +01:00
|
|
|
|
|
|
|
# Main process
|
|
|
|
# You should comment below what you do not want to happen
|
|
|
|
init
|
|
|
|
install_packages
|
2021-11-12 18:27:14 +01:00
|
|
|
add_users
|
2022-06-06 14:47:29 +02:00
|
|
|
get_sync
|
2021-11-12 18:27:14 +01:00
|
|
|
ssh_pubkey
|
2022-06-06 14:47:29 +02:00
|
|
|
set_sshd_conf
|
2021-11-12 19:32:49 +01:00
|
|
|
set_vsftpd
|
2021-11-12 18:27:14 +01:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "We're all good here!"
|
|
|
|
echo "You should now:"
|
|
|
|
echo "* set $user's password"
|
|
|
|
echo "* lock root account"
|
2022-06-06 14:47:29 +02:00
|
|
|
echo "* remove $run_directory_path content"
|
|
|
|
if [ "$dl_server" = "yes" ]; then
|
|
|
|
echo "* get the OpenVPN configuration file, move it to /etc/openvpn/client/vpn.conf"
|
|
|
|
echo " * and add at \`auth-user-pass\`: auth.txt"
|
|
|
|
echo " * create said auth.txt with VPN login and password (on two rows)"
|
|
|
|
fi
|
2021-11-12 18:27:14 +01:00
|
|
|
echo "* reboot the SBC"
|
|
|
|
echo "And perhaps:"
|
|
|
|
echo "* set htop at your convenience"
|
|
|
|
echo "* remove password for sudo" # TODO we should automate that, with a flag
|
|
|
|
echo "* use below commands to edit SSH config:"
|
|
|
|
echo " sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config"
|
|
|
|
echo " sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config"
|
2021-11-15 17:58:52 +01:00
|
|
|
echo "* register an encrypted volume to a tang server"
|
2021-11-12 15:53:21 +01:00
|
|
|
|
|
|
|
exit 0
|