Skip to content

Instantly share code, notes, and snippets.

@wjz1095
Last active September 13, 2023 16:07
Show Gist options
  • Save wjz1095/36fe9c5dec1a311ed0f313c20446c962 to your computer and use it in GitHub Desktop.
Save wjz1095/36fe9c5dec1a311ed0f313c20446c962 to your computer and use it in GitHub Desktop.
Linux Updater Scripts
#This script will automatically restart the docker containers held within
#It is customized to my docker configuration but can easily be modified to work with any other docker setup
echo "" >> /var/log/apt_updates.log
date >> /var/log/apt_updates.log
echo "-----APT UPDATES RAN-----" >> /var/log/apt_updates.log
echo ""
echo "-----UPDATE-----"
apt update
echo ""
echo "-----UPGRADE-----"
apt upgrade
echo ""
echo "-----FULL-UPGRADE-----"
apt full-upgrade
echo ""
echo "-----DIST-UPGRADE-----"
apt dist-upgrade
echo ""
echo "-----AUTOREMOVE-----"
apt-get autoremove --purge
echo ""
echo "-----CLEAN-----"
apt clean
echo ""
echo "#####SELECTING 'YES' WILL STOP AND RESTART DOCKER CONTAINERS#####"
echo -n "Update docker containers? (y/n)"
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo "Updating docker containers..."
docker pull louislam/uptime-kuma:1
docker stop uptime-kuma
docker rm uptime-kuma
docker run -d --restart=always -p 3001:3001 -v uptime-kuma:/app/data --name uptime-kuma louislam/uptime-kuma:1
docker pull portainer/portainer-ce:latest
docker stop portainer
docker rm portainer
docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 \
--name=portainer --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:latest
else
echo "NOT updating docker containers"
fi
echo ""
cat /run/motd.dynamic | grep restart
echo "-----Container Status-----"
docker ps --format "table {{.Names}}\t{{.Status}}"
uptime
#Check if system needs restart, if yes, then ask user if they want to restart
if [ ! $(cat /run/motd.dynamic | grep restart) ] ; then
echo "No restart necessary."
echo "-----UPDATES COMPLETE-----"
uptime
else
echo "*****Restart RECOMMENDED*****"
echo -n "Restart now? (y/n)"
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo "REBOOTING IN 5 SECONDS"
sleep 5
reboot now
fi
fi
#This script is more of a monthly maintenance script
echo "" >> /var/log/apt_updates.log
date >> /var/log/apt_updates.log
echo "-----APT UPDATES RAN-----" >> /var/log/apt_updates.log
echo -e "\033[1;34m-----UPDATE-----\033[0m"
apt update
echo ""
echo -e "\033[1;36m-----UPGRADE-----\033[0m"
apt upgrade
echo ""
echo -e "\033[1;32m-----DIST-UPGRADE-----\033[0m"
apt dist-upgrade
echo ""
echo -e "\033[1;33m-----AUTOREMOVE-----\033[0m"
apt autoremove
echo ""
echo -e "\033[1;35m-----CLEAN-----\033[0m"
apt clean
echo ""
#APT updates finished
#Syncing time
timedatectl set-ntp true
echo ""
timedatectl status
echo ""
timedatectl status | grep "NTP service"
#More logging
uptime >> /var/log/apt_updates.log
echo "" >> /var/log/apt_updates.log
#Check if system needs restart, if yes, then ask user if they want to restart
if [ ! $(cat /run/motd.dynamic | grep restart) ] ; then
echo "No restart necessary."
echo "-----UPDATES COMPLETE-----"
uptime
else
echo "*****Restart RECOMMENDED*****"
echo -n "Restart now? (y/n)"
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo "REBOOTING IN 5 SECONDS"
sleep 5
reboot now
fi
fi
#No restart prompt, very basic
echo "" >> /var/log/apt_updates.log
date >> /var/log/apt_updates.log
echo "-----APT UPDATES RAN-----" >> /var/log/apt_updates.log
echo ""
echo "-----UPDATE-----"
apt update
echo ""
echo "-----UPGRADE-----"
apt upgrade
echo ""
echo "-----FULL-UPGRADE-----"
apt full-upgrade
echo ""
echo "-----DIST-UPGRADE-----"
apt dist-upgrade
echo ""
echo "-----AUTOREMOVE-----"
apt-get autoremove --purge
echo ""
echo "-----CLEAN-----"
apt clean
echo ""
echo "Clearing /tmp..."
find /tmp -ctime +10 exec rm rf {} +
echo ""
uptime
echo ""
#Syncing time
timedatectl set-ntp true
echo ""
timedatectl status
echo ""
timedatectl status | grep "NTP service"
#Restart check
cat /run/motd.dynamic | grep restart
echo "" >> /var/log/apt_updates.log
date >> /var/log/apt_updates.log
echo "-----APT UPDATES RAN-----" >> /var/log/apt_updates.log
echo ""
echo "-----UPDATE-----"
apt update
echo ""
echo "-----UPGRADE-----"
apt upgrade
echo ""
echo "-----DIST-UPGRADE-----"
apt dist-upgrade
echo ""
echo "-----AUTOREMOVE-----"
apt-get autoremove --purge
echo ""
echo "-----CLEAN-----"
apt clean
echo ""
pihole -up
echo ""
uptime
echo ""
cat /run/motd.dynamic | grep restart
echo -e "\033[1;31m------WARNING------"
echo "Warning: This script may restart Plex. Follow the prompts, and be sure no users are using it." read -rp "Press Enter to continue, or Control+C to stop now." key
echo -e "\033[0m"
echo -n "Stop Plex service? (y/n)"
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo "Stopping Plex..."
service plexmediaserver stop
service plexmediaserver status | grep Active
else
echo "NOT STOPPING PLEX"
service plexmediaserver status | grep Active
fi
echo "Starting APT updates..."
echo "" >> /var/log/apt_updates.log
date >> /var/log/apt_updates.log
echo "-----APT UPDATES RAN-----" >> /var/log/apt_updates.log
echo -e "\033[1;34m-----UPDATE-----\033[0m"
apt update
echo ""
echo -e "\033[1;36m-----UPGRADE-----\033[0m"
apt upgrade
echo ""
echo -e "\033[1;32m-----DIST-UPGRADE-----\033[0m"
apt dist-upgrade
echo ""
echo -e "\033[1;33m-----AUTOREMOVE-----\033[0m"
apt autoremove
echo ""
echo -e "\033[1;35m-----CLEAN-----\033[0m"
apt clean
echo ""
echo "APT updates finished"
#Check if system needs restart, if yes, then ask user if they want to restart
if [ ! $(cat /run/motd.dynamic | grep restart) ] ; then
echo "No restart necessary."
echo "-----UPDATES COMPLETE-----"
uptime
else
echo "*****Restart RECOMMENDED*****"
echo -n "Restart now? (y/n)"
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo "REBOOTING IN 5 SECONDS"
sleep 5
reboot now
fi
echo "#####If you did not restart, it is HIGHLY recommended you restart now#####"
fi
#Plex question
echo ""
echo "Plex Status:"
service plexmediaserver status | grep Active
echo -n "Start Plex service? (y/n) Not necessary if Plex is already running: "
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo "Starting Plex..."
service plexmediaserver start
service plexmediaserver status | grep Active
else
echo "NOT STARTING PLEX, it may already be running!"
service plexmediaserver status
fi
echo ""
echo "If you did not restart, it is HIGHLY recommended you restart now"
echo ""
echo "Disk space usage:"
df -h | grep /dev/mapper
uptime
echo ""
#Logging, stores plex media server version as well
dpkg --list | grep plexmediaserver >> /var/log/apt_updates.log
echo ""
uptime >> /var/log/apt_updates.log
echo "" >> /var/log/apt_updates.log
#!/bin/bash
#Updater tool for Security Onion
#https://github.com/Security-Onion-Solutions/security-onion/wiki/Upgrade
#NOTE: This cannot run in cron as it asks for input from the user so you will need to run it manually
#Enable byobu tool to allow script to run in case we get disconnected
byobu-enable
#Built-in updater tool
#DO NOT USE APT UPDATE, USE THIS TOOL
sudo soup
#Update snort rules
sudo rule-update
#Restart snort after install
sudo so-bro-restart
date >> /var/log/apt_updates.log
echo "-----APT UPDATES RAN-----" >> /var/log/apt_updates.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment