From ae3a85434d03e70abb9f5bfb98a16480d3015428 Mon Sep 17 00:00:00 2001 From: akanealw Date: Sun, 27 Aug 2023 11:37:12 -0500 Subject: [PATCH] updated scripts --- debian/debian-install-docker.sh | 1 + debian/debian-install-samba.sh | 1 + .../debian-regenerate-ssh-keys-machine-id.sh | 34 ++++++------- debian/debian-set-ip.sh | 51 +++++++++---------- debian/debian-setup-unattended-upgrades.sh | 1 + debian/debian-update-sources.sh | 5 +- ubuntu/ubuntu-install-docker.sh | 1 + ubuntu/ubuntu-install-samba.sh | 1 + .../ubuntu-regenerate-ssh-keys-machine-id.sh | 36 +++++++------ ubuntu/ubuntu-set-ip.sh | 34 +++++++------ 10 files changed, 83 insertions(+), 82 deletions(-) diff --git a/debian/debian-install-docker.sh b/debian/debian-install-docker.sh index c3339bf..c554b3b 100755 --- a/debian/debian-install-docker.sh +++ b/debian/debian-install-docker.sh @@ -18,6 +18,7 @@ if [[ ! -f /etc/apt/keyrings/docker.gpg ]] systemctl start containerd.service systemctl status docker.service systemctl status containerd.service + echo "Docker installed successfully." else echo "Docker is already configured." fi diff --git a/debian/debian-install-samba.sh b/debian/debian-install-samba.sh index 3f64bd0..8248f87 100755 --- a/debian/debian-install-samba.sh +++ b/debian/debian-install-samba.sh @@ -14,6 +14,7 @@ if [ $isInFile -eq 0 ] echo "" >> /etc/samba/smb.conf systemctl restart smbd systemctl status smbd + echo "Samba configured successfully." else echo "Samba is already configured." fi diff --git a/debian/debian-regenerate-ssh-keys-machine-id.sh b/debian/debian-regenerate-ssh-keys-machine-id.sh index 2811bd1..495900a 100644 --- a/debian/debian-regenerate-ssh-keys-machine-id.sh +++ b/debian/debian-regenerate-ssh-keys-machine-id.sh @@ -3,14 +3,13 @@ # ask to regenerate machine-id if [[ ! -f /etc/machine-id-regenerated ]] then - read -r -p "Regenerate machine-id? " prompt - if [[ "${prompt,,}" =~ ^(y|yes)$ ]] - then - rm -f /etc/machine-id /var/lib/dbus/machine-id - dbus-uuidgen --ensure=/etc/machine-id - dbus-uuidgen --ensure - touch /etc/machine-id-regenerated - fi + rm -f /etc/machine-id /var/lib/dbus/machine-id + dbus-uuidgen --ensure=/etc/machine-id + dbus-uuidgen --ensure + touch /etc/machine-id-regenerated + echo "Machine-id regenerated successfully." + else + echo "Machine-id not regenerated." fi # ask to regenerate ssh host keys @@ -18,15 +17,14 @@ if [[ ! -d /etc/cloud ]] then if [[ ! -f /home/akanealw/.ssh/ssh_keys_regenerated ]] then - read -r -p "Regenerate SSH Keys? " prompt - if [[ "${prompt,,}" =~ ^(y|yes)$ ]] - then - rm /etc/ssh/ssh_host_* - dpkg-reconfigure openssh-server - mkdir /home/akanealw/.ssh - touch /home/akanealw/.ssh/ssh_keys_regenerated - chmod 700 /home/akanealw/.ssh - chown -R akanealw:akanealw /home/akanealw/.ssh - fi + rm /etc/ssh/ssh_host_* + dpkg-reconfigure openssh-server + mkdir /home/akanealw/.ssh + touch /home/akanealw/.ssh/ssh_keys_regenerated + chmod 700 /home/akanealw/.ssh + chown -R akanealw:akanealw /home/akanealw/.ssh + echo "SSH host keys regenerated successfully." + else + echo "SSH host keys not regenerated." fi fi diff --git a/debian/debian-set-ip.sh b/debian/debian-set-ip.sh index 0dc921b..bacdaff 100755 --- a/debian/debian-set-ip.sh +++ b/debian/debian-set-ip.sh @@ -5,32 +5,27 @@ if [[ ! -d /etc/cloud ]] then if [[ ! -f /etc/network/interfaces.bak ]] then - read -r -p "Set Static IP address? " prompt - if [[ "${prompt,,}" =~ ^(y|yes)$ ]] - then - read -r -p "Enter Static IP Address with subnet prefix: " staticip - read -r -p "Enter Gateway IP Address: " gatewayip - read -r -p "Enter Primary DNS IP Address: " dnsip1 - read -r -p "Enter Secondary DNS IP Address: " dnsip2 - name=$(basename /sys/class/net/e*) - if [[ ! -f /etc/network/interfaces.bak ]] - then - cp /etc/network/interfaces /etc/network/interfaces.bak - fi - rm /etc/network/interfaces - cp /etc/network/interfaces.bak /etc/network/interfaces - sed -i "s,^iface $name inet dhcp*,iface $name inet static," /etc/network/interfaces - echo " address $staticip" >> /etc/network/interfaces - echo " gateway $gatewayip" >> /etc/network/interfaces - if [[ ! -f /etc/resolv.conf.bak ]] - then - cp /etc/resolv.conf /etc/resolv.conf.bak - fi - rm /etc/resolv.conf - echo "nameserver $dnsip1" >> /etc/resolv.conf - echo "nameserver $dnsip2" >> /etc/resolv.conf - ifdown $name - ifup $name - fi + read -r -p "Enter Static IP Address with subnet mask: " staticip + read -r -p "Enter Gateway IP Address: " gatewayip + read -r -p "Enter Primary DNS IP Address: " dnsip1 + read -r -p "Enter Secondary DNS IP Address: " dnsip2 + name=$(basename /sys/class/net/e*) + cp /etc/network/interfaces /etc/network/interfaces.bak + rm /etc/network/interfaces + cp /etc/network/interfaces.bak /etc/network/interfaces + sed -i "s,^iface $name inet dhcp*,iface $name inet static," /etc/network/interfaces + echo " address $staticip" >> /etc/network/interfaces + echo " gateway $gatewayip" >> /etc/network/interfaces + cp /etc/resolv.conf /etc/resolv.conf.bak + rm /etc/resolv.conf + echo "nameserver $dnsip1" >> /etc/resolv.conf + echo "nameserver $dnsip2" >> /etc/resolv.conf + ifdown $name + ifup $name + echo "Static IP set successfully." + else + echo "Static IP not set." fi -fi \ No newline at end of file + else + echo "Static IP not set." +fi diff --git a/debian/debian-setup-unattended-upgrades.sh b/debian/debian-setup-unattended-upgrades.sh index 0b90acb..67e6967 100644 --- a/debian/debian-setup-unattended-upgrades.sh +++ b/debian/debian-setup-unattended-upgrades.sh @@ -13,6 +13,7 @@ if [ $isInFile -eq 0 ] systemctl enable unattended-upgrades systemctl start unattended-upgrades systemctl status unattended-upgrades + echo "Unattended upgrades configured successfully." else echo "Unattended upgrades already configured." fi diff --git a/debian/debian-update-sources.sh b/debian/debian-update-sources.sh index eace5d6..b1aa831 100644 --- a/debian/debian-update-sources.sh +++ b/debian/debian-update-sources.sh @@ -3,7 +3,7 @@ # update bookworm to new debian.sources file if [[ -f /etc/apt/sources.list.d/debian.sources ]] then - echo "Sources already updated" + echo "Sources already updated." else isInFile=$(cat /etc/apt/sources.list | grep -c "bullseye") if [ $isInFile -eq 0 ] @@ -22,7 +22,8 @@ if [[ -f /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" + echo "Bullseye detected, skipping sources update." fi fi diff --git a/ubuntu/ubuntu-install-docker.sh b/ubuntu/ubuntu-install-docker.sh index 1eb346a..bcb47e4 100755 --- a/ubuntu/ubuntu-install-docker.sh +++ b/ubuntu/ubuntu-install-docker.sh @@ -18,6 +18,7 @@ if [[ ! -f /etc/apt/keyrings/docker.gpg ]] systemctl start containerd.service systemctl status docker.service systemctl status containerd.service + echo "Docker installed successfully." else echo "Docker is already configured." fi diff --git a/ubuntu/ubuntu-install-samba.sh b/ubuntu/ubuntu-install-samba.sh index 873ae84..7db3a3f 100755 --- a/ubuntu/ubuntu-install-samba.sh +++ b/ubuntu/ubuntu-install-samba.sh @@ -14,6 +14,7 @@ if [ $isInFile -eq 0 ] echo "" >> /etc/samba/smb.conf systemctl restart smbd systemctl status smbd + echo "Samba configured successfully." else echo "Samba is already configured." fi diff --git a/ubuntu/ubuntu-regenerate-ssh-keys-machine-id.sh b/ubuntu/ubuntu-regenerate-ssh-keys-machine-id.sh index 2811bd1..cc04c4f 100644 --- a/ubuntu/ubuntu-regenerate-ssh-keys-machine-id.sh +++ b/ubuntu/ubuntu-regenerate-ssh-keys-machine-id.sh @@ -3,30 +3,28 @@ # ask to regenerate machine-id if [[ ! -f /etc/machine-id-regenerated ]] then - read -r -p "Regenerate machine-id? " prompt - if [[ "${prompt,,}" =~ ^(y|yes)$ ]] - then - rm -f /etc/machine-id /var/lib/dbus/machine-id - dbus-uuidgen --ensure=/etc/machine-id - dbus-uuidgen --ensure - touch /etc/machine-id-regenerated - fi -fi + rm -f /etc/machine-id /var/lib/dbus/machine-id + dbus-uuidgen --ensure=/etc/machine-id + dbus-uuidgen --ensure + touch /etc/machine-id-regenerated + echo "Machine-id regenerated successfully." + else + echo "Machine-id not regenerated." + fi # ask to regenerate ssh host keys if [[ ! -d /etc/cloud ]] then if [[ ! -f /home/akanealw/.ssh/ssh_keys_regenerated ]] then - read -r -p "Regenerate SSH Keys? " prompt - if [[ "${prompt,,}" =~ ^(y|yes)$ ]] - then - rm /etc/ssh/ssh_host_* - dpkg-reconfigure openssh-server - mkdir /home/akanealw/.ssh - touch /home/akanealw/.ssh/ssh_keys_regenerated - chmod 700 /home/akanealw/.ssh - chown -R akanealw:akanealw /home/akanealw/.ssh - fi + rm /etc/ssh/ssh_host_* + dpkg-reconfigure openssh-server + mkdir /home/akanealw/.ssh + touch /home/akanealw/.ssh/ssh_keys_regenerated + chmod 700 /home/akanealw/.ssh + chown -R akanealw:akanealw /home/akanealw/.ssh + echo "SSH host keys regenerated successfully." + else + echo "SSH host keys not regenerated." fi fi diff --git a/ubuntu/ubuntu-set-ip.sh b/ubuntu/ubuntu-set-ip.sh index 3713364..d43236c 100755 --- a/ubuntu/ubuntu-set-ip.sh +++ b/ubuntu/ubuntu-set-ip.sh @@ -1,16 +1,17 @@ # ask to set static ip address -read -r -p "Set Static IP address? " prompt -if [[ "${prompt,,}" =~ ^(y|yes)$ ]] ; then -read -r -p "Enter Static IP Address with subnet prefix: " staticip -read -r -p "Enter Gateway IP Address: " gatewayip -read -r -p "Enter DNS IP Address (separated by commas): " dnsip -# get adapter name -name=$(basename /sys/class/net/e*) -# backup original netplan yaml file -mv /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak > /dev/null 2>&1 -rm /etc/netplan/01-network-manager-all.yaml > /dev/null 2>&1 -# create new netplan yaml file -cat >> /etc/netplan/01-network-manager-all.yaml < /dev/null 2>&1 + rm /etc/netplan/01-network-manager-all.yaml > /dev/null 2>&1 + # create new netplan yaml file + cat >> /etc/netplan/01-network-manager-all.yaml <