diff --git a/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6164645f7461736b2e676966.gif b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6164645f7461736b2e676966.gif new file mode 100644 index 0000000..4c66e26 Binary files /dev/null and b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6164645f7461736b2e676966.gif differ diff --git a/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6170705f74687265655f636f6c732e706e67.png b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6170705f74687265655f636f6c732e706e67.png new file mode 100644 index 0000000..e2127d6 Binary files /dev/null and b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6170705f74687265655f636f6c732e706e67.png differ diff --git a/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6c696e6b696e672e676966 (1).gif b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6c696e6b696e672e676966 (1).gif new file mode 100644 index 0000000..7c0ccd6 Binary files /dev/null and b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6c696e6b696e672e676966 (1).gif differ diff --git a/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6c696e6b696e672e676966.gif b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6c696e6b696e672e676966.gif new file mode 100644 index 0000000..7c0ccd6 Binary files /dev/null and b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6c696e6b696e672e676966.gif differ diff --git a/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6d61726b646f776e2e676966.gif b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6d61726b646f776e2e676966.gif new file mode 100644 index 0000000..bbaea4d Binary files /dev/null and b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f706963732f6d61737465722f7479746f2f6d61726b646f776e2e676966.gif differ diff --git a/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f7479746f2f6d61737465722f7372632f696d672f7479746f2e706e67.png b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f7479746f2f6d61737465722f7372632f696d672f7479746f2e706e67.png new file mode 100644 index 0000000..99294fb Binary files /dev/null and b/68747470733a2f2f7261772e6769746875622e636f6d2f6a6833792f7479746f2f6d61737465722f7372632f696d672f7479746f2e706e67.png differ diff --git a/README.md b/README.md index 9dede0b..ac22fb9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# tyto_ynh +# Tyto for YunoHost manage and organise things: https://github.com/jh3y/tyto diff --git a/check_process.default b/check_process.default new file mode 100644 index 0000000..eeb8196 --- /dev/null +++ b/check_process.default @@ -0,0 +1,39 @@ +# See here for more informations +# https://github.com/YunoHost/package_check#syntax-check_process-file + +# Move this file from check_process.default to check_process when you have filled it. + +;; Test complet + ; Manifest + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + is_public=1 (PUBLIC|public=1|private=0) + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=1 + setup_public=1 + upgrade=1 + backup_restore=1 + multi_instance=1 + incorrect_path=1 + port_already_use=0 + change_url=1 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto +# Level 4: + Level 4=0 +# Level 5: + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 +;;; Options +Email=anmol@datamol.org +Notification=change diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..6e42650 --- /dev/null +++ b/conf/app.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/jh3y/tyto/archive/057781327fcfbfed3cf43da0993c5f4a5816a078.zip +SOURCE_SUM=cae63ac06dfe555e022fc231549eab0d7cd9d5e8a3235adeff4d5e5a793f134b +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=zip +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..3454094 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,20 @@ +location __PATH__ { + + # Path to source + alias __FINALPATH__/ ; + + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + + # Example PHP configuration (remove if not used) + index index.php index.html; + + # Common parameter to increase upload size limit in conjuction with dedicated php-fpm file + #client_max_body_size 50M; + + try_files $uri $uri/ index.php index.html; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..999e486 --- /dev/null +++ b/manifest.json @@ -0,0 +1,52 @@ +{ + "name": "Tyto app for YunoHost", + "id": "tyto", + "packaging_format": 1, + "description": { + "en": "tyto is an extensible and customizable management and organisation tool" + }, + "version": "3.0.4", + "url": "https://github.com/jh3y/tyto", + "license": "MIT", + "maintainer": { + "name": "Anmol Sharma", + "email": "anmol@datamol.org", + "url": "https://datamol.org" + }, + "requirements": { + "yunohost": ">= 2.7.2" + }, + "multi_instance": true, + "services": [ + "nginx" + ], + "arguments": { + "install" : [ + { + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain name for Tyto" + }, + "example": "example.com" + }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for Tyto" + }, + "example": "/tyto", + "default": "/tyto" + }, + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public application?" + }, + "default": true + } + ] + } +} diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..bb04a03 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# ============= FUTURE YUNOHOST HELPER ============= +# Delete a file checksum from the app settings +# +# $app should be defined when calling this helper +# +# usage: ynh_remove_file_checksum file +# | arg: file - The file for which the checksum will be deleted +ynh_delete_file_checksum () { + local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' + ynh_app_setting_delete $app $checksum_setting_name +} \ No newline at end of file diff --git a/scripts/backup b/scripts/backup new file mode 100755 index 0000000..d2c7b04 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,46 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Get the _common.sh file if it's not in the current directory + 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 + +final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get $app domain) + +#================================================= +# 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" + diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..d8b7b93 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,81 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +old_domain=$YNH_APP_OLD_DOMAIN +old_path=$YNH_APP_OLD_PATH + +new_domain=$YNH_APP_NEW_DOMAIN +new_path=$YNH_APP_NEW_PATH + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# CHECK THE SYNTAX OF THE PATHS +#================================================= + +test -n "$old_path" || old_path="/" +test -n "$new_path" || new_path="/" +new_path=$(ynh_normalize_url_path $new_path) +old_path=$(ynh_normalize_url_path $old_path) + +#================================================= +# CHECK WHICH PARTS SHOULD BE CHANGED +#================================================= + +change_domain=0 +if [ "$old_domain" != "$new_domain" ] +then + change_domain=1 +fi + +change_path=0 +if [ "$old_path" != "$new_path" ] +then + change_path=1 +fi + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= + +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# 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 + ynh_backup_if_checksum_is_different "$nginx_conf_path" + # Replace locations starting with old_path + # Look for every location possible patterns (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location) + ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $old_path" "location\1 $new_path" "$nginx_conf_path" + # Replace path in "return" directives + ynh_replace_string "return \([[:digit:]]\{3\}\) $old_path" "return \1 $new_path" "$nginx_conf_path" + # Calculate and store the nginx config file checksum + ynh_store_file_checksum "$nginx_conf_path" +fi + +# Change the domain for nginx +if [ $change_domain -eq 1 ] +then + # Delete file checksum for the old conf file location + ynh_delete_file_checksum "$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +systemctl reload nginx diff --git a/scripts/install b/scripts/install new file mode 100755 index 0000000..2e91dc6 --- /dev/null +++ b/scripts/install @@ -0,0 +1,111 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +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 + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +is_public=$YNH_APP_ARG_IS_PUBLIC + +# This is a multi-instance app, meaning it can be installed several times independently +# The id of the app as stated in the manifest is available as $YNH_APP_ID +# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +# The app instance name is available as $YNH_APP_INSTANCE_NAME +# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +# - ynhexample__{N} for the subsequent installations, with N=3,4, ... +# The app instance name is probably what you are interested the most, since this is +# guaranteed to be unique. This is a good unique identifier to define installation path, +# db names, ... +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= + +final_path=/var/www/$app +test ! -e "$final_path" || ynh_die "This path already contains a folder" + +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set $app domain $domain +ynh_app_setting_set $app path $path_url +ynh_app_setting_set $app is_public $is_public + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +ynh_app_setting_set $app final_path $final_path +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user +ynh_system_user_create $app + + +#================================================= +# SETUP APPLICATION WITH CURL +#================================================= + +# Set right permissions for curl install +chown -R $app: $final_path + +#================================================= +# SETUP SSOWAT +#================================================= + +if [ $is_public -eq 0 ] +then # Remove the public access + ynh_app_setting_delete $app skipped_uris +fi +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set $app unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx diff --git a/scripts/remove b/scripts/remove new file mode 100755 index 0000000..e78e30b --- /dev/null +++ b/scripts/remove @@ -0,0 +1,44 @@ +#!/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) +final_path=$(ynh_app_setting_get $app final_path) + +#================================================= +# STANDARD REMOVE +#================================================= +# REMOVE APP MAIN DIR +#================================================= + +# Remove the app directory securely +ynh_secure_remove "$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= + +# Delete a system user +ynh_system_user_delete $app diff --git a/scripts/restore b/scripts/restore new file mode 100755 index 0000000..7d1ef97 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,78 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Get the _common.sh file if it's not in the current directory + 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) +path_url=$(ynh_app_setting_get $app path) +final_path=$(ynh_app_setting_get $app final_path) + +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= + +ynh_webpath_available $domain $path_url \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die "There is already a directory: $final_path " + +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= + +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# 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: $final_path + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= + +systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100755 index 0000000..8ffa310 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,113 @@ +#!/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) +is_public=$(ynh_app_setting_get $app is_public) +final_path=$(ynh_app_setting_get $app final_path) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set $app is_public 1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set $app is_public 0 + is_public=0 +fi + +# If final_path doesn't exist, create it +if [ -z $final_path ]; then + final_path=/var/www/$app + ynh_app_setting_set $app final_path $final_path +fi + +#================================================= +# 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 + +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user +ynh_system_user_create $app + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Set right permissions for curl installation +chown -R $app: $final_path + +#================================================= +# SETUP SSOWAT +#================================================= + +if [ $is_public -eq 0 ] +then # Remove the public access + ynh_app_setting_delete $app skipped_uris +fi +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway + ynh_app_setting_set $app unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx