2021-10-22 16:04:48 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# The purpose of this script is to setup our print-scan server on a blank Armbian.
|
|
|
|
# This script is to be run as root.
|
|
|
|
|
|
|
|
# (Keep in mind that default root password is 1234)
|
|
|
|
# Flash SBC's SD with Armbian and copy this script as well as conf-sync.sh to /root
|
|
|
|
|
|
|
|
# YOU SHOULD REMOVE THIS SCRIPT AFTER SETUP
|
|
|
|
|
|
|
|
# Functions
|
|
|
|
init() {
|
|
|
|
echo "Starting initialization"
|
|
|
|
echo $fqdn > /etc/hostname
|
|
|
|
sed -i -e "s/$default_hostname/$fqdn $hostname/g" /etc/hosts
|
|
|
|
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
|
2021-10-31 13:09:56 +01:00
|
|
|
apt install -y vim tree tmux neofetch sane sane-utils hplip
|
2021-10-22 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
add_users() {
|
|
|
|
echo "Adding users"
|
|
|
|
useradd -U -G sudo,lpadmin -m -s /bin/bash $user
|
|
|
|
chmod 700 /home/$user
|
2021-10-31 13:09:56 +01:00
|
|
|
usermod -a -G lp saned
|
2021-10-22 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
2022-03-11 16:08:54 +01:00
|
|
|
get_conf() { # TODO when new conf-sync will be available
|
2021-10-22 16:04:48 +02:00
|
|
|
echo "Getting configuration"
|
|
|
|
sudo -H -u $user mkdir $sync_directory_path
|
2022-03-11 16:08:54 +01:00
|
|
|
|
|
|
|
git clone https://gitea.kto.black/adminconf/rcs-general.git $sync_directory_path/rcs-general
|
|
|
|
# git clone confsync-du-futur
|
2021-10-22 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
2022-03-11 16:08:54 +01:00
|
|
|
set_conf() { # TODO when new conf-sync will be available
|
2021-10-22 16:04:48 +02:00
|
|
|
echo "Setting configuration"
|
2022-03-11 16:08:54 +01:00
|
|
|
# deploy confsync-du-futur
|
2021-10-22 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
set_cups_conf() {
|
|
|
|
echo "Setting CUPS configuration"
|
|
|
|
mv $cups_conf_path/cupsd.conf $cups_conf_path/cupsd.conf.orig
|
2022-03-11 16:08:54 +01:00
|
|
|
cp $run_directory_path/cupsd.conf $cups_conf_path/cupsd.conf
|
2021-10-22 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
2022-03-11 16:08:54 +01:00
|
|
|
set_sane_conf() {
|
2021-10-31 13:36:44 +01:00
|
|
|
systemctl enable saned.socket
|
|
|
|
}
|
|
|
|
|
2022-03-11 16:08:54 +01:00
|
|
|
rcs_links() { # NOTE this should be handled by an install script in rcs-general
|
2021-10-22 16:04:48 +02:00
|
|
|
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
|
2021-10-31 13:09:56 +01:00
|
|
|
sudo -H -u $user ln -s $sync_directory_path/tmux.conf /home/$user/.tmux.conf
|
|
|
|
ln -s /home/$user/.tmux.conf /root/.tmux.conf
|
2021-10-22 16:04:48 +02: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
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
default_hostname='pine64'
|
|
|
|
hostname='pn1'
|
2022-03-11 16:08:54 +01:00
|
|
|
fqdn='pn1.hr.kto.black'
|
2021-10-22 16:04:48 +02:00
|
|
|
keymap='fr'
|
|
|
|
timezone='Europe/Paris'
|
2021-11-20 13:52:29 +01:00
|
|
|
deb_apt_default_repo='deb.debian.org'
|
2021-10-22 16:04:48 +02:00
|
|
|
deb_apt_repo='ftp.fr.debian.org'
|
|
|
|
user='alex'
|
|
|
|
sync_directory_path="/home/$user/.sync"
|
|
|
|
systemd_units_path='/etc/systemd/system'
|
|
|
|
cups_conf_path='/etc/cups'
|
|
|
|
remote_pubkey_location='https://keys.kto.black'
|
|
|
|
remote_pubkey='home.pub'
|
|
|
|
|
|
|
|
# Main process
|
|
|
|
# You should comment below what you do not want to happen
|
|
|
|
init
|
|
|
|
install_packages
|
|
|
|
add_users
|
|
|
|
get_conf
|
|
|
|
set_conf
|
|
|
|
set_cups_conf
|
2021-10-31 13:36:44 +01:00
|
|
|
set_sane_conf
|
2021-10-22 16:04:48 +02:00
|
|
|
rcs_links
|
|
|
|
ssh_pubkey
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "We're all good here!"
|
|
|
|
echo "You should now:"
|
|
|
|
echo "* set $user's password"
|
|
|
|
echo "* lock root account"
|
2022-03-11 16:08:54 +01:00
|
|
|
echo "* remove setup.sh"
|
2021-10-22 16:04:48 +02:00
|
|
|
echo "* reboot the SBC"
|
|
|
|
echo "And perhaps:"
|
|
|
|
echo "* connect to http://$hostname:631/ and add a printer"
|
|
|
|
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:"
|
2021-11-20 13:52:29 +01:00
|
|
|
echo " sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config"
|
|
|
|
echo " sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config"
|
2022-03-11 16:08:54 +01:00
|
|
|
echo "* MIND THAT CONF-SYNC IS NOT SET"
|
2021-10-22 16:04:48 +02:00
|
|
|
exit 0
|