1
0
Fork 0
ynh-apps_tools/maintenance.sh

104 lines
2.7 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2024-09-13 20:28:40 +02:00
set -Eeuo pipefail
2024-09-13 20:28:40 +02:00
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
2024-09-13 20:28:40 +02:00
update_venv() {
2024-08-30 13:49:39 +02:00
if [ -d "venv" ]; then
venv/bin/pip install -r requirements.txt >/dev/null
2024-08-30 13:49:39 +02:00
fi
}
2024-09-13 20:28:40 +02:00
update_apps_repo() {
if [ -d ".apps" ]; then
git -C .apps pull
else
git clone https://github.com/YunoHost/apps.git .apps
fi
}
update_apps_cache() {
2024-09-13 22:07:14 +02:00
./app_caches.py -d -l .apps -c .apps_cache -j20
2024-09-13 20:28:40 +02:00
}
git_pull_and_restart_services() {
commit="$(git rev-parse HEAD)"
2024-09-09 17:24:10 +02:00
if ! git pull &>/dev/null; then
2024-09-13 20:28:40 +02:00
sendxmpppy "[apps-tools] Couldn't pull, maybe local changes are present?"
2024-09-09 17:24:10 +02:00
exit 1
fi
2024-09-13 20:28:40 +02:00
if [[ "$(git rev-parse HEAD)" == "$commit" ]]; then
return
fi
2024-09-13 20:28:40 +02:00
# Cron
cat cron | sed "s@__BASEDIR__@$SCRIPT_DIR@g" > /etc/cron.d/apps_tools
2024-09-13 20:28:40 +02:00
pushd app_generator > /dev/null
2024-08-30 13:49:39 +02:00
update_venv
2024-09-13 20:43:54 +02:00
pushd static >/dev/null
./tailwindcss-linux-x64 --input tailwind-local.css --output tailwind.css --minify
popd >/dev/null
2024-09-13 20:28:40 +02:00
popd > /dev/null
systemctl restart appgenerator
sleep 3
systemctl --quiet is-active appgenerator || sendxmpppy "[appgenerator] Uhoh, failed to (re)start the appgenerator service?"
2024-08-30 13:49:39 +02:00
update_venv
2024-09-13 20:48:02 +02:00
systemctl restart yunohost_app_webhooks
2024-09-13 20:28:40 +02:00
sleep 3
2024-09-13 20:48:02 +02:00
systemctl --quiet is-active yunohost_app_webhooks || sendxmpppy "[autoreadme] Uhoh, failed to (re)start the autoreadme service?"
}
2024-09-13 20:28:40 +02:00
rebuild_catalog_error_msg="[list_builder] Rebuilding the application list failed miserably!"
rebuild_catalog() {
date
2024-09-13 20:36:06 +02:00
update_apps_repo
update_apps_cache
2024-09-13 22:27:30 +02:00
venv/bin/python3 list_builder.py -l .apps -c .apps_cache ../catalog/default
}
2024-09-13 20:28:40 +02:00
autoupdate_app_sources_error_msg="[autoupdate_app_sources] App sources auto-update failed miserably!"
autoupdate_app_sources() {
date
2024-09-13 20:36:06 +02:00
update_apps_repo
update_apps_cache
2024-09-13 22:27:30 +02:00
venv/bin/python3 autoupdate_app_sources/autoupdate_app_sources.py \
2024-09-13 20:43:20 +02:00
-l .apps -c .apps_cache --latest-commit-weekly --edit --commit --pr --paste -j1
}
2024-09-13 20:28:40 +02:00
update_app_levels_error_msg="[update_app_levels] Updating apps level failed miserably!"
update_app_levels() {
date
2024-09-13 20:36:06 +02:00
update_apps_repo
update_apps_cache
2024-09-14 14:17:42 +02:00
venv/bin/python3 update_app_levels/update_app_levels.py -r "git@github.com:YunoHost/apps.git" -c .apps_cache
}
2024-09-13 20:28:40 +02:00
safe_run() {
logfile="$SCRIPT_DIR/$1.log"
error_msg_var="${1}_error_msg"
2024-09-13 20:37:00 +02:00
if ! "$@" &>> "$logfile"; then
2024-09-13 20:28:40 +02:00
sendxmpppy "${!error_msg_var}"
fi
}
2024-09-13 20:28:40 +02:00
main() {
cd "$SCRIPT_DIR"
# Update self, then re-exec to prevent an issue with modified bash scripts
if [[ -z "${APPS_TOOLS_UPDATED:-}" ]]; then
git_pull_and_restart_services
APPS_TOOLS_UPDATED=1 exec "$0" "$@"
fi
2024-09-13 20:28:40 +02:00
safe_run "$@"
}
2024-09-13 20:28:40 +02:00
main "$@"