110 lines
3.3 KiB
Bash
110 lines
3.3 KiB
Bash
#!/bin/bash
|
|
|
|
# The purpose of this script is to setup our ISO server on a blank Armbian.
|
|
# This script is to be run as root.
|
|
# This script runs AFTER setup1.sh, which installs OMV and reboots the system
|
|
|
|
# YOU SHOULD REMOVE THIS SCRIPT AFTER SETUP
|
|
|
|
# Functions
|
|
set_hostname() {
|
|
echo $fqdn > /etc/hostname
|
|
}
|
|
|
|
install_packages() { # TODO these packages do not seem to exist as of 2021/10/10
|
|
echo "Starting packages installation"
|
|
apt install -y openmediavault-luksencryption openmediavault-downloader
|
|
}
|
|
|
|
add_users() {
|
|
echo "Adding users"
|
|
useradd -N -g users -G sudo,ssh,openmediavault-admin -m -s /bin/bash $user
|
|
chmod 700 /home/$user
|
|
}
|
|
|
|
set_sudo_conf() { # TODO that doesn't seem to work
|
|
echo "Setting sudo configuration"
|
|
sed -i -e "s/%sudo ALL=(ALL:ALL) ALL/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g" /etc/sudoers
|
|
}
|
|
|
|
get_conf() {
|
|
echo "Getting configuration"
|
|
sudo -H -u $user mkdir $sync_directory_path
|
|
cp $run_directory_path/conf-sync.sh $sync_directory_path/
|
|
chown $user:users $sync_directory_path/conf-sync.sh
|
|
sudo -H -u $user chmod u+x $sync_directory_path/conf-sync.sh
|
|
sudo -H -u $user $sync_directory_path/conf-sync.sh
|
|
}
|
|
|
|
set_conf() {
|
|
echo "Setting configuration"
|
|
#sudo -H -u $user chmod uo+x $sync_directory_path/clean-cloud.sh $sync_directory_path/scan-to-cloud.sh
|
|
ln -s $sync_directory_path/*.service $systemd_units_path/
|
|
ln -s $sync_directory_path/*.timer $systemd_units_path/
|
|
#ln -s $sync_directory_path/*.socket $systemd_units_path/
|
|
#ln -s $sync_directory_path/*.mount $systemd_units_path/
|
|
#ln -s $sync_directory_path/*.path $systemd_units_path/
|
|
systemctl daemon-reload
|
|
systemctl enable conf-sync.timer
|
|
}
|
|
|
|
rcs_links() {
|
|
echo "Linking rcs"
|
|
rm /home/$user/.bashrc
|
|
rm /root/.bashrc
|
|
sudo -H -u $user ln -s $sync_directory_path/bashrc /home/$user/.bashrc
|
|
ln -s /home/$user/.bashrc /root/.bashrc
|
|
sudo -H -u $user ln -s $sync_directory_path/vimrc /home/$user/.vimrc
|
|
ln -s /home/$user/.vimrc /root/.vimrc
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
# 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
|
|
fqdn='hk1.kto.black'
|
|
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'
|
|
|
|
# Main process
|
|
# You should comment below what you do not want to happen
|
|
set_hostname
|
|
install_packages
|
|
add_users
|
|
set_sudo_conf
|
|
get_conf
|
|
set_conf
|
|
rcs_links
|
|
ssh_pubkey
|
|
|
|
echo ""
|
|
echo "We're all good here!"
|
|
echo "You should now:"
|
|
echo "* set $user's password"
|
|
echo "* lock root and admin accounts"
|
|
echo "* remove $run_directory_path content"
|
|
echo "* reboot the SBC"
|
|
echo "* go to http://$fqdn/ to set up Openmediavault"
|
|
echo "* set up lighttpd"
|
|
echo "And perhaps:"
|
|
echo "* set htop at your convenience"
|
|
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" # NOTE This one is different from the others, because of OMV setup
|
|
exit 0
|