2021-04-11 23:47:00 +02:00
#!/usr/bin/env bash
# author: Daniel Sommer <daniel.sommer@velvettear.de>
# license: MIT
# variables
swappiness = "25"
tmpfs_size = "1G"
# execution
printf "|>> executing debian install script...\n"
[ [ " $INSTALL_USERNAME " ] ] && printf " |> username set to ' $INSTALL_USERNAME ' via environment variable'...\n " && user = " $INSTALL_USERNAME "
if [ [ ! " $user " ] ] ; then
read -p "|> enter your desired username: " user
[ [ ! " $user " ] ] && printf "|> error: no username entered\n" && exit 1
fi
[ [ " $INSTALL_PASSWORD " ] ] && printf " |> password set to ' $( printf " $INSTALL_PASSWORD \n " | sed "s/./\*/g" ) ' via environment variable'...\n " && password = " $INSTALL_PASSWORD "
if [ [ ! " $password " ] ] ; then
read -s -p " |> enter the password for ' $user ': " password && printf "\n"
[ [ ! " $password " ] ] && printf "|> error: no password entered\n" && exit 1
read -s -p "|> confirm the password: " password_confirmation && printf "\n"
[ [ " $password_confirmation " != " $password " ] ] && printf "|> error: passwords do not match\n" && exit 1
fi
printf "|> updating packages...\n"
apt-get update -y
printf "|> upgrading installed packages...\n"
apt-get upgrade -y
printf "|> installing base packages...\n"
apt-get install -y \
sudo \
tzdata \
zsh \
htop \
iotop \
iftop \
neovim \
curl \
wget \
git \
unzip \
rsync \
dropbear \
2021-04-12 00:11:47 +02:00
openssh-client
2021-04-11 23:47:00 +02:00
read -p "|> enter additional packages to install: " packages
[ [ " $packages " ] ] && packages = " $( printf " $packages " | tr '\n' ' ' ) " && apt-get install -y $packages
2021-10-14 15:31:56 +02:00
print "|> cleaning up...\n"
2021-04-12 00:28:32 +02:00
apt-get clean -y
apt-get autoremove --purge -y
rm -rf "/var/cache/apt/*"
2021-04-11 23:47:00 +02:00
printf "|> setting timezone...\n"
rm -f "/etc/localtime"
ln -s "/usr/share/zoneinfo/Europe/Berlin" "/etc/localtime"
printf "|> changing shell from 'ash' to 'zsh'...\n"
sed -i "s/\/bin\/bash/\/bin\/zsh/g" "/etc/passwd"
printf " |> creating user ' $user '...\n "
useradd -m -g users -s "/bin/zsh" " $user "
printf " |> setting password for user ' $user '...\n "
echo -e " $password \n $password " | passwd " $user "
2023-09-27 11:50:48 +02:00
printf " |> adding user ' $user ' to group 'disk'...\n " && gpasswd -a " $user " disk > /dev/null
printf " |> adding user ' $user ' to group 'lp'...\n " && gpasswd -a " $user " lp > /dev/null
printf " |> adding user ' $user ' to group 'wheel'...\n " && gpasswd -a " $user " wheel > /dev/null
printf " |> adding user ' $user ' to group 'floppy'...\n " && gpasswd -a " $user " floppy > /dev/null
printf " |> adding user ' $user ' to group 'audio'...\n " && gpasswd -a " $user " audio > /dev/null
printf " |> adding user ' $user ' to group 'cdrom'...\n " && gpasswd -a " $user " cdrom > /dev/null
printf " |> adding user ' $user ' to group 'dialout'...\n " && gpasswd -a " $user " dialout > /dev/null
printf " |> adding user ' $user ' to group 'tape'...\n " && gpasswd -a " $user " tape > /dev/null
printf " |> adding user ' $user ' to group 'video'...\n " && gpasswd -a " $user " video > /dev/null
printf " |> adding user ' $user ' to group 'netdev'...\n " && gpasswd -a " $user " netdev > /dev/null
printf " |> adding user ' $user ' to group 'games'...\n " && gpasswd -a " $user " games > /dev/null
printf " |> adding user ' $user ' to group 'sudo'...\n " && gpasswd -a " $user " sudo > /dev/null
2021-04-11 23:47:00 +02:00
printf "|> modifying sudoers...\n"
sed -i "s/# %sudo ALL=(ALL) ALL/%sudo ALL=(ALL) ALL/" "/etc/sudoers"
2021-04-14 10:20:13 +02:00
printf "|> disabling root login via ssh...\n"
sed -i "s/DROPBEAR_EXTRA_ARGS.*/DROPBEAR_EXTRA_ARGS=\"-w\"/" "/etc/default/dropbear"
2021-04-11 23:47:00 +02:00
[ [ -r " $HOME /.ssh/authorized_keys " ] ] && printf " |> moving authorized ssh keys from ' $USER ' to ' $user '...\n " && mkdir -p " /home/ $user /.ssh " & > /dev/null && mv " $HOME /.ssh/authorized_keys " " /home/ $user /.ssh/authorized_keys " && chown -R " $user " :users " /home/ $user /.ssh "
printf "|> creating dropbear keys...\n"
mkdir -p "/etc/dropbear" & > /dev/null
dropbearkey -t "rsa" -s "4096" -f "/etc/dropbear/dropbear_rsa_host_key"
dropbearkey -t "dss" -s "1024" -f "/etc/dropbear/dropbear_dss_host_key"
dropbearkey -t "ecdsa" -s "521" -f "/etc/dropbear/dropbear_ecdsa_host_key"
2021-04-12 00:24:50 +02:00
printf "|> disabling sshd...\n"
systemctl disable sshd
2021-04-11 23:47:00 +02:00
printf "|> enabling and starting dropbear...\n"
2021-04-14 10:20:13 +02:00
sed -i "s/NO_START.*/NO_START=\"0\"/" "/etc/default/dropbear"
2021-04-11 23:47:00 +02:00
systemctl enable dropbear --now
[ [ " $swappiness " ] ] && printf "|> tuning swappiness...\n" && printf "vm.swappiness=" $swappiness "" > "/etc/sysctl.d/99-swappiness.conf"
printf "|> cleaning '/etc/fstab'...\n"
rm -rf "/etc/fstab"
touch "/etc/fstab"
options = "defaults,noatime"
[ [ " $tmpfs_size " ] ] && options = " $options ,size= $tmpfs_size "
printf "|> setting up '/var/cache' as tmpfs...\n" && rm -rf "/var/cache/*" & > /dev/null && printf " cache\t/var/cache\ttmpfs\t $options 0 0\n " >> "/etc/fstab"
printf "|> setting up '/var/log' as tmpfs...\n" && rm -rf "/var/log/*" & > /dev/null && printf " logs\t/var/log\ttmpfs\t $options 0 0\n " >> "/etc/fstab"
printf "|> setting up '/tmp' as tmpfs...\n" && rm -rf "/tmp/*" & > /dev/null && printf " tmp\t/tmp\ttmpfs\t $options ,mode=1777 0 0\n " >> "/etc/fstab"
printf "|> remounting '/etc/fstab' entries...\n"
mount -a
printf "|> customizing environment...\n"
2021-10-15 10:40:55 +02:00
git clone -b "lxc-debian" "https://git.velvettear.de/velvettear/etc.git" "/etc/velvettear"
2021-04-11 23:47:00 +02:00
chown -R " $user " :users "/etc/velvettear"
ln -s "/etc/velvettear/shell/zshrc.sh" " /home/ $user /.zshrc "
ln -s "/etc/velvettear/shell/zshrc_root.sh" "/root/.zshrc"
ln -s "/etc/velvettear/shell/zprofile" " /home/ $user /.zprofile "
ln -s "/etc/velvettear/shell/zprofile" "/root/.zprofile"
2021-04-14 10:21:15 +02:00
printf "|> removing motd...\n"
rm -f "/etc/motd"
2021-04-11 23:47:00 +02:00
printf "|>> debian install script finished!\n"
printf " |>> remote access: 'ssh $user @ $( ip -f inet -o address | awk '/eth0/ {print $4}' | cut -d "/" -f1) '\n "
read -p "|> would you like to delete the install script? [YES/no] " prompt
2021-04-12 00:11:47 +02:00
[ [ " $prompt " ] ] && prompt = " ${ prompt ,, } "
2021-04-11 23:47:00 +02:00
[ [ ! " $prompt " ] ] || [ [ " $prompt " = = "y" ] ] || [ [ "prompt" = = "yes" ] ] && printf " |> deleting script ' $0 '...\n " && rm -f " $0 "
read -p "|> would you like to reboot now? [YES/no] " prompt
2021-04-12 00:11:47 +02:00
[ [ " $prompt " ] ] && prompt = " ${ prompt ,, } "
2021-04-11 23:47:00 +02:00
[ [ ! " $prompt " ] ] || [ [ " $prompt " = = "y" ] ] || [ [ " $prompt " = = "yes" ] ] && printf "|> rebooting now!\n" && reboot