1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lstu_ynh.git synced 2024-09-03 19:36:12 +02:00

Merge pull request #29 from YunoHost-Apps/testing

Testing
This commit is contained in:
Kayou 2019-02-21 14:12:53 +01:00 committed by GitHub
commit dc72a01f68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 814 additions and 251 deletions

View file

@ -32,7 +32,7 @@ How to configure this app: a plain file with SSH.
#### Multi-users support #### Multi-users support
Are LDAP and HTTP auth supported? **Not yet** Are LDAP and HTTP auth supported? **Yes**
Can the app be used by multiple users? **Yes** Can the app be used by multiple users? **Yes**
#### Supported architectures #### Supported architectures
@ -67,9 +67,6 @@ sudo yunohost app upgrade lstu -u https://github.com/YunoHost-Apps/lstu_ynh/tree
``` ```
## Todo ## Todo
- [ ] Integrate with LDAP
- [ ] Add a question for the admin features' password
- [ ] Allow to choose the database (sqlite or PostgreSQL) - [ ] Allow to choose the database (sqlite or PostgreSQL)
- [ ] Allow to choose to use Minion - [ ] Allow to choose to use Minion
- [ ] Add CI stuff - [ ] Add CI stuff
- [ ] Theme choice (default or milligram)

75
actions.json Normal file
View file

@ -0,0 +1,75 @@
[
{
"id": "public_private",
"name": "Move to public or private",
"command": "/bin/bash scripts/actions/public_private",
"user": "root",
"accepted_return_codes": [
0
],
"description": {
"en": "Change the public access of the app."
},
"arguments": [
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Is it a public app ?"
},
"default": true
}
]
},
{
"id": "change_password",
"name": "Change the admin password",
"command": "/bin/bash scripts/actions/change_password",
"user": "root",
"accepted_return_codes": [
0
],
"description": {
"en": "Change the admin password of the app.",
"fr": "Change le mot de passe administrateur de l'app."
},
"arguments": [
{
"name": "password",
"type": "password",
"ask": {
"en": "New password",
"fr": "Nouveau mot de passe"
}
}
]
},
{
"id": "change_theme",
"name": "Change the theme",
"command": "/bin/bash scripts/actions/change_theme",
"user": "root",
"accepted_return_codes": [
0
],
"description": {
"en": "Change the theme of the app.",
"fr": "Change le thème de l'app."
},
"arguments": [
{
"name": "theme",
"type": "string",
"ask": {
"en": "Choose a theme",
"fr": "Choisissez un theme"
},
"choices": [
"default",
"milligram"
],
"default": "milligram"
}
]
}
]

View file

@ -4,7 +4,8 @@
domain="domain.tld" (DOMAIN) domain="domain.tld" (DOMAIN)
path="/path" (PATH) path="/path" (PATH)
is_public=1 (PUBLIC|public=1|private=0) is_public=1 (PUBLIC|public=1|private=0)
theme="milligram" (THEME)
password="verysecretpassword" (PASSWORD)
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_sub_dir=1 setup_sub_dir=1
@ -13,25 +14,20 @@
setup_private=1 setup_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
upgrade=1 from_commit=7410eb674fc4670fcc0398e8e1d086e2560c7f28
backup_restore=1 backup_restore=1
multi_instance=0 multi_instance=1
wrong_user=1
wrong_path=1
incorrect_path=1 incorrect_path=1
corrupt_source=1 port_already_use=1 (8095)
fail_download_source=1 change_url=1
port_already_use=1
final_path_already_use=1
;;; Levels ;;; Levels
Level 1=auto Level 1=auto
Level 2=auto Level 2=auto
Level 3=auto Level 3=auto
Level 4=na Level 4=1
# level 4: https://github.com/YunoHost-Apps/lstu_ynh/issues/4 Level 5=auto
Level 5=1
# level 5: https://github.com/YunoHost-Apps/lstu_ynh/issues/3
Level 6=auto Level 6=auto
Level 7=auto Level 7=auto
Level 8=0 Level 8=0
Level 9=0 Level 9=0
Level 10=0 Level 10=0

View file

@ -29,11 +29,11 @@
# secret hashed passphrase to access some admin features # secret hashed passphrase to access some admin features
# Hash your password by issuing `echo -n s3cr3T | sha256sum` on your terminal # Hash your password by issuing `echo -n s3cr3T | sha256sum` on your terminal
# optional, but you won't have access to admin /stats if not set and if adminpwd is not set either # optional, but you won't have access to admin /stats if not set and if adminpwd is not set either
#hashed_adminpwd => '94b2feede6ea5e2eec62f457ecb7d3f719b24d19c29d4e5466246a31908fc23b', hashed_adminpwd => '__PASSWORD_HASHED__',
# choose a theme. See the available themes in `themes` directory # choose a theme. See the available themes in `themes` directory
# optional, default is 'default' # optional, default is 'default'
theme => 'default', theme => '__SELECTED_THEME__', # default or milligram
# number of URLs to be displayed per page in /stats # number of URLs to be displayed per page in /stats
# optional, default is 10 # optional, default is 10
@ -178,14 +178,14 @@
# set `ldap` if you want that only authenticated users can shorten URLs # set `ldap` if you want that only authenticated users can shorten URLs
# please note that everybody can still use shortend URLs # please note that everybody can still use shortend URLs
# optional, no default # optional, no default
#ldap => { __IS_PUBLIC__ldap => {
# uri => 'ldaps://ldap.example.org', # server URI __IS_PUBLIC__ uri => 'ldap://localhost:389', # server URI
# user_tree => 'ou=users,dc=example,dc=org', # search base DN __IS_PUBLIC__ user_tree => 'dc=yunohost,dc=org', # search base DN
# bind_dn => 'uid=ldap_user,ou=users,dc=example,dc=org', # search bind DN __IS_PUBLIC__ bind_dn => 'ou=users,dc=yunohost,dc=org', # search bind DN
# bind_pwd => 'secr3t', # search bind password __IS_PUBLIC__# bind_pwd => '', # search bind password
# user_attr => 'uid', # user attribute (uid, mail, sAMAccountName, etc.) __IS_PUBLIC__ user_attr => 'uid', # user attribute (uid, mail, sAMAccountName, etc.)
# user_filter => '(!(uid=ldap_user))', # user filter (to exclude some users, etc.) __IS_PUBLIC__# user_filter => '(!(uid=ldap_user))', # user filter (to exclude some users, etc.)
#}, __IS_PUBLIC__},
# set `htpasswd` if you want to use an htpasswd file instead of ldap # set `htpasswd` if you want to use an htpasswd file instead of ldap
# create the file with `htpasswd -c lstu.passwd user`, update it with `htpasswd lstu.passwd user2` # create the file with `htpasswd -c lstu.passwd user`, update it with `htpasswd lstu.passwd user2`

View file

@ -3,9 +3,6 @@ location __PATH__ {
rewrite ^ https://$server_name$request_uri? permanent; rewrite ^ https://$server_name$request_uri? permanent;
} }
#--PRIVATE--# Include SSOWAT user panel.
#--PRIVATE--include conf.d/yunohost_panel.conf.inc;
access_log /var/log/nginx/lstu.access.log; access_log /var/log/nginx/lstu.access.log;
error_log /var/log/nginx/lstu.error.log; error_log /var/log/nginx/lstu.error.log;
@ -19,4 +16,7 @@ location __PATH__ {
# We expect the downsteam servers to redirect to the right hostname, so don't do any rewrite$ # We expect the downsteam servers to redirect to the right hostname, so don't do any rewrite$
proxy_redirect off; proxy_redirect off;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
} }

View file

@ -2,7 +2,7 @@
"name": "Lstu", "name": "Lstu",
"id": "lstu", "id": "lstu",
"packaging_format": 1, "packaging_format": 1,
"version": "0.21-4~ynh2", "version": "0.21-4~ynh3",
"requirements": { "requirements": {
"yunohost": ">= 3.0" "yunohost": ">= 3.0"
}, },
@ -16,12 +16,12 @@
"name": "frju365", "name": "frju365",
"email": "abld@abld.info" "email": "abld@abld.info"
}, },
"multi_instance": false, "multi_instance": true,
"services": [ "services": [
"nginx" "nginx"
], ],
"arguments": { "arguments": {
"install" : [ "install": [
{ {
"name": "domain", "name": "domain",
"type": "domain", "type": "domain",
@ -49,6 +49,27 @@
"fr": "Est-ce une application publique ?" "fr": "Est-ce une application publique ?"
}, },
"default": false "default": false
},
{
"name": "theme",
"type": "string",
"ask": {
"en": "Choose a theme",
"fr": "Choisissez un theme"
},
"choices": [
"default",
"milligram"
],
"default": "milligram"
},
{
"name": "password",
"type": "password",
"ask": {
"en": "Choose a password",
"fr": "Choisissez un mot de passe"
}
} }
] ]
} }

View file

@ -1,12 +1,5 @@
#!/bin/bash #!/bin/bash
CHECK_VAR () { # Verifies that the variable is not empty.
# $1 = Variable to be checked
# $2 = Display text on error
test -n "$1" || (echo "$2" >&2 && false)
}
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started # Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
# #
# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ] # usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ]
@ -14,6 +7,9 @@ CHECK_VAR () { # Verifies that the variable is not empty.
# | arg: -a, --action= - Action to perform with systemctl. Default: start # | arg: -a, --action= - Action to perform with systemctl. Default: start
# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot. # | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot.
# If not defined it don't wait until the service is completely started. # If not defined it don't wait until the service is completely started.
# WARNING: When using --line_match, you should always add `ynh_clean_check_starting` into your
# `ynh_clean_setup` at the beginning of the script. Otherwise, tail will not stop in case of failure
# of the script. The script will then hang forever.
# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log # | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds. # | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
# | arg: -e, --length= - Length of the error log : Default : 20 # | arg: -e, --length= - Length of the error log : Default : 20
@ -40,22 +36,24 @@ ynh_systemd_action() {
if [[ -n "${line_match:-}" ]] if [[ -n "${line_match:-}" ]]
then then
local templog="$(mktemp)" local templog="$(mktemp)"
# Following the starting of the app in its log # Following the starting of the app in its log
if [ "$log_path" == "systemd" ] ; then if [ "$log_path" == "systemd" ] ; then
# Read the systemd journal # Read the systemd journal
journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" & journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" &
else # Get the PID of the journalctl command
local pid_tail=$!
else
# Read the specified log file # Read the specified log file
tail -F -n0 "$log_path" > "$templog" & tail -F -n0 "$log_path" > "$templog" &
fi # Get the PID of the tail command
# Get the PID of the tail command local pid_tail=$!
local pid_tail=$! fi
fi fi
echo "${action^} the service $service_name" >&2 echo "${action^} the service $service_name" >&2
systemctl $action $service_name \ systemctl $action $service_name \
|| ( journalctl --lines=$length -u $service_name >&2 \ || ( journalctl --no-pager --lines=$length -u $service_name >&2 \
; test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \ ; test -e "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \
; false ) ; false )
# Start the timeout and try to find line_match # Start the timeout and try to find line_match
@ -77,8 +75,8 @@ ynh_systemd_action() {
then then
echo "The service $service_name didn't fully started before the timeout." >&2 echo "The service $service_name didn't fully started before the timeout." >&2
echo "Please find here an extract of the end of the log of the service $service_name:" echo "Please find here an extract of the end of the log of the service $service_name:"
journalctl --lines=$length -u $service_name >&2 journalctl --no-pager --lines=$length -u $service_name >&2
test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 test -e "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2
fi fi
echo "" echo ""
@ -95,3 +93,142 @@ ynh_clean_check_starting () {
kill -s 15 $pid_tail 2>&1 kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1 ynh_secure_remove "$templog" 2>&1
} }
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
# | arg: -m --app_message= - The file with the content to send to the administrator.
# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2"
# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
ynh_send_readme_to_admin() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
local app_message
local recipients
local type
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
app_message="${app_message:-}"
recipients="${recipients:-root}"
type="${type:-install}"
# Get the value of admin_mail_html
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
admin_mail_html="${admin_mail_html:-0}"
# Retrieve the email of users
find_mails () {
local list_mails="$1"
local mail
local recipients=" "
# Read each mail in argument
for mail in $list_mails
do
# Keep root or a real email address as it is
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
then
recipients="$recipients $mail"
else
# But replace an user name without a domain after by its email
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
then
recipients="$recipients $mail"
fi
fi
done
echo "$recipients"
}
recipients=$(find_mails "$recipients")
# Subject base
local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
# Adapt the subject according to the type of mail required.
if [ "$type" = "backup" ]; then
mail_subject="$mail_subject has just been backup."
elif [ "$type" = "change_url" ]; then
mail_subject="$mail_subject has just been moved to a new URL!"
elif [ "$type" = "remove" ]; then
mail_subject="$mail_subject has just been removed!"
elif [ "$type" = "restore" ]; then
mail_subject="$mail_subject has just been restored!"
elif [ "$type" = "upgrade" ]; then
mail_subject="$mail_subject has just been upgraded!"
else # install
mail_subject="$mail_subject has just been installed!"
fi
local mail_message="This is an automated message from your beloved YunoHost server.
Specific information for the application $app.
$(if [ -n "$app_message" ]
then
cat "$app_message"
else
echo "...No specific information..."
fi)
---
Automatic diagnosis data from YunoHost
__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
# Store the message into a file for further modifications.
echo "$mail_message" > mail_to_send
# If a html email is required. Apply html tags to the message.
if [ "$admin_mail_html" -eq 1 ]
then
# Insert 'br' tags at each ending of lines.
ynh_replace_string "$" "<br>" mail_to_send
# Insert starting HTML tags
sed --in-place '1s@^@<!DOCTYPE html>\n<html>\n<head></head>\n<body>\n@' mail_to_send
# Keep tabulations
ynh_replace_string " " "\&#160;\&#160;" mail_to_send
ynh_replace_string "\t" "\&#160;\&#160;" mail_to_send
# Insert url links tags
ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "<a href=\"\2\">\1</a>" mail_to_send
# Insert pre tags
ynh_replace_string "__PRE_TAG1__" "<pre>" mail_to_send
ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
# Insert finishing HTML tags
echo -e "\n</body>\n</html>" >> mail_to_send
# Otherwise, remove tags to keep a plain text.
else
# Remove URL tags
ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
ynh_replace_string "__URL_TAG2__" ": " mail_to_send
# Remove PRE tags
ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
fi
# Define binary to use for mail command
if [ -e /usr/bin/bsd-mailx ]
then
local mail_bin=/usr/bin/bsd-mailx
else
local mail_bin=/usr/bin/mail.mailutils
fi
if [ "$admin_mail_html" -eq 1 ]
then
content_type="text/html"
else
content_type="text/plain"
fi
# Send the email to the recipients
cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
}

56
scripts/actions/change_password Executable file
View file

@ -0,0 +1,56 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
# Get is_public
password=${YNH_ACTION_PASSWORD}
hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1)
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
hashed_password_old=$(ynh_app_setting_get $app hashed_password)
if [ "$hashed_password" == "$hashed_password_old" ]
then
ynh_die "Same password." 0
fi
#=================================================
# SPECIFIC ACTION
#=================================================
# MOVE TO PUBLIC OR PRIVATE
#=================================================
ynh_backup_if_checksum_is_different "$final_path/lstu.conf"
ynh_replace_string "$hashed_password_old" "$hashed_password" "${final_path}/lstu.conf"
ynh_store_file_checksum "${final_path}/lstu.conf"
# Update the config of the app
ynh_app_setting_set $app hashed_password $hashed_password
#=================================================
# RELOAD NGINX
#=================================================
ynh_systemd_action -n $app -a reload -l "Reloaded Shortened URLs service." -p "systemd"
#=================================================
# END OF SCRIPT
#=================================================

55
scripts/actions/change_theme Executable file
View file

@ -0,0 +1,55 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
# Get is_public
theme=${YNH_ACTION_THEME}
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
theme_old=$(ynh_app_setting_get $app theme)
if [ "$theme" == "$theme_old" ]
then
ynh_die "Same theme." 0
fi
#=================================================
# SPECIFIC ACTION
#=================================================
# MOVE TO PUBLIC OR PRIVATE
#=================================================
ynh_backup_if_checksum_is_different "$final_path/lstu.conf"
ynh_replace_string "$theme_old" "$theme" "${final_path}/lstu.conf"
ynh_store_file_checksum "${final_path}/lstu.conf"
# Update the config of the app
ynh_app_setting_set $app theme $theme
#=================================================
# RELOAD NGINX
#=================================================
ynh_systemd_action -n $app -a reload -l "Reloaded Shortened URLs service." -p "systemd"
#=================================================
# END OF SCRIPT
#=================================================

101
scripts/actions/public_private Executable file
View file

@ -0,0 +1,101 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
# Get is_public
is_public=${YNH_ACTION_IS_PUBLIC}
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
port=$(ynh_app_setting_get $app port)
final_path=$(ynh_app_setting_get $app final_path)
secret=$(ynh_app_setting_get $app secret)
db_name=$(ynh_app_setting_get $app db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get $app psqlpwd)
theme=$(ynh_app_setting_get $app theme)
hashed_password=$(ynh_app_setting_get $app hashed_password)
#=================================================
# CHECK IF ARGUMENTS ARE CORRECT
#=================================================
#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
is_public_old=$(ynh_app_setting_get $app is_public)
if [ $is_public -eq $is_public_old ]
then
ynh_die "is_public is already set as $is_public." 0
fi
#=================================================
# SPECIFIC ACTION
#=================================================
# MOVE TO PUBLIC OR PRIVATE
#=================================================
ynh_backup_if_checksum_is_different "$final_path/lstu.conf"
cp conf/lstu.conf.template "${final_path}/lstu.conf"
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf"
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf"
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf"
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf"
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf"
ynh_replace_string "__SELECTED_THEME__" "$theme" "${final_path}/lstu.conf"
ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf"
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
if [ $is_public -eq 0 ];
then
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lstu.conf"
else
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lstu.conf"
fi
ynh_store_file_checksum "${final_path}/lstu.conf"
if [ $is_public -eq 0 ]; then
public_private="private"
else
public_private="public"
fi
ynh_app_setting_set $app unprotected_uris "/"
if [ $is_public -eq 0 ];
then # If the app is private, only the shortened URLs are publics
ynh_app_setting_set $app protected_regex "/login$","/logout$","/api$","/extensions$","/stats$","/d/.*$","/a$","/$"
else
ynh_app_setting_delete $app protected_regex
fi
# Regen ssowat configuration
yunohost app ssowatconf
# Update the config of the app
ynh_app_setting_set $app is_public $is_public
#=================================================
# RELOAD NGINX
#=================================================
ynh_systemd_action -n $app -a reload -l "Reloaded Shortened URLs service." -p "systemd"
#=================================================
# END OF SCRIPT
#=================================================

147
scripts/change_url Normal file
View file

@ -0,0 +1,147 @@
#!/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
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get $app final_path)
# Needed for lstu conf
port=$(ynh_app_setting_get $app port)
is_public=$(ynh_app_setting_get $app is_public)
db_name=$(ynh_app_setting_get "$app" db_name)
db_pwd=$(ynh_app_setting_get $app psqlpwd)
db_user=$db_name
secret=$(ynh_app_setting_get $app secret)
theme=$(ynh_app_setting_get $app theme)
hashed_password=$(ynh_app_setting_get $app hashed_password)
#=================================================
# 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
#=================================================
ynh_print_info "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
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"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated nginx config
ynh_add_nginx_config
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
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# SETUP LSTU
#=================================================
ynh_print_info "Updating lstu configuration..."
domain="$new_domain"
path_url="$new_path"
ynh_backup_if_checksum_is_different "$final_path/lstu.conf"
cp ../conf/lstu.conf.template "${final_path}/lstu.conf"
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf"
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf"
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf"
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf"
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf"
ynh_replace_string "__SELECTED_THEME__" "$theme" "${final_path}/lstu.conf"
ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf"
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
if [ $is_public -eq 0 ];
then
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lstu.conf"
else
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lstu.conf"
fi
ynh_store_file_checksum "${final_path}/lstu.conf"
#=================================================
# GENERIC FINALISATION
#=================================================
# RESTART LSTU
#=================================================
ynh_systemd_action -n $app -a reload -l "Starting hot deployment for Hypnotoad server" -p "systemd"
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
systemctl reload nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Change of URL completed for $app"

View file

@ -14,7 +14,8 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script. ynh_clean_check_starting
true true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -27,20 +28,19 @@ ynh_abort_if_errors
domain=$YNH_APP_ARG_DOMAIN domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
theme=$YNH_APP_ARG_THEME
password=$YNH_APP_ARG_PASSWORD
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_print_info "Validating installation parameters..."
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
final_path=/var/www/$app final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die "This path already contains a folder"
domain_regex=$(echo "$domain" | sed 's@-@.@g')
# Normalize the url path syntax # Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url) path_url=$(ynh_normalize_url_path $path_url)
@ -48,11 +48,11 @@ path_url=$(ynh_normalize_url_path $path_url)
ynh_webpath_available $domain $path_url ynh_webpath_available $domain $path_url
# Register (book) web path # Register (book) web path
ynh_webpath_register $app $domain $path_url ynh_webpath_register $app $domain $path_url
CHECK_VAR "$domain_regex" "domain_regex empty"
#================================================= #=================================================
# FIND AND OPEN A PORT # FIND AND OPEN A PORT
#================================================= #=================================================
ynh_print_info "Configuring firewall..."
# Find a free port # Find a free port
port=$(ynh_find_port 8095) port=$(ynh_find_port 8095)
@ -62,23 +62,29 @@ yunohost firewall allow --no-upnp TCP $port 2>&1
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_print_info "Storing installation settings..."
ynh_app_setting_set $app domain $domain ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app port $port ynh_app_setting_set $app port $port
ynh_app_setting_set $app path $path_url ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app theme $theme
hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1)
ynh_app_setting_set $app hashed_password $hashed_password
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Installing dependencies..."
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql cpanminus
# Install Carton # Install Carton
echo yes | cpan Carton echo yes | cpanm Carton
#================================================= #=================================================
# CREATE A POSTGRESQL DATABASE # CREATE A POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Creating a PostgreSQL database..."
# Create postgresql database # Create postgresql database
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
@ -92,6 +98,7 @@ db_pwd=$(ynh_app_setting_get $app psqlpwd) # Password created in ynh_psql_setup_
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_print_info "Setting up source files..."
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
@ -100,6 +107,7 @@ ynh_setup_source "$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Configuring nginx web server..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
@ -107,6 +115,7 @@ ynh_add_nginx_config
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Configuring system user..."
# Create a system user # Create a system user
ynh_system_user_create $app ynh_system_user_create $app
@ -114,6 +123,7 @@ ynh_system_user_create $app
#================================================= #=================================================
## Copy and fix variable into lstu config ## Copy and fix variable into lstu config
#================================================= #=================================================
ynh_print_info "Configuring lstu..."
cp ../conf/lstu.conf.template "${final_path}/lstu.conf" cp ../conf/lstu.conf.template "${final_path}/lstu.conf"
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf" ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf"
@ -122,15 +132,24 @@ ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf"
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf" ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf"
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf" ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf"
ynh_replace_string "__SELECTED_THEME__" "$theme" "${final_path}/lstu.conf"
ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf"
secret=$(ynh_string_random 24) secret=$(ynh_string_random 24)
ynh_app_setting_set $app secret $secret ynh_app_setting_set $app secret $secret
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf" ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
if [ $is_public -eq 0 ];
then
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lstu.conf"
else
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lstu.conf"
fi
ynh_store_file_checksum "${final_path}/lstu.conf" ynh_store_file_checksum "${final_path}/lstu.conf"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_print_info "Configuring a systemd service..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
@ -138,6 +157,7 @@ ynh_add_systemd_config
#================================================= #=================================================
# Install lstu's dependencies via carton # Install lstu's dependencies via carton
#================================================= #=================================================
ynh_print_info "Installing lstu..."
pushd $final_path pushd $final_path
carton install --deployment --without=sqlite --without=mysql carton install --deployment --without=sqlite --without=mysql
@ -146,6 +166,7 @@ popd
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Configuring log rotation..."
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate ynh_use_logrotate
@ -154,22 +175,20 @@ ynh_use_logrotate
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
#================================================= #=================================================
yunohost service add $app --log "/var/log/$app.log" yunohost service add $app --log "/var/log/$app.log" --log "/var/www/$app/log/production.log"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Configuring SSOwat..."
# Make app public or private # Make app public or private
ynh_app_setting_set $app skipped_uris "/" ynh_app_setting_set $app unprotected_uris "/"
if [ $is_public -eq 0 ]; if [ $is_public -eq 0 ];
then # If the app is private, only the shortened URLs are publics then # If the app is private, only the shortened URLs are publics
if [ "$path_url" == "/" ]; then ynh_app_setting_set $app protected_regex "/login$","/logout$","/api$","/extensions$","/stats$","/d/.*$","/a$","/$"
path_url=""
fi
ynh_app_setting_set $app protected_regex "$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$"
else else
ynh_replace_string "#--PRIVATE--" "" "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_app_setting_delete $app protected_regex
fi fi
#================================================= #=================================================
@ -188,6 +207,14 @@ ynh_systemd_action -n $app -a start -l "Server available at" -p "systemd"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..."
# Reload Nginx # Reload Nginx
systemctl reload nginx systemctl reload nginx
yunohost app ssowatconf
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Installation of $app completed"

View file

@ -1,147 +0,0 @@
#=================================================
# POSTGRES HELPERS
#=================================================
# Open a connection as a user
#
# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;"
# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql
#
# usage: ynh_psql_connect_as user pwd [db]
# | arg: user - the user name to connect as
# | arg: pwd - the user password
# | arg: db - the database to connect to
ynh_psql_connect_as() {
user="$1"
pwd="$2"
db="$3"
su --command="PGUSER=\"${user}\" PGPASSWORD=\"${pwd}\" psql \"${db}\"" postgres
}
# # Execute a command as root user
#
# usage: ynh_psql_execute_as_root sql [db]
# | arg: sql - the SQL command to execute
# | arg: db - the database to connect to
ynh_psql_execute_as_root () {
sql="$1"
su --command="psql" postgres <<< "$sql"
}
# Execute a command from a file as root user
#
# usage: ynh_psql_execute_file_as_root file [db]
# | arg: file - the file containing SQL commands
# | arg: db - the database to connect to
ynh_psql_execute_file_as_root() {
file="$1"
db="$2"
su -c "psql $db" postgres < "$file"
}
# Create a database, an user and its password. Then store the password in the app's config
#
# After executing this helper, the password of the created database will be available in $db_pwd
# It will also be stored as "psqlpwd" into the app settings.
#
# usage: ynh_psql_setup_db user name [pwd]
# | arg: user - Owner of the database
# | arg: name - Name of the database
# | arg: pwd - Password of the database. If not given, a password will be generated
ynh_psql_setup_db () {
db_user="$1"
app="$1"
db_name="$2"
new_db_pwd=$(ynh_string_random) # Generate a random password
# If $3 is not given, use new_db_pwd instead for db_pwd.
db_pwd="${3:-$new_db_pwd}"
ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database
ynh_app_setting_set "$app" psqlpwd "$db_pwd" # Store the password in the app's config
}
# Create a database and grant optionnaly privilegies to a user
#
# usage: ynh_psql_create_db db [user [pwd]]
# | arg: db - the database name to create
# | arg: user - the user to grant privilegies
# | arg: pwd - the user password
ynh_psql_create_db() {
db="$1"
user="$2"
pwd="$3"
ynh_psql_create_user "$user" "$pwd"
su --command="createdb --owner=\"${user}\" \"${db}\"" postgres
}
# Drop a database
#
# usage: ynh_psql_drop_db db user
# | arg: db - the database name to drop
# | arg: user - the user to drop
ynh_psql_remove_db() {
db="$1"
user="$2"
su --command="dropdb \"${db}\"" postgres
ynh_psql_drop_user "${user}"
}
# Dump a database
#
# example: ynh_psql_dump_db 'roundcube' > ./dump.sql
#
# usage: ynh_psql_dump_db db
# | arg: db - the database name to dump
# | ret: the psqldump output
ynh_psql_dump_db() {
db="$1"
su --command="pg_dump \"${db}\"" postgres
}
# Create a user
#
# usage: ynh_psql_create_user user pwd [host]
# | arg: user - the user name to create
ynh_psql_create_user() {
user="$1"
pwd="$2"
su --command="psql -c\"CREATE USER ${user} WITH PASSWORD '${pwd}'\"" postgres
}
# Drop a user
#
# usage: ynh_psql_drop_user user
# | arg: user - the user name to drop
ynh_psql_drop_user() {
user="$1"
su --command="dropuser \"${user}\"" postgres
}
ynh_psql_test_if_first_run() {
if [ -f /etc/yunohost/psql ];
then
echo "PostgreSQL is already installed, no need to create master password"
else
pgsql=$(ynh_string_random)
pg_hba=""
echo "$pgsql" >> /etc/yunohost/psql
if [ -e /etc/postgresql/9.4/ ]
then
pg_hba=/etc/postgresql/9.4/main/pg_hba.conf
elif [ -e /etc/postgresql/9.6/ ]
then
pg_hba=/etc/postgresql/9.6/main/pg_hba.conf
else
ynh_die "postgresql shoud be 9.4 or 9.6"
fi
systemctl start postgresql
su --command="psql -c\"ALTER user postgres WITH PASSWORD '${pgsql}'\"" postgres
# we can't use peer since YunoHost create users with nologin
sed -i '/local\s*all\s*all\s*peer/i \
local all all password' "$pg_hba"
systemctl enable postgresql
systemctl reload postgresql
fi
}

View file

@ -12,6 +12,8 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
@ -36,6 +38,7 @@ fi
#================================================= #=================================================
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
#================================================= #=================================================
ynh_print_info "Stopping and removing the systemd service"
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config ynh_remove_systemd_config
@ -43,6 +46,7 @@ ynh_remove_systemd_config
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Removing app main directory"
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove "$final_path" ynh_secure_remove "$final_path"
@ -50,6 +54,7 @@ ynh_secure_remove "$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing nginx web server configuration"
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_remove_nginx_config ynh_remove_nginx_config
@ -63,6 +68,7 @@ ynh_secure_remove "/var/log/$app.log"
#================================================= #=================================================
# REMOVE LOGROTATE CONFIGURATION # REMOVE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing logrotate configuration"
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_remove_logrotate
@ -80,12 +86,30 @@ fi
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Removing dependencies"
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_remove_app_dependencies ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE THE PostgreSQL DATABASE # REMOVE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Removing the PostgreSQL database"
ynh_psql_remove_db $db_name $db_user ynh_psql_remove_db $db_name $db_user
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_print_info "Removing the dedicated system user"
# Delete a system user
ynh_system_user_delete $app
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Removal of $app completed"

View file

@ -14,7 +14,8 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script. ynh_clean_check_starting
true true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -23,6 +24,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -34,6 +36,7 @@ db_name=$(ynh_app_setting_get $app db_name)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_print_info "Validating restoration parameters..."
ynh_webpath_available $domain $path_url \ ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die "Path not available: ${domain}${path_url}"
@ -45,9 +48,12 @@ test ! -d $final_path \
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Reinstalling dependencies..."
# Define and install dependencies # Define and install dependencies
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql cpanminus
# Install Carton
echo yes | cpanm Carton
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
@ -58,23 +64,41 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Restoring the app main directory..."
ynh_restore_file "$final_path" ynh_restore_file "$final_path"
#================================================= #=================================================
# RESTORE THE MYSQL DATABASE # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_print_info "Restoring the PostregSQL database..."
db_pwd=$(ynh_app_setting_get $app psqlpwd) db_pwd=$(ynh_app_setting_get $app psqlpwd)
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_setup_db $db_name $db_name $db_pwd ynh_psql_setup_db $db_name $db_name $db_pwd
ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R www-data $final_path
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_print_info "Restoring the systemd configuration..."
ynh_restore_file "/etc/systemd/system/$app.service" ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service systemctl enable $app.service
@ -84,7 +108,7 @@ ynh_systemd_action -n $app -a start -l "Server available at" -p "systemd"
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
#================================================= #=================================================
yunohost service add $app --log "/var/log/$app.log" yunohost service add $app --log "/var/log/$app.log" --log "/var/www/$app/log/production.log"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
@ -97,6 +121,13 @@ ynh_restore_file "/etc/logrotate.d/$app"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..."
systemctl reload nginx systemctl reload nginx
yunohost app ssowatconf yunohost app ssowatconf
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Restoration completed for $app"

View file

@ -9,20 +9,10 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -35,10 +25,13 @@ secret=$(ynh_app_setting_get $app secret)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get $app db_name)
db_user=$db_name db_user=$db_name
db_pwd=$(ynh_app_setting_get $app psqlpwd) db_pwd=$(ynh_app_setting_get $app psqlpwd)
theme=$(ynh_app_setting_get $app theme)
hashed_password=$(ynh_app_setting_get $app hashed_password)
#================================================= #=================================================
# FIX OLD THINGS # FIX OLD THINGS
#================================================= #=================================================
ynh_print_info "Ensuring downward compatibility..."
if [ "$is_public" = "Yes" ]; then if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen
@ -68,26 +61,73 @@ if [ -z "$db_pwd" ]; then
fi fi
fi fi
if [ -z "$theme" ]; then
theme="milligram"
ynh_app_setting_set $app theme $theme
fi
if [ -z "$hashed_password" ]; then
# Generate random password
password=$(ynh_string_random 8)
hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1)
echo "The new version of LSTU provide an admin and a stats area which required a password.
This password is: $password" > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --type="upgrade"
ynh_app_setting_set $app hashed_password $hashed_password
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_print_info "Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_print_info "Upgrading source files..."
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql cpanminus
ynh_setup_source "$final_path" ynh_setup_source "$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Upgrading nginx web server configuration..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_print_info "Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create $app
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#================================================= #=================================================
# SETUP LSTU # SETUP LSTU
#================================================= #=================================================
ynh_print_info "Upgrading lstu configuration..."
ynh_backup_if_checksum_is_different "$final_path/lstu.conf" ynh_backup_if_checksum_is_different "$final_path/lstu.conf"
cp ../conf/lstu.conf.template "${final_path}/lstu.conf" cp ../conf/lstu.conf.template "${final_path}/lstu.conf"
@ -97,8 +137,16 @@ ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf"
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf" ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf"
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf" ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf"
ynh_replace_string "__SELECTED_THEME__" "$theme" "${final_path}/lstu.conf"
ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf"
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf" ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
if [ $is_public -eq 0 ];
then
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lstu.conf"
else
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lstu.conf"
fi
ynh_store_file_checksum "${final_path}/lstu.conf" ynh_store_file_checksum "${final_path}/lstu.conf"
#================================================= #=================================================
@ -110,6 +158,7 @@ chown -R www-data $final_path
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_print_info "Upgrading systemd configuration..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
@ -125,9 +174,10 @@ popd
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Upgrading logrotate configuration..."
# Use logrotate to manage application logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate ynh_use_logrotate --non-append
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
@ -139,27 +189,32 @@ yunohost service add $app --log "/var/log/$app.log"
# RESTART LSTU # RESTART LSTU
#================================================= #=================================================
ynh_systemd_action -n $app -a reload -l "Starting hot deployment for Hypnotoad server" -p "systemd" ynh_systemd_action -n $app -a reload -l "Reloaded Shortened URLs service." -p "systemd"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Upgrading SSOwat configuration..."
# Make app public or private # Make app public or private
ynh_app_setting_set $app skipped_uris "/" ynh_app_setting_set $app unprotected_uris "/"
if [ $is_public -eq 0 ]; if [ $is_public -eq 0 ];
then # If the app is private, only the shortened URLs are publics then # If the app is private, only the shortened URLs are publics
if [ "$path_url" == "/" ]; then ynh_app_setting_set $app protected_regex "/login$","/logout$","/api$","/extensions$","/stats$","/d/.*$","/a$","/$"
path_url=""
fi
ynh_app_setting_set $app protected_regex "$domain$path_url/login$","$domain$path_url/logout$","$domain$path_url/api$","$domain$path_url/extensions$","$domain$path_url/stats$","$domain$path_url/d/.*$","$domain$path_url/a$","$domain$path_url/$"
else else
ynh_replace_string "#--PRIVATE--" "" "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_app_setting_delete $app protected_regex
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..."
systemctl reload nginx systemctl reload nginx
yunohost app ssowatconf yunohost app ssowatconf
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Upgrade of $app completed"

View file

@ -1,12 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
BEGIN { unshift @INC, "$FindBin::Bin/../local/lib/perl5" }
# Start command line interface for application
require Mojolicious::Commands;
Mojolicious::Commands->start_app('Mounter');