1
0
Fork 0
ynh-apps_tools/maintenance.sh

136 lines
4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
workdir=$(realpath $(dirname "$0"))
cd $workdir
2024-08-30 13:49:39 +02:00
function update_venv()
{
if [ -d "venv" ]; then
venv/bin/pip install -r requirements.txt >/dev/null
2024-08-30 13:49:39 +02:00
fi
}
function git_pull_and_update_cron_and_restart_services_if_needed()
{
2024-09-09 17:24:10 +02:00
if ! git pull &>/dev/null; then
sendxmpppy "[apps repo] Couldn't pull, maybe local changes are present?"
exit 1
fi
# Cron
cat cron | sed "s@__BASEDIR__@$workdir@g" > /etc/cron.d/app_list
# App store
chown -R appstore store
pushd store >/dev/null
modified_after_service_start="$(find *.py translations/ templates/ assets/ -newermt "$(systemctl show --property=ActiveEnterTimestamp appstore | cut -d= -f2 | cut -d' ' -f2-3)")"
if [ -n "$modified_after_service_start" ]
then
2024-08-30 13:49:39 +02:00
update_venv
pushd assets >/dev/null
./tailwindcss-linux-x64 --input tailwind-local.css --output tailwind.css --minify
popd >/dev/null
systemctl restart appstore
sleep 3
fi
popd >/dev/null
systemctl --quiet is-active appstore || sendxmpppy "[appstore] Uhoh, failed to (re)start the appstore service?"
# App generator
chown -R appgenerator tools/app_generator
pushd tools/app_generator >/dev/null
modified_after_service_start="$(find *.py translations/ templates/ static/ -newermt "$(systemctl show --property=ActiveEnterTimestamp appgenerator | cut -d= -f2 | cut -d' ' -f2-3)")"
if [ -n "$modified_after_service_start" ]
then
2024-08-30 13:49:39 +02:00
update_venv
pushd assets >/dev/null
./tailwindcss-linux-x64 --input tailwind-local.css --output tailwind.css --minify
popd >/dev/null
systemctl restart appgenerator
sleep 3
fi
popd >/dev/null
systemctl --quiet is-active appgenerator || sendxmpppy "[appgenerator] Uhoh, failed to (re)start the appgenerator service?"
# Autoreadme
pushd tools/readme_generator >/dev/null
modified_after_service_start="$(find *.py translations/ templates/ -newermt "$(systemctl show --property=ActiveEnterTimestamp webhooks | cut -d= -f2 | cut -d' ' -f2-3)")"
if [ -n "$modified_after_service_start" ]
then
2024-08-30 13:49:39 +02:00
update_venv
systemctl restart webhooks
sleep 3
fi
popd >/dev/null
# Autoreadme
pushd tools/webhooks >/dev/null
modified_after_service_start="$(find *.py -newermt "$(systemctl show --property=ActiveEnterTimestamp webhooks | cut -d= -f2 | cut -d' ' -f2-3)")"
if [ -n "$modified_after_service_start" ]
then
2024-08-30 13:49:39 +02:00
update_venv
systemctl restart webhooks
sleep 3
fi
popd >/dev/null
2024-08-30 13:49:39 +02:00
pushd tools/autoupdate_app_sources >/dev/null
update_venv
popd >/dev/null
systemctl --quiet is-active webhooks || sendxmpppy "[autoreadme] Uhoh, failed to (re)start the autoreadme service?"
}
function update_app_cache()
{
./tools/app_caches.py -d -l . -c .apps_caches -j20
}
function rebuild_catalog()
{
log=$workdir/app_list_auto_update.log
date >> $log
git_pull_and_update_cron_and_restart_services_if_needed
update_app_cache
./tools/list_builder.py &>> $log || sendxmpppy "[listbuilder] Rebuilding the application list failed miserably"
}
function autoupdate_app_sources()
{
log=$workdir/app_sources_auto_update.log
date >> $log
git_pull_and_update_cron_and_restart_services_if_needed
update_app_cache
tools/autoupdate_app_sources/venv/bin/python3 tools/autoupdate_app_sources/autoupdate_app_sources.py \
--latest-commit-weekly --edit --commit --pr --paste -j1 \
&> $log || sendxmpppy "[appsourcesautoupdate] App sources auto-update failed miserably"
}
function update_app_levels()
{
update_app_cache
pushd tools/update_app_levels >/dev/null
python3 update_app_levels.py
popd >/dev/null
}
function fetch_main_dashboard()
{
pushd store >/dev/null
venv/bin/python3 fetch_main_dashboard.py 2>&1 | grep -v 'Following Github server redirection'
popd >/dev/null
}
function fetch_level_history()
{
pushd store >/dev/null
venv/bin/python3 fetch_level_history.py
popd >/dev/null
}
$1