2024-07-18 19:24:22 +00:00
#!/bin/bash -e
# "-e" tries to exit right away on error.
2024-07-18 02:26:11 +00:00
2024-07-18 09:19:38 +00:00
# Upgrade IIAB core software (apt updates, Ansible, Admin Console, etc).
2024-07-18 02:26:11 +00:00
2024-07-18 09:19:38 +00:00
# Also with a focus on upgrading IIAB Calibre-Web, if that's installed:
2024-07-18 02:26:11 +00:00
# https://github.com/iiab/calibre-web/wiki
2024-07-18 17:37:24 +00:00
# 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
2024-07-18 02:26:11 +00:00
2024-07-18 17:37:24 +00:00
{
if [[ $(id -un) != "root" ]]; then
2024-07-18 18:16:39 +00:00
echo -e "\nPlease run: sudo iiab-update\n"
exit 1
2024-07-18 02:26:11 +00:00
fi
2024-07-18 17:37:24 +00:00
2024-07-18 02:26:11 +00:00
if [[ $1 == "-f" || $1 == "--fast" ]]; then
2024-07-18 18:16:39 +00:00
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"
2024-07-18 02:26:11 +00:00
else
2024-07-19 10:26:19 +00:00
echo -e "\n\n\e[44;1mUpgrading IIAB core software: (apt updates, Ansible, Admin Console, etc)\e[0m\n"
2024-07-18 18:16:39 +00:00
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"
apt update
echo -e "\n\e[4mNow running: apt dist-upgrade -y\e[0m\n"
apt dist-upgrade -y
echo -e "\n\e[4mNow running: apt autoremove -y\e[0m\n"
apt autoremove -y
2024-07-18 02:26:11 +00:00
fi
2024-07-18 17:37:24 +00:00
cd /opt/iiab/iiab
2024-07-18 20:28:14 +00:00
if [[ $(git branch --show-current) != "master" || $(git status --porcelain --untracked-files=no) != "" ]]; then # Permit detritus, e.g. untracked files like adm-run-roles-tmp.yml
2024-07-18 18:16:39 +00:00
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
2024-07-18 17:37:24 +00:00
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
2024-10-01 23:58:33 +00:00
echo
if grep -q 'tailscale_installed: True' /etc/iiab/iiab_state.yml; then
echo -e "\e[4mNow running: cp -u roles/tailscale/templates/iiab-vpn /usr/bin\e[0m\n"
cp -u roles/tailscale/templates/iiab-vpn /usr/bin
fi
2024-07-18 17:37:24 +00:00
if [[ $1 == "-f" || $1 == "--fast" ]]; then # Otherwise ./runrole does it below! (as Ansible runs roles/0-init)
2024-07-18 18:16:39 +00:00
cd scripts
2024-10-01 23:58:33 +00:00
echo -e "\e[4mNow running: cp -u iiab-update iiab-summary iiab-diagnostics iiab-root-login /usr/bin\e[0m\n"
2024-08-07 05:03:29 +00:00
cp -u iiab-update iiab-summary iiab-diagnostics iiab-root-login /usr/bin
2024-07-18 17:37:24 +00:00
fi
2024-07-18 02:26:11 +00:00
if [[ $1 == "-f" || $1 == "--fast" ]]; then
2024-07-19 10:26:19 +00:00
echo -e "\n\e[33m'iiab-update -f' DOES NOT upgrade Ansible.\e[0m\n\n"
2024-07-18 02:26:11 +00:00
else
2024-07-18 18:16:39 +00:00
echo -e "\n\n\e[4mNow running: scripts/ansible\e[0m"
scripts/ansible
2024-07-18 17:37:24 +00:00
fi
if grep -q 'calibreweb_installed: True' /etc/iiab/iiab_state.yml; then
2024-07-18 18:16:39 +00:00
if [[ $1 == "-f" || $1 == "--fast" ]]; then
2024-12-16 02:00:30 +00:00
echo -e "\e[4mChecking if an older version of 'library' (formerly 'xklb') exists...\e[0m"
if pipx list | grep -q 'xklb'; then
echo -e "\e[4mOlder version 'xklb' detected. Now running: pipx uninstall xklb\e[0m"
pipx uninstall xklb
fi
2024-12-16 12:25:06 +00:00
echo -e "\e[4mNow running: pipx uninstall library # THIS ALSO UNINSTALLS yt-dlp\e[0m\n"
pipx uninstall library || true
2024-12-13 23:50:35 +00:00
echo -e "\n\e[4mNow running: pipx install library # THIS ALSO INSTALLS yt-dlp\e[0m\n"
pipx install library
2024-07-20 15:52:53 +00:00
echo -e "\n\e[4mNow running: yt-dlp --version\e[0m\n"
yt-dlp --version
2024-12-13 23:50:35 +00:00
echo -e '\n\e[4mNeed better YouTube scraping? Run this for the latest yt-dlp "nightly" release:\e[0m\n\n\e[1mpipx inject --pip-args="--upgrade --pre" -f library yt-dlp[default]\e[0m\n'
2024-07-20 17:43:35 +00:00
# NEED BETTER/EXPERIMENTAL YouTube SCRAPING? UNCOMMENT THE NEXT LINE:
2024-12-13 23:50:35 +00:00
# pipx inject --pip-args="--upgrade --pre" -f library yt-dlp[default]
2024-07-20 17:43:35 +00:00
#
# https://github.com/yt-dlp/yt-dlp-nightly-builds/releases
# https://pypi.org/project/yt-dlp/#history
2024-07-20 15:52:53 +00:00
cd /usr/local/calibre-web-py3
if [[ $(git branch --show-current) != "master" || $(git status --porcelain --untracked-files=no) != "" ]]; then # Permit venv detritus, e.g. untracked files like these 5: bin/ include/ lib/ lib64 pyvenv.cfg
2024-07-20 17:43:35 +00:00
echo -e "\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
2024-07-20 15:52:53 +00:00
fi
echo -e "\e[4mNow running: systemctl stop calibre-web\e[0m\n"
systemctl stop calibre-web
echo -e "\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
2024-07-19 10:26:19 +00:00
echo -e "\n\e[4mNow running: bin/pip install -r requirements.txt --prefer-binary\e[0m\n"
bin/pip install -r requirements.txt --prefer-binary > /dev/null
echo -e "\e[4mNow running: systemctl restart calibre-web\e[0m\n"
2024-07-18 17:37:24 +00:00
systemctl restart calibre-web
2024-07-18 18:16:39 +00:00
else
2024-07-19 10:26:19 +00:00
cd /opt/iiab/iiab
2024-07-18 18:16:39 +00:00
echo -e "\n\e[4mNow running: ./runrole --reinstall calibre-web\e[0m\n"
2024-07-18 17:37:24 +00:00
./runrole --reinstall calibre-web
2024-07-18 18:16:39 +00:00
fi
2024-07-18 02:26:11 +00:00
fi
2024-07-18 17:37:24 +00:00
# 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
2024-07-18 18:16:39 +00:00
if [[ $1 == "-f" || $1 == "--fast" ]]; then
echo -e "\n\e[33m'iiab-update -f' DOES NOT upgrade Admin Console.\e[0m"
else
cd /opt/iiab/iiab-admin-console
if [[ $(git branch --show-current) != "master" || $(git status --porcelain) != "" ]]; then
echo -e "\n\n\e[41;1mIn /opt/iiab/iiab-admin-console, (1) 'git branch' MUST show current branch 'master' and (2) 'git status' must show NO MODIFIED FILES.\e[0m\n\n"
exit 1
fi
2024-07-19 05:19:00 +00:00
GITHASH1=$(git rev-parse HEAD)
2024-07-18 18:16:39 +00:00
echo -e "\n\e[4mNow running: git pull https://github.com/iiab/iiab-admin-console --no-rebase --no-edit\e[0m\n"
git pull https://github.com/iiab/iiab-admin-console --no-rebase --no-edit
2024-07-19 05:19:00 +00:00
GITHASH2=$(git rev-parse HEAD)
if [[ $GITHASH1 != $GITHASH2 ]]; then
echo -e "\n\e[4mNow running: ./install\e[0m\n"
./install
else
echo -e "\n\e[33mSkipping Admin Console './install' — as it appears up-to-date!\e[0m"
fi
2024-07-18 18:16:39 +00:00
fi
2024-07-18 17:37:24 +00:00
fi
2024-07-19 10:26:19 +00:00
if [[ $1 == "-f" || $1 == "--fast" ]]; then
echo -e "\n\n\e[44;1m'iiab-update -f' COMPLETE!\e[0m\n"
echo -e "\e[44;1mIf Calibre-Web fails, please try 'iiab-update' WITHOUT '-f'\e[0m\n\n" # \e[7m == reverse video (e.g. black on white)
else
echo -e "\n\n\e[44;1miiab-update COMPLETE!\e[0m\n\n"
fi
2024-07-18 17:37:24 +00:00
exit # https://stackoverflow.com/questions/2285403/how-to-make-shell-scripts-robust-to-source-being-changed-as-they-run
}