diff --git a/scripts/backup b/scripts/backup index ecc5c13..dcb85ed 100644 --- a/scripts/backup +++ b/scripts/backup @@ -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" \ No newline at end of file diff --git a/scripts/install b/scripts/install index 2f09b7d..6ad5130 100644 --- a/scripts/install +++ b/scripts/install @@ -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" #================================================= diff --git a/scripts/restore b/scripts/restore index b0cda10..e122ae4 100644 --- a/scripts/restore +++ b/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 \ No newline at end of file +# 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" \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..a06a92a --- /dev/null +++ b/scripts/upgrade @@ -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" + + + + + +