#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: https://mirrors.slickstack.io/bash/ss-update-modules.txt ############################## #### path: /var/www/ss-update-modules ############################################################## #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Updates and cleans up required Ubuntu packages including the Linux kernel ############ #### module version: Ubuntu 22.04 LTS ############################################################## #### sourced by: n/a ############################################################################### #### bash aliases: ss update|upgrade modules, ss update|upgrade packages ########################### #################################################################################################### ## YOU CAN SAFELY RUN UPDATES WITH NO CHANGES TO YOUR LEMP MODULE CONFIGURATION FILES ## ## IN CASE YOU ACCIDENTALLY OVERWRITE CONFIG FILES SIMPLY RUN SS-INSTALL AGAIN ## ## source ss-config ## source /var/www/ss-config ## source ss-functions ## source /var/www/ss-functions ## BELOW THIS RELIES ON SS-CONFIG AND SS-FUNCTIONS #################################################################################################### #### TABLE OF CONTENTS (SS-Update-Modules) ######################################################### #################################################################################################### ## this is a brief summary of the different code snippets you will find in this script ## ## each section should be commented so you understand what is being accomplished ## ## A. Touch Timestamp File ## B. Message (Begin Script) ## C. Backup MySQL Database Before Proceeding #################################################################################################### #### A. SS-Update-Modules: Touch Timestamp File #################################################### #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ## script timestamp ## ss_touch "${TIMESTAMP_SS_UPDATE_MODULES}" #################################################################################################### #### B. SS-Update-Modules: Message (Begin Script) ################################################## #################################################################################################### ## this is a simple message that announces to the shell the purpose of this bash script ## ## it will only be noticed by sudo users who manually call ss core bash scripts ## ## echo message ## ss_echo "${COLOR_INFO}Running ss-update-modules... ${COLOR_RESET}" #################################################################################################### #### C. SS-Update-Modules: Backup MySQL Database Before Proceeding ################################# #################################################################################################### ## here we first dump the live production database to /var/www/meta/ before proceeding ## ## this ensures a recent backup exists in case any database corruption occurs ## ## delete? ## ## run ss-dump-database ## # source "${PATH_SS_DUMP_DATABASE}" #################################################################################################### #### SS-Update: Retrieve Latest SS-Check + SS-Worker (Core Bash Scripts) ########################### #################################################################################################### ## here we run ss-check and ss-worker in case ss core cron jobs have not been running ## ## this ensures that all ss core bash scripts are updated before proceeding ## ## delete? ## ## run ss-check and ss-worker ## # source "${PATH_SS_CHECK}" # source "${PATH_SS_WORKER}" # source "${PATH_SS_CHECK}" #################################################################################################### #### SS-Update: Set Dpkg Basic Settings + Update Apt (Package) Cache ############################### #################################################################################################### ## for smoother execution and to avoid conflicts we set dpkg to noninteractive/confold ## ## it is much better to run ss-update instead of calling apt get upgrade manually ## ## set confold as dpkg default (fail-safe in case apt upgrade called directly) ## DEBIAN_FRONTEND=noninteractive dpkg --configure -a --force-confold #################################################################################################### #### SS-Update-Packages: Upgrade Ubuntu Packages + Linux Kernel #################################### #################################################################################################### ## the main purpose of ss-update is to upgrade all currently installed Ubuntu packages ## ## we use apt full-upgrade (not apt-get) in order to upgrade the Linux kernel ## ## clean apt cache ## ss_apt_clean ## update apt cache ## ss_apt_update ## upgrade apt packages (including linux kernel) ## ss_apt_full_upgrade ## remove unused dependencies ## ss_apt_autoremove #################################################################################################### #### SS-Update-Packages: Restart Modules (All Modules) ############################################# #################################################################################################### ## this script is using init.d instead of systemd shortcuts to allow for absolute paths ## ## we are looking into including other snippets here such as unmasking (etc) ## ## run ss-restart-php ## # source "${PATH_SS_RESTART_PHP}" ## run ss-restart-nginx ## # source "${PATH_SS_RESTART_NGINX}" ## run ss-restart-mysql ## # source "${PATH_SS_RESTART_MYSQL}" ## run ss-restart-redis ## # source "${PATH_SS_RESTART_REDIS}" #################################################################################################### #### PLACEHOLDER: Reset Permissions (SlickStack Scripts) ########################################### #################################################################################################### ## we include this permissions reset in all cron jobs and bash scripts for redundancy ## ## chmod 0700 means only the root/sudo users can execute any SlickStack scripts ## ## THIS SNIPPET DOES NOT RELY ON SS-CONFIG OR SS-FUNCTIONS ## SNIPPET: ss bash scripts, ss cron jobs ## UPDATED: 02JUL2022 chown root:root /var/www/ss* ## must be root:root chown root:root /var/www/crons/*cron* ## must be root:root chown root:root /var/www/crons/custom/*cron* ## must be root:root chmod 0700 /var/www/ss* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/*cron* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/custom/*cron* ## 0700 means only root/sudo can execute #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://linux.die.net/man/8/apt-get ## Ref: https://askubuntu.com/questions/1112555/is-apt-dist-upgrade-not-necessary-anymore ## Ref: https://unix.stackexchange.com/questions/467552/reboot-over-ssh/467996#467996 ## Ref: https://askubuntu.com/questions/254129/how-to-display-all-apt-get-dpkgoptions-and-their-current-values ## Ref: https://serverfault.com/questions/48724/100-non-interactive-debian-dist-upgrade ## Ref: https://askubuntu.com/questions/938359/apt-get-install-remove-update-upgrade-via-cron-job ## Ref: http://manpages.ubuntu.com/manpages/trusty/man8/apt.8.html ## Ref: https://www.debian.org/doc/manuals/apt-guide/index.en.html ## Ref: https://serverfault.com/questions/478461/how-to-install-packages-with-apt-without-user-interaction ## Ref: https://serverfault.com/questions/644180/what-does-qq-argument-for-apt-get-mean ## Ref: https://superuser.com/questions/1438031/ubuntu-18-command-apt-get-dist-upgrade-qq-force-yes-deprecated ## Ref: https://superuser.com/questions/1412054/non-interactive-apt-upgrade ## Ref: https://serverfault.com/questions/227190/how-do-i-ask-apt-get-to-skip-any-interactive-post-install-configuration-steps ## Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1253351 ## Ref: https://kb.cloudberrylab.com/backup-mac-linux/silent-install-macos-and-linux-builds ## Ref: https://unix.stackexchange.com/questions/32533/debian-how-to-delay-configuration-when-installing-upgrading ## Ref: https://raymii.org/s/tutorials/Silent-automatic-apt-get-upgrade.html ## Ref: https://unix.stackexchange.com/questions/138504/setting-path-vs-exporting-path-in-bash-profile ## Ref: https://askubuntu.com/questions/578568/path-error-in-ubuntu ## Ref: https://stackoverflow.com/questions/38977713/what-is-snap-bin-directory-in-path-can-i-remove-it-from-path ## Ref: https://askubuntu.com/questions/1121495/add-snap-bin-to-path-used-by-systemd ## Ref: https://askubuntu.com/questions/163200/e-dpkg-was-interrupted-run-sudo-dpkg-configure-a ## Ref: https://stackoverflow.com/questions/1305237/how-to-list-variables-declared-in-script-in-bash ## Ref: https://stackoverflow.com/questions/32739572/bash-search-and-replace-value-of-a-variable-inside-a-file ## Ref: https://askubuntu.com/questions/76808/how-do-i-use-variables-in-a-sed-command ## Ref: https://unix.stackexchange.com/questions/69112/how-can-i-use-variables-in-the-lhs-and-rhs-of-a-sed-substitution ## Ref: https://stackoverflow.com/questions/19151954/how-to-use-variables-in-a-command-in-sed ## Ref: https://unix.stackexchange.com/questions/47584/in-a-bash-script-using-the-conditional-or-in-an-if-statement ## Ref: https://stackoverflow.com/questions/11287861/how-to-check-if-a-file-contains-a-specific-string-using-bash ## Ref: https://stackoverflow.com/questions/25564051/how-to-compare-grep-result-with-a-variable ## Ref: https://stackoverflow.com/questions/26458121/grep-a-specific-string-from-bash-script-and-compare ## Ref: https://unix.stackexchange.com/questions/372733/get-output-and-return-value-of-grep-in-single-operation-in-bash ## Ref: https://stackoverflow.com/questions/18789907/read-values-from-configuration-file-and-use-in-shell-script ## Ref: https://stackoverflow.com/questions/38385963/sed-replacing-string-with-quotation-marks ## Ref: https://github.com/littlebizzy/slickstack/issues/36 ## Ref: http://manpages.ubuntu.com/manpages/bionic/man1/date.1.html ## Ref: https://crunchify.com/shell-script-append-timestamp-to-file-name/ ## Ref: https://stackoverflow.com/questions/6946677/grep-with-quotation-mark ## Ref: https://unix.stackexchange.com/questions/48535/can-grep-return-true-false-or-are-there-alternative-methods ## Ref: https://www.cyberciti.biz/faq/can-i-delete-var-cache-apt-archives-for-ubuntu-debian-linux/ ## Ref: https://linux.die.net/man/8/apt-get ## Ref: https://askubuntu.com/questions/1112555/is-apt-dist-upgrade-not-necessary-anymore ## Ref: https://unix.stackexchange.com/questions/467552/reboot-over-ssh/467996#467996 ## Ref: https://askubuntu.com/questions/254129/how-to-display-all-apt-get-dpkgoptions-and-their-current-values ## Ref: https://serverfault.com/questions/48724/100-non-interactive-debian-dist-upgrade ## Ref: https://askubuntu.com/questions/938359/apt-get-install-remove-update-upgrade-via-cron-job ## Ref: http://manpages.ubuntu.com/manpages/trusty/man8/apt.8.html ## Ref: https://www.debian.org/doc/manuals/apt-guide/index.en.html ## Ref: https://serverfault.com/questions/478461/how-to-install-packages-with-apt-without-user-interaction ## Ref: https://serverfault.com/questions/644180/what-does-qq-argument-for-apt-get-mean ## Ref: https://superuser.com/questions/1438031/ubuntu-18-command-apt-get-dist-upgrade-qq-force-yes-deprecated ## Ref: https://superuser.com/questions/1412054/non-interactive-apt-upgrade ## Ref: https://serverfault.com/questions/227190/how-do-i-ask-apt-get-to-skip-any-interactive-post-install-configuration-steps ## Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1253351 ## Ref: https://kb.cloudberrylab.com/backup-mac-linux/silent-install-macos-and-linux-builds ## Ref: https://unix.stackexchange.com/questions/32533/debian-how-to-delay-configuration-when-installing-upgrading ## Ref: https://raymii.org/s/tutorials/Silent-automatic-apt-get-upgrade.html ## Ref: https://unix.stackexchange.com/questions/138504/setting-path-vs-exporting-path-in-bash-profile ## Ref: https://askubuntu.com/questions/578568/path-error-in-ubuntu ## Ref: https://stackoverflow.com/questions/38977713/what-is-snap-bin-directory-in-path-can-i-remove-it-from-path ## Ref: https://askubuntu.com/questions/1121495/add-snap-bin-to-path-used-by-systemd ## Ref: https://askubuntu.com/questions/163200/e-dpkg-was-interrupted-run-sudo-dpkg-configure-a ## Ref: https://stackoverflow.com/questions/1305237/how-to-list-variables-declared-in-script-in-bash ## Ref: https://stackoverflow.com/questions/32739572/bash-search-and-replace-value-of-a-variable-inside-a-file ## Ref: https://askubuntu.com/questions/76808/how-do-i-use-variables-in-a-sed-command ## Ref: https://unix.stackexchange.com/questions/69112/how-can-i-use-variables-in-the-lhs-and-rhs-of-a-sed-substitution ## Ref: https://stackoverflow.com/questions/19151954/how-to-use-variables-in-a-command-in-sed ## Ref: https://unix.stackexchange.com/questions/47584/in-a-bash-script-using-the-conditional-or-in-an-if-statement ## Ref: https://stackoverflow.com/questions/11287861/how-to-check-if-a-file-contains-a-specific-string-using-bash ## Ref: https://stackoverflow.com/questions/25564051/how-to-compare-grep-result-with-a-variable ## Ref: https://stackoverflow.com/questions/26458121/grep-a-specific-string-from-bash-script-and-compare ## Ref: https://unix.stackexchange.com/questions/372733/get-output-and-return-value-of-grep-in-single-operation-in-bash ## Ref: https://stackoverflow.com/questions/18789907/read-values-from-configuration-file-and-use-in-shell-script ## Ref: https://stackoverflow.com/questions/38385963/sed-replacing-string-with-quotation-marks ## Ref: https://github.com/littlebizzy/slickstack/issues/36 ## Ref: http://manpages.ubuntu.com/manpages/bionic/man1/date.1.html ## Ref: https://crunchify.com/shell-script-append-timestamp-to-file-name/ ## Ref: https://stackoverflow.com/questions/6946677/grep-with-quotation-mark ## Ref: https://unix.stackexchange.com/questions/48535/can-grep-return-true-false-or-are-there-alternative-methods ## Ref: https://ubuntuforums.org/showthread.php?t=2243852 ## Ref: https://www.networkworld.com/article/3453032/cleaning-up-with-apt-get.html ## SS_EOF