mirror of
				https://github.com/iiab/iiab.git
				synced 2025-03-09 15:40:17 +00:00 
			
		
		
		
	Preload all of iiab-update (bash script) into RAM for safety
This commit is contained in:
		
							parent
							
								
									3d6a116352
								
							
						
					
					
						commit
						1e1998cb14
					
				
					 1 changed files with 101 additions and 91 deletions
				
			
		| 
						 | 
				
			
			@ -5,15 +5,21 @@
 | 
			
		|||
# Also with a focus on upgrading IIAB Calibre-Web, if that's installed:
 | 
			
		||||
# https://github.com/iiab/calibre-web/wiki
 | 
			
		||||
 | 
			
		||||
if [[ $(id -un) != "root" ]]; then
 | 
			
		||||
# 2024-07-18 fixes underway, thanks to:
 | 
			
		||||
# https://stackoverflow.com/questions/21096478/overwrite-executing-bash-script-files
 | 
			
		||||
# https://stackoverflow.com/questions/2285403/how-to-make-shell-scripts-robust-to-source-being-changed-as-they-run
 | 
			
		||||
# https://stackoverflow.com/questions/2336977/can-a-shell-script-indicate-that-its-lines-be-loaded-into-memory-initially
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
    if [[ $(id -un) != "root" ]]; then
 | 
			
		||||
	echo -e "\nPlease run: sudo iiab-update\n"
 | 
			
		||||
	exit 1
 | 
			
		||||
fi
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
if [[ $1 == "-f" || $1 == "--fast" ]]; then
 | 
			
		||||
    if [[ $1 == "-f" || $1 == "--fast" ]]; then
 | 
			
		||||
	echo -e "\n\n\e[44;1mAttempting a FAST upgrade of IIAB Calibre-Web...\e[0m\n"
 | 
			
		||||
	echo -e "\n\e[33m'iiab-update -f' DOES NOT apply apt updates.\e[0m"
 | 
			
		||||
else
 | 
			
		||||
    else
 | 
			
		||||
	echo -e "\n\n\e[44;1mUpgrade IIAB core software: (apt updates, Ansible, Admin Console, etc)\e[0m\n"
 | 
			
		||||
	echo -e "\n\e[44;1mOr try 'iiab-update -f' for a FAST upgrade of IIAB Calibre-Web!\e[0m\n\n"
 | 
			
		||||
	echo -e "\e[4mNow running: apt update\e[0m\n"
 | 
			
		||||
| 
						 | 
				
			
			@ -22,29 +28,29 @@ else
 | 
			
		|||
	apt dist-upgrade -y
 | 
			
		||||
	echo -e "\n\e[4mNow running: apt autoremove -y\e[0m\n"
 | 
			
		||||
	apt autoremove -y
 | 
			
		||||
fi
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
cd /opt/iiab/iiab
 | 
			
		||||
if [[ $(git branch --show-current) != "master" || $(git status --porcelain) != "" ]]; then
 | 
			
		||||
    cd /opt/iiab/iiab
 | 
			
		||||
    if [[ $(git branch --show-current) != "master" || $(git status --porcelain) != "" ]]; then
 | 
			
		||||
	echo -e "\n\n\e[41;1mIn /opt/iiab/iiab, (1) 'git branch' MUST show current branch 'master' and (2) 'git status' must show NO MODIFIED FILES.\e[0m\n\n"
 | 
			
		||||
	exit 1
 | 
			
		||||
fi
 | 
			
		||||
echo -e "\n\n\e[4mNow running: git pull https://github.com/iiab/iiab --no-rebase --no-edit\e[0m\n"
 | 
			
		||||
git pull https://github.com/iiab/iiab --no-rebase --no-edit
 | 
			
		||||
if [[ $1 == "-f" || $1 == "--fast" ]]; then    # Otherwise ./runrole and ./install do it below! (as Ansible runs roles/0-init)
 | 
			
		||||
    fi
 | 
			
		||||
    echo -e "\n\n\e[4mNow running: git pull https://github.com/iiab/iiab --no-rebase --no-edit\e[0m\n"
 | 
			
		||||
    git pull https://github.com/iiab/iiab --no-rebase --no-edit
 | 
			
		||||
    if [[ $1 == "-f" || $1 == "--fast" ]]; then    # Otherwise ./runrole does it below! (as Ansible runs roles/0-init)
 | 
			
		||||
	cd scripts
 | 
			
		||||
	echo -e "\n\e[4mNow running: cp iiab-update iiab-summary iiab-diagnostics /usr/bin\e[0m\n"
 | 
			
		||||
	cp iiab-update iiab-summary iiab-diagnostics /usr/bin
 | 
			
		||||
fi
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
if [[ $1 == "-f" || $1 == "--fast" ]]; then
 | 
			
		||||
    if [[ $1 == "-f" || $1 == "--fast" ]]; then
 | 
			
		||||
	echo -e "\n\e[33m'iiab-update -f' DOES NOT upgrade Ansible.\e[0m\n"
 | 
			
		||||
else
 | 
			
		||||
    else
 | 
			
		||||
	echo -e "\n\n\e[4mNow running: scripts/ansible\e[0m"
 | 
			
		||||
	scripts/ansible
 | 
			
		||||
fi
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
if grep -q 'calibreweb_installed: True' /etc/iiab/iiab_state.yml; then
 | 
			
		||||
    if grep -q 'calibreweb_installed: True' /etc/iiab/iiab_state.yml; then
 | 
			
		||||
	if [[ $1 == "-f" || $1 == "--fast" ]]; then
 | 
			
		||||
            echo -e "\n\e[1mIf you want a COMPLETE reinstall of Calibre-Web, then also run:\n\n\e[0m\e[7mcd /opt/iiab/iiab ; ./runrole --reinstall calibre-web\e[0m\n"
 | 
			
		||||
	fi
 | 
			
		||||
| 
						 | 
				
			
			@ -61,6 +67,7 @@ if grep -q 'calibreweb_installed: True' /etc/iiab/iiab_state.yml; then
 | 
			
		|||
	    echo -e "\n\n\e[41;1mIn /usr/local/calibre-web-py3, (1) 'git branch' MUST show current branch 'master' and (2) 'git status' must show NO MODIFIED FILES.\e[0m\n\n"
 | 
			
		||||
	    exit 1
 | 
			
		||||
	fi
 | 
			
		||||
	systemctl stop calibre-web
 | 
			
		||||
	echo -e "\n\e[4mNow running: git pull https://github.com/iiab/calibre-web --no-rebase --no-edit\e[0m\n"
 | 
			
		||||
	git pull https://github.com/iiab/calibre-web --no-rebase --no-edit
 | 
			
		||||
	cd /opt/iiab/iiab
 | 
			
		||||
| 
						 | 
				
			
			@ -71,29 +78,29 @@ if grep -q 'calibreweb_installed: True' /etc/iiab/iiab_state.yml; then
 | 
			
		|||
	    echo -e "\n\e[4mNow running: ./runrole --reinstall calibre-web\e[0m\n"
 | 
			
		||||
            ./runrole --reinstall calibre-web
 | 
			
		||||
	fi
 | 
			
		||||
fi
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
# 2024-07-17: Run Admin Console stanza last for safety -- it failed ~50% of the
 | 
			
		||||
# time over 20 tests for me -- leading to 3+ different kinds of errors right
 | 
			
		||||
# after "(Restarting CMDSRV" e.g. "syntax error near unexpected token" was the
 | 
			
		||||
# most common error -- once the error was "command not found" -- and another
 | 
			
		||||
# time Admin Console's ./install VERY MYSTERIOUSLY RAN TWICE!
 | 
			
		||||
#
 | 
			
		||||
# Any chance this get_oer2go_catalog error ~15 lines up...might be related ?
 | 
			
		||||
#
 | 
			
		||||
# ...
 | 
			
		||||
# Finished writing to /etc/iiab/kiwix_catalog.json
 | 
			
		||||
# SUCCESS/opt/admin/cmdsrv/scripts/get_oer2go_catalog:52: SyntaxWarning: invalid escape sequence '\<'
 | 
			
		||||
#   php_parser = re.compile('\<\?php echo .+? \?>')
 | 
			
		||||
# Skipping module not needed by Internet in a Box 12 en-PhET
 | 
			
		||||
# ...
 | 
			
		||||
# [ ~15 lines ]
 | 
			
		||||
# ...
 | 
			
		||||
# (Restarting CMDSRV
 | 
			
		||||
# ...
 | 
			
		||||
# [ VARIOUS ERRORS SOMETIMES HAPPEN HERE ]
 | 
			
		||||
    # 2024-07-17: Run Admin Console stanza last for safety -- it failed ~50% of the
 | 
			
		||||
    # time over 20 tests for me -- leading to 3+ different kinds of errors right
 | 
			
		||||
    # after "(Restarting CMDSRV" e.g. "syntax error near unexpected token" was the
 | 
			
		||||
    # most common error -- once the error was "command not found" -- and another
 | 
			
		||||
    # time Admin Console's ./install VERY MYSTERIOUSLY RAN TWICE!
 | 
			
		||||
    #
 | 
			
		||||
    # Any chance this get_oer2go_catalog error ~15 lines up...might be related ?
 | 
			
		||||
    #
 | 
			
		||||
    # ...
 | 
			
		||||
    # Finished writing to /etc/iiab/kiwix_catalog.json
 | 
			
		||||
    # SUCCESS/opt/admin/cmdsrv/scripts/get_oer2go_catalog:52: SyntaxWarning: invalid escape sequence '\<'
 | 
			
		||||
    #   php_parser = re.compile('\<\?php echo .+? \?>')
 | 
			
		||||
    # Skipping module not needed by Internet in a Box 12 en-PhET
 | 
			
		||||
    # ...
 | 
			
		||||
    # [ ~15 lines ]
 | 
			
		||||
    # ...
 | 
			
		||||
    # (Restarting CMDSRV
 | 
			
		||||
    # ...
 | 
			
		||||
    # [ VARIOUS ERRORS SOMETIMES HAPPEN HERE ]
 | 
			
		||||
 | 
			
		||||
if [ -d /opt/admin ]; then
 | 
			
		||||
    if [ -d /opt/admin ]; then
 | 
			
		||||
	if [[ $1 == "-f" || $1 == "--fast" ]]; then
 | 
			
		||||
	    echo -e "\n\e[33m'iiab-update -f' DOES NOT upgrade Admin Console.\e[0m"
 | 
			
		||||
	else
 | 
			
		||||
| 
						 | 
				
			
			@ -107,6 +114,9 @@ if [ -d /opt/admin ]; then
 | 
			
		|||
	    echo -e "\n\e[4mNow running: ./install\e[0m\n"
 | 
			
		||||
	    ./install
 | 
			
		||||
	fi
 | 
			
		||||
fi
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
echo -e "\n\n\e[44;1miiab-update COMPLETE!\e[0m\n\n"
 | 
			
		||||
    echo -e "\n\n\e[44;1miiab-update COMPLETE!\e[0m\n\n"
 | 
			
		||||
 | 
			
		||||
    exit    # https://stackoverflow.com/questions/2285403/how-to-make-shell-scripts-robust-to-source-being-changed-as-they-run
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue