diff --git a/debian/debian-essentials-scott.sh b/debian/debian-essentials-scott.sh new file mode 100755 index 0000000..1aa24e2 --- /dev/null +++ b/debian/debian-essentials-scott.sh @@ -0,0 +1,246 @@ +#!/bin/bash + +if [ "$EUID" -ne 0 ] + then + echo "Please run as root" + exit +fi + +# autoreply config update dialog with default answer no +if [[ ! -f /etc/apt/apt.conf.d/local ]] + then + echo "Dpkg::Options {" >> /etc/apt/apt.conf.d/local + echo " "--force-confdef";" >> /etc/apt/apt.conf.d/local + echo " "--force-confold";" >> /etc/apt/apt.conf.d/local + echo "}" >> /etc/apt/apt.conf.d/local +fi + +# update bookworm to new debian.sources file +if [[ -f /etc/apt/sources.list.d/debian.sources ]] + then + echo "Bookworm sources already updated." + else + isInFile=$(cat /etc/apt/sources.list | grep -c "bullseye") + if [ $isInFile -eq 0 ] + then + mkdir /etc/apt/mirrors > /dev/null 2>&1 + echo "https://deb.debian.org/debian" >> /etc/apt/mirrors/debian.list + echo "https://deb.debian.org/debian-security" >> /etc/apt/mirrors/debian-security.list + echo "Types: deb deb-src" >> /etc/apt/sources.list.d/debian.sources + echo "URIs: mirror+file:///etc/apt/mirrors/debian.list" >> /etc/apt/sources.list.d/debian.sources + echo "Suites: bookworm bookworm-updates bookworm-backports" >> /etc/apt/sources.list.d/debian.sources + echo "Components: main contrib non-free non-free-firmware" >> /etc/apt/sources.list.d/debian.sources + echo "" >> /etc/apt/sources.list.d/debian.sources + echo "Types: deb deb-src" >> /etc/apt/sources.list.d/debian.sources + echo "URIs: mirror+file:///etc/apt/mirrors/debian-security.list" >> /etc/apt/sources.list.d/debian.sources + echo "Suites: bookworm-security" >> /etc/apt/sources.list.d/debian.sources + echo "Components: main" >> /etc/apt/sources.list.d/debian.sources + mv /etc/apt/sources.list /etc/apt/sources.list.bak > /dev/null 2>&1 + rm /etc/apt/sources.list.11.backup > /dev/null 2>&1 + echo "Bookworm sources updated successfully." + else + echo "Bullseye detected, skipping sources update." + fi +fi + +# remove os prober +apt-get remove os-prober -y > /dev/null 2>&1 + +# update and upgrade +apt-get update +apt-get upgrade -y + +# check if vm or lxc +if [[ -f /dev/.lxc-boot-id ]] + then + apt-get remove -y qemu-guest-agent + else + apt-get install -y qemu-guest-agent +fi + +# download and install packages +apt-get install -y bind9-dnsutils restic hstr htop ncdu pwgen lsb-release cron sudo nano curl wget zip unzip git rsync man-db cifs-utils nfs-common parted libtalloc2 libwbclient0 net-tools gnupg apt-transport-https tmux gdisk bash-completion + +# add wettsten user if not existing +isInFile=$(cat /etc/passwd | grep -c "wettsten") +if [ $isInFile -eq 0 ] + then + echo "Set password for wettsten" + useradd -m -p '$6$rGI6DeTQ/SfWBQrR$JcYtt/tBq1xhe5lynqXHaNb6mNQ4G3UGlIkNZPPaHOUOuGRV/AbXwXkQacGd1bv9BpyW4aWARI0r7wz8n9ME6/' -s /bin/bash -d /home/wettsten wettsten + mkdir /home/wettsten/.ssh + chown wettsten:wettsten /home/wettsten/.ssh + chmod 700 /home/wettsten/.ssh + cp /root/.ssh/authorized_keys /home/wettsten/.ssh > /dev/null 2>&1 + chown wettsten:wettsten /home/wettsten/.ssh/authorized_keys > /dev/null 2>&1 + chmod 600 /home/wettsten/.ssh/authorized_keys > /dev/null 2>&1 +fi + +# create wettsten file in /etc/sudoers.d +if [[ ! -f /etc/sudoers.d/wettsten ]] + then + echo "wettsten ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/wettsten +fi +usermod -a -G sudo wettsten + +# enable ping for all users +setcap 'cap_net_admin,cap_net_raw+ep' $(which ping) + +# remove all motd +rm /etc/motd > /dev/null 2>&1 + +# disable systemd-networkd-wait-online.service +systemctl disable systemd-networkd-wait-online.service + +# git config +git config --global credential.helper store +git config --global user.name "akanealw" +git config --global user.email "akanealw@gmail.com" +git config --global init.defaultBranch main + +# show ip in /etc/issue +if [[ ! -f /etc/issue.default ]] + then wget -qO /etc/issue.default https://files.akanealw.com/debian/issue.default +fi +rm /etc/issue > /dev/null 2>&1 +cp /etc/issue.default /etc/issue +name=$(basename /sys/class/net/e*) +echo "" >> /etc/issue +echo "$name: \4{$name}" >> /etc/issue +echo "" >> /etc/issue + +# set input preferences +if [[ ! -f /etc/inputrc.default ]] + then wget -qO /etc/inputrc.default https://files.akanealw.com/debian/inputrc.default +fi +rm /etc/inputrc > /dev/null 2>&1 +cp /etc/inputrc.default /etc/inputrc +echo "" >> /etc/inputrc +echo "set completion-ignore-case On" >> /etc/inputrc + +# set bash preferences and aliases +if [[ ! -f /etc/bash.bashrc.default ]] + then wget -qO /etc/bash.bashrc.default https://files.akanealw.com/debian/bash.bashrc.default +fi +rm /etc/bash.bashrc > /dev/null 2>&1 +cp /etc/bash.bashrc.default /etc/bash.bashrc +echo "" >> /etc/bash.bashrc +echo "# custom settings and aliases" >> /etc/bash.bashrc +echo "set -o noclobber" >> /etc/bash.bashrc +echo "alias lsa='ls -alhvF'" >> /etc/bash.bashrc +echo "alias cd..='cd ..'" >> /etc/bash.bashrc +echo "alias grep='grep --color'" >> /etc/bash.bashrc +echo "alias si='sudo -i'" >> /etc/bash.bashrc +echo "alias mkdir='mkdir -pv'" >> /etc/bash.bashrc +echo "alias du='sudo du -h'" >> /etc/bash.bashrc +echo "alias df='sudo df -h'" >> /etc/bash.bashrc +echo "alias ports='sudo netstat -tulpna'" >> /etc/bash.bashrc +echo "alias start='sudo systemctl start'" >> /etc/bash.bashrc +echo "alias stop='sudo systemctl stop'" >> /etc/bash.bashrc +echo "alias restart='sudo systemctl restart'" >> /etc/bash.bashrc +echo "alias status='sudo systemctl status'" >> /etc/bash.bashrc +echo "alias sdr='sudo systemctl daemon-reload'" >> /etc/bash.bashrc +echo "alias senable='sudo systemctl enable'" >> /etc/bash.bashrc +echo "alias sdisable='sudo systemctl disable'" >> /etc/bash.bashrc +echo "alias snano='sudo nano'" >> /etc/bash.bashrc +echo "alias sreboot='sudo reboot'" >> /etc/bash.bashrc +echo "alias spoweroff='sudo poweroff'" >> /etc/bash.bashrc +echo "alias tf='sudo tail -f'" >> /etc/bash.bashrc +echo "alias aptupy='sudo apt update && sudo apt upgrade -y'" >> /etc/bash.bashrc +echo "alias aptiy='sudo apt install -y'" >> /etc/bash.bashrc +echo "alias aptry='sudo apt remove -y'" >> /etc/bash.bashrc +echo "alias aptrpy='sudo apt remove --purge -y'" >> /etc/bash.bashrc +echo "alias aptary='sudo apt autoremove -y'" >> /etc/bash.bashrc +echo "alias apts='sudo apt search'" >> /etc/bash.bashrc +echo "alias aptl='sudo apt list --installed'" >> /etc/bash.bashrc +echo "alias aptsh='sudo apt show'" >> /etc/bash.bashrc +echo "alias aptac='sudo apt autoclean'" >> /etc/bash.bashrc +echo "alias dpkgi='sudo dpkg -i'" >> /etc/bash.bashrc +echo "alias tmuxls='tmux ls'" >> /etc/bash.bashrc +echo "alias tmuxa='tmux attach -t'" >> /etc/bash.bashrc +echo "alias hh='hstr'" >> /etc/bash.bashrc +echo "export HSTR_CONFIG=hide-help,hicolor,prompt-bottom,ignorespace,raw-history-view" >> /etc/bash.bashrc + +# docker aliases +if [[ -f /etc/apt/keyrings/docker.gpg ]] + then + echo "alias dc='docker compose'" >> /etc/bash.bashrc + echo "alias dcup='docker compose up -d'" >> /etc/bash.bashrc + echo "alias dcdown='docker compose down'" >> /etc/bash.bashrc + echo "alias dcpull='docker compose pull'" >> /etc/bash.bashrc + echo "alias dps='docker ps'" >> /etc/bash.bashrc + echo "alias dstart='docker start'" >> /etc/bash.bashrc + echo "alias dstop='docker stop'" >> /etc/bash.bashrc + echo "alias drestart='docker restart'" >> /etc/bash.bashrc + echo "alias dlf='docker logs -f'" >> /etc/bash.bashrc + echo "alias dipaf='docker image prune -a -f'" >> /etc/bash.bashrc + echo "alias deit='docker exec -it'" >> /etc/bash.bashrc +fi + +# create copy of file before editing +if [[ ! -f /usr/local/bin/cpb ]]; then +cat <<'EOF' >> /usr/local/bin/cpb +#!/bin/bash + +if [ $# -eq 1 ] +then + cp -pvi "$1" "${1}.bak" +else + echo "Info: $0 copies to a backup file" + echo "Usage: $0 " +fi +EOF +chmod +x /usr/local/bin/cpb +fi + +# create tmux config +rm /etc/tmux.conf* > /dev/null 2>&1 +echo "unbind C-b" >> /etc/tmux.conf +echo "set-option -g prefix C-a" >> /etc/tmux.conf +echo "bind-key C-a send-prefix" >> /etc/tmux.conf + +# configure email for sending notifications +isInFile=$(cat /etc/postfix/main.cf | grep -c "gmail") +if [ $isInFile -eq 0 ] + then + DEBIAN_FRONTEND=noninteractive apt-get install -y libsasl2-modules mailutils postfix postfix-pcre + echo "smtp.gmail.com notify.akanealw@gmail.com:leawkqqpthbwacrf" > /etc/postfix/sasl_passwd + echo "/^From:.*/ REPLACE From: $(hostname) " > /etc/postfix/smtp_header_checks + chmod 600 /etc/postfix/sasl_passwd + postmap hash:/etc/postfix/sasl_passwd + postmap hash:/etc/postfix/smtp_header_checks + sed -i 's@relayhost =@#relayhost = @g' /etc/postfix/main.cf + sed -i 's@smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache@#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache@g' /etc/postfix/main.cf + echo "" >> /etc/postfix/main.cf + echo "# google mail configuration" >> /etc/postfix/main.cf + echo "relayhost = smtp.gmail.com:587" >> /etc/postfix/main.cf + echo "smtp_use_tls = yes" >> /etc/postfix/main.cf + echo "smtp_sasl_auth_enable = yes" >> /etc/postfix/main.cf + echo "smtp_sasl_security_options =" >> /etc/postfix/main.cf + echo "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" >> /etc/postfix/main.cf + echo "smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem" >> /etc/postfix/main.cf + echo "smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache" >> /etc/postfix/main.cf + echo "smtp_tls_session_cache_timeout = 3600s" >> /etc/postfix/main.cf + echo "smtp_header_checks = pcre:/etc/postfix/smtp_header_checks" >> /etc/postfix/main.cf + echo "" >> /etc/postfix/main.cf + postfix reload + echo "This is a test message sent from postfix on $(hostname)" | mail -s "Test Email from $(hostname)" akanealw@gmail.com + else + echo "Email already configured." +fi + +# configure unattended upgrades +isInFile=$(cat /etc/apt/apt.conf.d/20auto-upgrades | grep -c 'APT::Periodic::Unattended-Upgrade "1";') +if [ $isInFile -eq 0 ] + then + apt-get install -y apt-listchanges unattended-upgrades + sed -i 's@// "origin=Debian,codename=${distro_codename}-updates";@ "origin=Debian,codename=${distro_codename}-updates";@g' /etc/apt/apt.conf.d/50unattended-upgrades + sed -i 's!//Unattended-Upgrade::Mail "";!Unattended-Upgrade::Mail "akanealw@gmail.com";!g' /etc/apt/apt.conf.d/50unattended-upgrades + sed -i 's@//Unattended-Upgrade::MailReport "on-change";@Unattended-Upgrade::MailReport "on-change";@g' /etc/apt/apt.conf.d/50unattended-upgrades + sed -i 's@//Unattended-Upgrade::Remove-Unused-Dependencies "false";@Unattended-Upgrade::Remove-Unused-Dependencies "true";@g' /etc/apt/apt.conf.d/50unattended-upgrades + echo "APT::Periodic::Update-Package-Lists \"1\";" > /etc/apt/apt.conf.d/20auto-upgrades + echo "APT::Periodic::Unattended-Upgrade \"1\";" >> /etc/apt/apt.conf.d/20auto-upgrades + systemctl enable unattended-upgrades + systemctl start unattended-upgrades + else + echo "Unattended upgrades already configured." +fi