mirror of
https://github.com/YunoHost-Apps/kodi_ynh.git
synced 2024-09-03 19:26:34 +02:00
Work on backup, install, restore and upgrade scripts
This commit is contained in:
parent
cda089d3a8
commit
c017d18001
4 changed files with 236 additions and 53 deletions
|
@ -11,45 +11,50 @@ if [ ! -e _common.sh ]; then
|
|||
cp ../settings/scripts/_common.sh ./_common.sh
|
||||
chmod a+rx _common.sh
|
||||
fi
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
launch_on_boot=$(ynh_app_setting_get $app launch_on_boot)
|
||||
open_webserver_port=$(ynh_app_setting_get $app open_webserver_port)
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
launch_on_boot=$(ynh_app_setting_get "$app" launch_on_boot)
|
||||
open_webserver_port=$(ynh_app_setting_get "$app" open_webserver_port)
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_backup "$final_path"
|
||||
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
|
||||
#=================================================
|
||||
# BACKUP SYSTEMD
|
||||
#=================================================
|
||||
ynh_backup "/etc/systemd/system/$app.service"
|
||||
|
||||
|
||||
#=================================================
|
||||
# BACKUP SOURCE FILE
|
||||
#=================================================
|
||||
if [ -f "/etc/apt/sources.list.d/${app}.list" ] ; then
|
||||
ynh_backup "/etc/apt/sources.list.d/${app}.list"
|
||||
fi
|
||||
|
||||
ynh_backup "/etc/systemd/system/$app.service"
|
|
@ -60,7 +60,7 @@ ynh_app_setting_set "$app" open_webserver_port "$open_webserver_port"
|
|||
ynh_system_user_create "$app" "$final_path"
|
||||
sudo mkdir "$final_path"
|
||||
sudo chown -R "$app":"$app" "$final_path"
|
||||
sudo usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input "$app"
|
||||
sudo usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input,netdev "$app"
|
||||
|
||||
|
||||
#=================================================
|
||||
|
|
120
scripts/restore
120
scripts/restore
|
@ -1,5 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
# MEMO TO TEST THIS SCRIPT
|
||||
# yunohost backup create --ignore-system --apps kodi
|
||||
# yunohost app remove kodi
|
||||
# yunohost backup restore backup.tar
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
|
@ -14,91 +19,122 @@ fi
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
|
||||
#=================================================
|
||||
# GLOBAL VARS
|
||||
#=================================================
|
||||
arch=$(uname -m)
|
||||
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
launch_on_boot=$(ynh_app_setting_get $app launch_on_boot)
|
||||
open_webserver_port=$(ynh_app_setting_get $app open_webserver_port)
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
launch_on_boot=$(ynh_app_setting_get "$app" launch_on_boot)
|
||||
open_webserver_port=$(ynh_app_setting_get "$app" open_webserver_port)
|
||||
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
|
||||
ynh_webpath_available $domain $path_url \
|
||||
ynh_webpath_available "$domain" "$path_url" \
|
||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||
test ! -d $final_path \
|
||||
test ! -d "$final_path" \
|
||||
|| ynh_die "There is already a directory: $final_path "
|
||||
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
# CREATE KODI USER
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_system_user_create "$app" "$final_path"
|
||||
sudo mkdir "$final_path"
|
||||
sudo chown -R "$app":"$app" "$final_path"
|
||||
sudo usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input,netdev "$app"
|
||||
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "$final_path"
|
||||
|
||||
|
||||
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
#=================================================
|
||||
|
||||
# Create the dedicated user (if not existing)
|
||||
ynh_system_user_create $app
|
||||
|
||||
|
||||
#=================================================
|
||||
# RESTORE USER RIGHTS
|
||||
#=================================================
|
||||
|
||||
# Restore permissions on app files
|
||||
chown -R $app:$app $final_path
|
||||
|
||||
chown -R "$app":"$app" "$final_path"
|
||||
|
||||
|
||||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
yunohost service add $app --log "$final_path/.kodi/temp/kodi.log"
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
|
||||
#=================================================
|
||||
# RESTORE SYSTEMD
|
||||
#=================================================
|
||||
ynh_restore_file "/etc/systemd/system/$app.service"
|
||||
if [ $launch_on_boot -eq 0 ]
|
||||
|
||||
|
||||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
#=================================================
|
||||
yunohost service add "$app" --log "$final_path/.kodi/temp/kodi.log"
|
||||
|
||||
|
||||
#=================================================
|
||||
# RESTORE LAUNCH ON BOOT
|
||||
#=================================================
|
||||
if [ "$launch_on_boot" -eq 0 ]
|
||||
then
|
||||
sudo systemctl disable $app
|
||||
sudo systemctl disable "$app"
|
||||
else
|
||||
systemctl enable $app.service
|
||||
systemctl enable "$app".service
|
||||
fi
|
||||
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
# INSTALL DEPENDENCIES AND KODI
|
||||
#=================================================
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
if [[ $arch != arm* ]]; then
|
||||
ynh_restore_file "/etc/apt/sources.list.d/${app}.list"
|
||||
ynh_package_update
|
||||
ynh_package_install xorg xinit dbus-x11 kodi
|
||||
else
|
||||
ynh_package_update
|
||||
ynh_package_install xserver-xorg-legacy xorg dbus-x11 kodi
|
||||
fi
|
||||
|
||||
|
||||
#=================================================
|
||||
systemctl reload php5-fpm
|
||||
systemctl reload nginx
|
||||
# X11 SETTINGS
|
||||
#=================================================
|
||||
sudo sed -i 's/allowed_users=console/allowed_users=anybody/' /etc/X11/Xwrapper.config
|
||||
|
||||
|
||||
#=================================================
|
||||
# CONTROL WEB INTERFACE
|
||||
#=================================================
|
||||
if [ "$open_webserver_port" -eq 1 ]
|
||||
then
|
||||
yunohost firewall allow --no-upnp TCP 8080 2>&1
|
||||
fi
|
||||
|
||||
|
||||
# Reload SSOwat config
|
||||
yunohost app ssowatconf
|
||||
|
||||
# Reload Nginx
|
||||
systemctl reload nginx
|
||||
|
||||
|
||||
#=================================================
|
||||
# START KODI
|
||||
#=================================================
|
||||
sudo systemctl start "$app"
|
142
scripts/upgrade
Normal file
142
scripts/upgrade
Normal file
|
@ -0,0 +1,142 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
launch_on_boot=$(ynh_app_setting_get "$app" launch_on_boot)
|
||||
open_webserver_port=$(ynh_app_setting_get "$app" open_webserver_port)
|
||||
|
||||
|
||||
#=================================================
|
||||
# GLOBAL VARS
|
||||
#=================================================
|
||||
arch=$(uname -m)
|
||||
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
# Fix launch_on_boot as a boolean value
|
||||
if [ "$launch_on_boot" = "Yes" ]; then
|
||||
ynh_app_setting_set "$app" launch_on_boot 1
|
||||
launch_on_boot=1
|
||||
elif [ "$launch_on_boot" = "No" ]; then
|
||||
ynh_app_setting_set "$app" launch_on_boot 0
|
||||
launch_on_boot=0
|
||||
fi
|
||||
|
||||
# Fix launch_on_boot as a boolean value
|
||||
if [ "$open_webserver_port" = "Yes" ]; then
|
||||
ynh_app_setting_set "$app" open_webserver_port 1
|
||||
open_webserver_port=1
|
||||
elif [ "$open_webserver_port" = "No" ]; then
|
||||
ynh_app_setting_set "$app" open_webserver_port 0
|
||||
open_webserver_port=0
|
||||
fi
|
||||
|
||||
|
||||
#=================================================
|
||||
# STOP KODI
|
||||
#=================================================
|
||||
sudo systemctl stop "$app"
|
||||
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
# restore it if the upgrade fails
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
|
||||
|
||||
#=================================================
|
||||
# REPLACE SYSTEMD CONFIG
|
||||
#=================================================
|
||||
ynh_add_systemd_config
|
||||
|
||||
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES AND KODI
|
||||
#=================================================
|
||||
if [[ "$arch" != arm* ]]; then
|
||||
sudo cp ../conf/kodi.list "/etc/apt/sources.list.d/${app}.list"
|
||||
ynh_package_update
|
||||
ynh_package_install xorg xinit dbus-x11 kodi
|
||||
else
|
||||
ynh_package_update
|
||||
ynh_package_install xserver-xorg-legacy xorg dbus-x11 kodi
|
||||
|
||||
fi
|
||||
|
||||
|
||||
#=================================================
|
||||
# X11 SETTINGS
|
||||
#=================================================
|
||||
sudo sed -i 's/allowed_users=console/allowed_users=anybody/' /etc/X11/Xwrapper.config
|
||||
|
||||
|
||||
#=================================================
|
||||
# CONTROL WEB INTERFACE
|
||||
#=================================================
|
||||
if [ $open_webserver_port -eq 1 ]
|
||||
then
|
||||
yunohost firewall allow --no-upnp TCP 8080 2>&1
|
||||
fi
|
||||
|
||||
|
||||
#=================================================
|
||||
# NGINX
|
||||
#=================================================
|
||||
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_backup_if_checksum_is_different "$finalnginxconf"
|
||||
sudo cp ../conf/nginx.conf "$finalnginxconf"
|
||||
|
||||
if [ "$path_url" == "/" ]; then
|
||||
ynh_replace_string "__PATH__/" "/" "$finalnginxconf"
|
||||
else
|
||||
ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf"
|
||||
fi
|
||||
|
||||
ynh_app_setting_set "$app" protected_uris "/"
|
||||
|
||||
domainregex=$(echo "$domain" | sed 's/-/\%&/g')
|
||||
ynh_app_setting_set "$app" skipped_regex "$domainregex/jsonrpc.*$,$domainregex/image.*$"
|
||||
|
||||
# Reload SSOwat config
|
||||
yunohost app ssowatconf
|
||||
|
||||
# Reload Nginx
|
||||
systemctl reload nginx
|
||||
|
||||
|
||||
|
||||
#=================================================
|
||||
# START KODI
|
||||
#=================================================
|
||||
sudo systemctl start "$app"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue