diff --git a/conf/app.src b/conf/app.src old mode 100644 new mode 100755 index f95eb29..9aeddf2 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/apankrat/nullboard/archive/d449da9f54677ef9ef5c066106e78c0b16be996a.tar.gz -SOURCE_SUM=1126b02a8626e6685c4b6f1892ea43a6e3aa7a04cc91243bea672d10268435e8 +SOURCE_URL=https://github.com/Jermolene/TiddlyWiki5/archive/v5.1.21.tar.gz +SOURCE_SUM=9f36a082f55334fd4b88f9af82a8711c4ef787b04f5280e52dd97e0df9864616 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100755 index 0000000..668a965 --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1,16 @@ +[Unit] +Description=__APP__ service +After=network.target + +[Service] +Type=simple +User=__APP__ +Group=__APP__ +WorkingDirectory=__FINALPATH__ +ExecStart=__NODEJS_PATH__/node __FINALPATH__/tiddlywiki monwiki --listen port=__port__ authenticated-user-header=basic +Restart=always +Environment=PATH=/usr/bin:/usr/local/bin:__NODEJS_PATH__ +Environment=NODE_ENV=production + +[Install] +WantedBy=multi-user.target diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100755 index 0000000..7912aa4 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +#================================================= +# COMMON VARIABLES +#================================================= + +nodejs_version=14 + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup old mode 100644 new mode 100755 index 80e4cd6..e3fec32 --- a/scripts/backup +++ b/scripts/backup @@ -6,12 +6,18 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= @@ -41,6 +47,14 @@ ynh_backup --src_path="$final_path" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url old mode 100644 new mode 100755 index e912667..a4cec5f --- a/scripts/change_url +++ b/scripts/change_url @@ -6,47 +6,30 @@ # IMPORT GENERIC HELPERS #================================================= +source _common.sh source /usr/share/yunohost/helpers -ynh_abort_if_errors - #================================================= # RETRIEVE ARGUMENTS #================================================= +ynh_print_info --message="Retrieve arguments from the manifest" old_domain=$YNH_APP_OLD_DOMAIN old_path=$YNH_APP_OLD_PATH new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH +new_path="/" app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_print_info --message="Loading installation settings..." # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up $app before changing its URL (may take a while)..." --weight=2 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED #================================================= @@ -63,26 +46,35 @@ then change_path=1 fi +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Stopping a systemd service..." + +ynh_systemd_action --service_name=$app --action="stop" + #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=3 +ynh_print_info --message="Updating nginx web server configuration..." nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf -# Change the path in the NGINX config file +# Change the path in the nginx config file if [ $change_path -eq 1 ] then - # Make a backup of the original NGINX config file if modified + # Make a backup of the original nginx config file if modified ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper + # Set global variables for nginx helper domain="$old_domain" path_url="$new_path" - # Create a dedicated NGINX config + # Create a dedicated nginx config ynh_add_nginx_config fi -# Change the domain for NGINX +# Change the domain for nginx if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location @@ -92,10 +84,19 @@ then ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi +#================================================= +# GENERIC FINALISATION +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" + #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=2 +ynh_print_info --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -103,4 +104,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_print_info --message="Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 4f3cbde..b83dd51 100755 --- a/scripts/install +++ b/scripts/install @@ -6,18 +6,23 @@ # IMPORT GENERIC HELPERS #================================================= +source _common.sh +source ynh_send_readme_to_admin__2 source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -# Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH @@ -25,12 +30,14 @@ is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME +# ldap_user="svc_${app}_ldap" +# ldap_password=$(ynh_string_random --length=8) + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 +ynh_script_progression --message="Validating installation parameters..." -# Copy files to the right place final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" @@ -40,35 +47,73 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --weight=2 +ynh_script_progression --message="Storing installation settings..." -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=is_public --value=$is_public +# ynh_app_setting_set --app=$app --key=ldap_user --value=$ldap_user +# ynh_app_setting_set --app=$app --key=ldap_password --value=$ldap_password + #================================================= # STANDARD MODIFICATIONS +#================================================= +# FIND AND OPEN A PORT +#================================================= +ynh_script_progression --message="Finding an available port..." + +# Find a free port +port=$(ynh_find_port --port=8095) +ynh_app_setting_set --app=$app --key=port --value=$port + +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." + +ynh_install_nodejs --nodejs_version=$nodejs_version + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=1 +ynh_script_progression --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path - # Download, check integrity, uncompress and patch the source from app.src -#ynh_setup_source --dest_dir="$final_path" - -mkdir -p $final_path -cp -a ../sources/empty.html $final_path/empty.html +ynh_setup_source --dest_dir=$final_path #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=2 +ynh_script_progression --message="Configuring NGINX web server..." -# Create a dedicated NGINX config +# Create a dedicated nginx config ynh_add_nginx_config +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user ..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# SPECIFIC SETUP +#================================================= +ynh_script_progression --message="tiddlywiki..." --weight=2 +pushd $final_path + $nodejs_path/node $final_path/tiddlywiki monwiki --init server +popd + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." + +ynh_add_systemd_config + #================================================= # GENERIC FINALIZATION #================================================= @@ -76,7 +121,23 @@ ynh_add_nginx_config #================================================= # Set permissions to app files -chown -R root: $final_path +chown -R $app: $final_path + +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 + +yunohost service add $app --description="Collaborative editor" --log="/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_print_info --message="on demarre le service..." + +ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Browse to http://localhost" + +sleep 30 #================================================= # SETUP SSOWAT @@ -92,7 +153,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_print_info --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -100,4 +161,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_print_info --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 2123569..5d9c264 100755 --- a/scripts/remove +++ b/scripts/remove @@ -6,24 +6,66 @@ # IMPORT GENERIC HELPERS #================================================= +source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) +ldap_user=$(ynh_app_setting_get --app=$app --key=ldap_user) + #================================================= # STANDARD REMOVE +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= + +# Remove a service from the admin panel, added by `yunohost service add` +if ynh_exec_warn_less yunohost service status $app >/dev/null +then + ynh_print_info --message="Removing $app service..." + yunohost service remove $app +fi + +#================================================= +# STOP AND REMOVE SERVICE +#================================================= +ynh_print_info --message="Stopping and removing the systemd service..." + +# Remove the dedicated systemd config +ynh_remove_systemd_config + +#================================================= +# REMOVE THE POSTGRESQL DATABASE +#================================================= +ynh_print_info --message="Removing the PostgreSQL database..." + +# Remove a database if it exists, along with the associated user +ynh_psql_remove_db --db_user=$db_user --db_name=$db_name + +#================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_print_info --message="Removing dependencies..." + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies +ynh_remove_nodejs + #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing $app main directory..." --weight=3 +ynh_print_info --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -31,13 +73,42 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 +ynh_print_info --message="Removing nginx web server configuration..." -# Remove the dedicated NGINX config +# Remove the dedicated nginx config ynh_remove_nginx_config +#================================================= +# CLOSE A PORT +#================================================= + +if yunohost firewall list | grep -q "\- $port$" +then + ynh_print_info --message="Closing port $port..." + ynh_exec_warn_less yunohost firewall disallow TCP $port +fi + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE LDAP USER +#================================================= +ynh_print_info --message="Removing ldap user..." + +yunohost user delete $ldap_user --purge + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= +ynh_print_info --message="Removing the dedicated system user..." + +# Delete a system user +ynh_system_user_delete --username=$app + #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_print_info --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore old mode 100644 new mode 100755 index 7680bdd..0f17565 --- a/scripts/restore +++ b/scripts/restore @@ -6,18 +6,24 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=1 +ynh_print_info --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME @@ -28,7 +34,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 +ynh_print_info --message="Validating restoration parameters..." ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" @@ -46,31 +52,63 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring $app main directory..." --weight=2 +ynh_print_info --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 +ynh_print_info --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # RESTORE USER RIGHTS #================================================= # Restore permissions on app files -chown -R root: $final_path +chown -R $app: $final_path + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_print_info --message="Reinstalling dependencies..." + +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + +#================================================= +# RESTORE SYSTEMD +#================================================= +ynh_print_info --message="Restoring the systemd configuration..." + +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service --quiet + +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add $app --description="" --log="/var/log/$app/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="" + #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=3 +ynh_print_info --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -78,4 +116,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_print_info --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade old mode 100644 new mode 100755 index dc4d419..a6d7083 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -6,12 +6,13 @@ # IMPORT GENERIC HELPERS #================================================= +source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -19,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK VERSION @@ -29,7 +31,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_print_info --message="Ensuring downward compatibility..." # If final_path doesn't exist, create it if [ -z "$final_path" ]; then @@ -37,27 +39,44 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all + + ynh_app_setting_delete --app=$app --key=is_public +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=3 +ynh_print_info --message="Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { # restore it if the upgrade fails ynh_restore_upgradebackup + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Stopping a systemd service..." + +ynh_systemd_action --service_name=$app --action=stop + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --weight=4 + ynh_print_info --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" @@ -66,22 +85,76 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 +ynh_print_info --message="Upgrading NGINX web server configuration..." -# Create a dedicated NGINX config +# Create a dedicated nginx config ynh_add_nginx_config +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_print_info --message="Upgrading dependencies..." + +ynh_install_nodejs --nodejs_version=$nodejs_version + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_print_info --message="Making sure dedicated system user exists..." + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# MODIFY A CONFIG FILE +#================================================= + +config_file="$final_path/config.yml" +ynh_backup_if_checksum_is_different --file=$config_file +cp -f ../conf/config.sample.yml $config_file + +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=$config_file +ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file=$config_file +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file=$config_file + +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= + +# Recalculate and store the checksum of the file for the next upgrade. +ynh_store_file_checksum --file=$config_file + +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_print_info --message="Upgrading systemd configuration..." + +ynh_add_systemd_config + +#================================================= +# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= # Set permissions on app files -chown -R root: $final_path +chown -R $app: $final_path + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd + +sleep 30 #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_print_info --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -89,4 +162,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_print_info --message="Upgrade of $app completed" diff --git a/sources/empty.html b/sources/empty.html deleted file mode 100644 index f7486dc..0000000 --- a/sources/empty.html +++ /dev/null @@ -1,12900 +0,0 @@ - - - - - - - - - - - - - - - - - - - - -TiddlyWiki — a non-linear personal web notebook - - - - - - - - - - - -
- -
- - - - - - - - - - - - - - - - -