mirror of
https://github.com/YunoHost-Apps/teampass_ynh.git
synced 2024-09-03 20:26:37 +02:00
Tentative of cleanup
This commit is contained in:
parent
70dfff4b45
commit
a8f3fee37f
6 changed files with 79 additions and 127 deletions
1
conf/cron
Normal file
1
conf/cron
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0 0 * * 0 __APP__ cd __INSTALL_DIR__/backups && php__PHPVERSION__ script.backup.php
|
|
@ -22,19 +22,13 @@ ynh_print_info --message="Declaring files to be backed up..."
|
||||||
ynh_backup --src_path="$install_dir"
|
ynh_backup --src_path="$install_dir"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE NGINX CONFIGURATION
|
# SYSTEM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# BACKUP THE PHP-FPM CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
|
ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC BACKUP
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP VARIOUS FILES
|
# BACKUP VARIOUS FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -21,16 +21,7 @@ ynh_setup_source --dest_dir="$install_dir"
|
||||||
ynh_secure_remove --file="$install_dir/install"
|
ynh_secure_remove --file="$install_dir/install"
|
||||||
|
|
||||||
chmod -R o-rwx "$install_dir"
|
chmod -R o-rwx "$install_dir"
|
||||||
chown -R $app:www-data "$install_dir"
|
chown -R "$app:www-data" "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# PHP-FPM CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
|
|
||||||
|
|
||||||
ynh_add_fpm_config
|
|
||||||
|
|
||||||
ynh_add_nginx_config
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP
|
# SPECIFIC SETUP
|
||||||
|
@ -45,24 +36,23 @@ timezone="$(cat /etc/timezone)"
|
||||||
time="$(date +%s)"
|
time="$(date +%s)"
|
||||||
|
|
||||||
# Remplacement des variables dans le fichier sql
|
# Remplacement des variables dans le fichier sql
|
||||||
if [ $(echo $LANG | cut -c1-2) == "fr" ]
|
if [ "$(echo $LANG | cut -c1-2)" == "fr" ]; then
|
||||||
then
|
langue=french
|
||||||
langue=french
|
folders="partagés"
|
||||||
folders="partagés"
|
roles=utilisateurs
|
||||||
roles=utilisateurs
|
|
||||||
else
|
else
|
||||||
langue=english
|
langue=english
|
||||||
folders=shared
|
folders=shared
|
||||||
roles=users
|
roles=users
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_add_config --template="../conf/populate.sql" --destination="$install_dir/populate.sql"
|
ynh_add_config --template="../conf/populate.sql" --destination="$install_dir/populate.sql"
|
||||||
|
|
||||||
# Enregistre les infos dans la config YunoHost
|
# Enregistre les infos dans la config YunoHost
|
||||||
ynh_app_setting_set --app=$app --key=langue --value=$langue
|
ynh_app_setting_set --app="$app" --key=langue --value=$langue
|
||||||
|
|
||||||
# Import du fichier SQL
|
# Import du fichier SQL
|
||||||
ynh_mysql_connect_as $db_name $db_pwd $db_name < $install_dir/populate.sql
|
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "$install_dir/populate.sql"
|
||||||
ynh_secure_remove --file="$install_dir/populate.sql"
|
ynh_secure_remove --file="$install_dir/populate.sql"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -77,11 +67,12 @@ ynh_add_config --template="settings.php" --destination="$install_dir/includes/co
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Creating tp.config.php file..."
|
ynh_script_progression --message="Creating tp.config.php file..."
|
||||||
|
|
||||||
cp $YNH_APP_BASEDIR/conf/maketpconfig.php $install_dir/
|
cp "$YNH_APP_BASEDIR/conf/maketpconfig.php" "$install_dir/"
|
||||||
|
|
||||||
pushd $install_dir
|
pushd $install_dir
|
||||||
ynh_exec_as $app php$phpversion maketpconfig.php
|
ynh_exec_as "$app" "php$phpversion" maketpconfig.php
|
||||||
popd
|
popd
|
||||||
ynh_secure_remove $install_dir/maketpconfig.php
|
ynh_secure_remove "$install_dir/maketpconfig.php"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE A SALTKEY
|
# CREATE A SALTKEY
|
||||||
|
@ -128,11 +119,15 @@ ynh_replace_string "jsUrl\" => \"" "&includes/libraries/csrfp/js/csrfprotector.j
|
||||||
# done
|
# done
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE A CRON FILE FOR AN AUTOMATIC BACKUP
|
# SYSTEM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Creating a cron file for an automatic backup..."
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
||||||
|
|
||||||
echo "0 0 * * 0 $app cd $install_dir/backups && php script.backup.php" > /etc/cron.d/$app
|
ynh_add_fpm_config
|
||||||
|
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SECURING FILES AND DIRECTORIES
|
# SECURING FILES AND DIRECTORIES
|
||||||
|
@ -141,13 +136,13 @@ echo "0 0 * * 0 $app cd $install_dir/backups && php script.backup.php" > /etc/cr
|
||||||
# Les fichiers appartiennent à root
|
# Les fichiers appartiennent à root
|
||||||
chmod 750 "$install_dir"
|
chmod 750 "$install_dir"
|
||||||
chmod -R o-rwx "$install_dir"
|
chmod -R o-rwx "$install_dir"
|
||||||
chown -R $app:www-data "$install_dir"
|
chown -R "$app:www-data" "$install_dir"
|
||||||
|
|
||||||
# Sauf certains dossiers includes, files et upload
|
# Sauf certains dossiers includes, files et upload
|
||||||
chown -R $app $install_dir/{includes,files,upload}
|
chown -R "$app" "$install_dir"/{includes,files,upload}
|
||||||
# Restreint l'accès au dossier de backup
|
# Restreint l'accès au dossier de backup
|
||||||
mkdir -p $install_dir/backups
|
mkdir -p "$install_dir/backups"
|
||||||
chmod 750 $install_dir/backups
|
chmod 750 "$install_dir/backups"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
|
@ -10,28 +10,16 @@ source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE NGINX CONFIGURATION
|
# REMOVE SYSTEM CONFIGURATIONS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
|
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
|
||||||
|
|
||||||
# Remove the dedicated NGINX config
|
# Remove the dedicated NGINX config
|
||||||
ynh_remove_nginx_config
|
ynh_remove_nginx_config
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# REMOVE PHP-FPM CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Removing PHP-FPM configuration..." --weight=1
|
|
||||||
|
|
||||||
# Remove the dedicated PHP-FPM config
|
# Remove the dedicated PHP-FPM config
|
||||||
ynh_remove_fpm_config
|
ynh_remove_fpm_config
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC REMOVE
|
|
||||||
#=================================================
|
|
||||||
# REMOVE VARIOUS FILES
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Removing various files..."
|
|
||||||
|
|
||||||
# Remove a directory securely
|
# Remove a directory securely
|
||||||
ynh_secure_remove --file="/etc/$app"
|
ynh_secure_remove --file="/etc/$app"
|
||||||
|
|
||||||
|
|
|
@ -19,24 +19,10 @@ ynh_restore_file --origin_path="$install_dir"
|
||||||
|
|
||||||
chmod 750 "$install_dir"
|
chmod 750 "$install_dir"
|
||||||
chmod -R o-rwx "$install_dir"
|
chmod -R o-rwx "$install_dir"
|
||||||
chown -R $app:www-data "$install_dir"
|
chown -R "$app:www-data" "$install_dir"
|
||||||
|
|
||||||
# Sauf les dossiers includes, files et upload
|
# Sauf les dossiers includes, files et upload
|
||||||
chown -R $app $install_dir/{includes,files,upload}
|
chown -R "$app" "$install_dir"/{includes,files,upload}
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RESTORE THE PHP-FPM CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Restoring the PHP-FPM configuration..."
|
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RESTORE THE NGINX CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
|
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE MYSQL DATABASE
|
# RESTORE THE MYSQL DATABASE
|
||||||
|
@ -45,15 +31,23 @@ ynh_script_progression --message="Restoring the MySQL database..." --weight=1
|
||||||
|
|
||||||
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE SYSTEM CONFIGURATIONS
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE VARIOUS FILES
|
# RESTORE VARIOUS FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Restoring various files..."
|
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/cron.d/$app"
|
ynh_restore_file --origin_path="/etc/cron.d/$app"
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/$app/sk.php"
|
ynh_restore_file --origin_path="/etc/$app/sk.php"
|
||||||
chown -R $app "/etc/$app/sk.php"
|
chown -R "$app" "/etc/$app/sk.php"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
|
@ -62,7 +56,7 @@ chown -R $app "/etc/$app/sk.php"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
|
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
|
||||||
|
|
||||||
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
|
ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload
|
||||||
ynh_systemd_action --service_name=nginx --action=reload
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -9,44 +9,25 @@
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# CHECK VERSION
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
upgrade_type=$(ynh_check_app_version_changed)
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD UPGRADE STEPS
|
# STANDARD UPGRADE STEPS
|
||||||
#=================================================
|
#=================================================
|
||||||
# ENSURE DOWNWARD COMPATIBILITY
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Ensuring downward compatibility..."
|
# ynh_script_progression --message="Ensuring downward compatibility..."
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Upgrading source files..."
|
||||||
|
|
||||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
then
|
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="includes/config/settings.php includes/libraries/csrfp/libs/csrfp.config.php files upload backups"
|
||||||
ynh_script_progression --message="Upgrading source files..."
|
# Do not delete the install directory. Keep it for the manual upgrade process...
|
||||||
|
# ynh_secure_remove "$install_dir/install"
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
|
||||||
ynh_setup_source --dest_dir="$install_dir"
|
|
||||||
# Do not delete the install directory. Keep it for the manual upgrade process...
|
|
||||||
# ynh_secure_remove "$install_dir/install"
|
|
||||||
fi
|
|
||||||
|
|
||||||
chmod -R o-rwx "$install_dir"
|
chmod -R o-rwx "$install_dir"
|
||||||
chown -R $app:www-data "$install_dir"
|
chown -R "$app:www-data" "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# PHP-FPM CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
|
|
||||||
|
|
||||||
ynh_add_fpm_config
|
|
||||||
|
|
||||||
ynh_add_nginx_config
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC UPGRADE
|
# SPECIFIC UPGRADE
|
||||||
|
@ -76,39 +57,27 @@ ynh_script_progression --message="Updating a configuration file..."
|
||||||
|
|
||||||
ynh_add_config --template="settings.php" --destination="$install_dir/includes/config/settings.php"
|
ynh_add_config --template="settings.php" --destination="$install_dir/includes/config/settings.php"
|
||||||
|
|
||||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
# Move settings.php from old teampass version
|
||||||
then
|
if [ ! -e "$install_dir/includes/config/settings.php" ]; then
|
||||||
# Move settings.php from old teampass version
|
mv "$install_dir/includes/settings.php" "$install_dir/includes/config/settings.php"
|
||||||
if [ ! -e "$install_dir/includes/config/settings.php" ]
|
|
||||||
then
|
|
||||||
mv "$install_dir/includes/settings.php" "$install_dir/includes/config/settings.php"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create csrfp.config.php
|
|
||||||
if [ ! -e "$install_dir/includes/libraries/csrfp/libs/csrfp.config.php" ]
|
|
||||||
then
|
|
||||||
cp $install_dir/includes/libraries/csrfp/libs/csrfp.config.sample.php $install_dir/includes/libraries/csrfp/libs/csrfp.config.php # Créer le fichier de config de csrfp
|
|
||||||
ynh_replace_string "CSRFP_TOKEN\" => \"" "&$(head -n40 /dev/urandom | tr -c -d 'a-f0-9' | head -c50)" $install_dir/includes/libraries/csrfp/libs/csrfp.config.php # Renseigne un token, valide en hexadécimal
|
|
||||||
ynh_replace_string "jsUrl\" => \"" "&includes/libraries/csrfp/js/csrfprotector.js" $install_dir/includes/libraries/csrfp/libs/csrfp.config.php # Renseigne l'adresse de csrfprotector.js
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run database upgrades
|
|
||||||
# Upgrade to 2.1.23.4
|
|
||||||
#ynh_mysql_execute_as_root "ALTER TABLE teampass_misc ADD id INT(12) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (id);" $app >&2
|
|
||||||
# Upgrade to 2.1.24.4
|
|
||||||
#ynh_mysql_execute_as_root "ALTER TABLE teampass_items CHANGE pw_len pw_len INT(5) NOT NULL DEFAULT '0';" $app >&2
|
|
||||||
# Upgrade to 2.1.25.2
|
|
||||||
#ynh_mysql_execute_as_root "INSERT INTO teampass_misc (id, type, intitule, valeur) VALUES (NULL, 'admin', 'encryption_protocol', 'ctr');" $app >&2
|
|
||||||
# Upgrade to 2.1.27.x
|
|
||||||
#ynh_mysql_execute_as_root "ALTER TABLE teampass_misc CHANGE id increment_id INT(12) NOT NULL AUTO_INCREMENT;" $app >&2
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
# Create csrfp.config.php
|
||||||
# CREATE A CRON FILE FOR AN AUTOMATIC BACKUP
|
if [ ! -e "$install_dir/includes/libraries/csrfp/libs/csrfp.config.php" ]; then
|
||||||
#=================================================
|
cp $install_dir/includes/libraries/csrfp/libs/csrfp.config.sample.php $install_dir/includes/libraries/csrfp/libs/csrfp.config.php # Créer le fichier de config de csrfp
|
||||||
ynh_script_progression --message="Creating a cron file for an automatic backup..."
|
ynh_replace_string "CSRFP_TOKEN\" => \"" "&$(head -n40 /dev/urandom | tr -c -d 'a-f0-9' | head -c50)" $install_dir/includes/libraries/csrfp/libs/csrfp.config.php # Renseigne un token, valide en hexadécimal
|
||||||
|
ynh_replace_string "jsUrl\" => \"" "&includes/libraries/csrfp/js/csrfprotector.js" $install_dir/includes/libraries/csrfp/libs/csrfp.config.php # Renseigne l'adresse de csrfprotector.js
|
||||||
|
fi
|
||||||
|
|
||||||
echo "0 0 * * 0 $app cd $install_dir/backups && php script.backup.php" > /etc/cron.d/$app
|
# Run database upgrades
|
||||||
|
# Upgrade to 2.1.23.4
|
||||||
|
#ynh_mysql_execute_as_root "ALTER TABLE teampass_misc ADD id INT(12) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (id);" $app >&2
|
||||||
|
# Upgrade to 2.1.24.4
|
||||||
|
#ynh_mysql_execute_as_root "ALTER TABLE teampass_items CHANGE pw_len pw_len INT(5) NOT NULL DEFAULT '0';" $app >&2
|
||||||
|
# Upgrade to 2.1.25.2
|
||||||
|
#ynh_mysql_execute_as_root "INSERT INTO teampass_misc (id, type, intitule, valeur) VALUES (NULL, 'admin', 'encryption_protocol', 'ctr');" $app >&2
|
||||||
|
# Upgrade to 2.1.27.x
|
||||||
|
#ynh_mysql_execute_as_root "ALTER TABLE teampass_misc CHANGE id increment_id INT(12) NOT NULL AUTO_INCREMENT;" $app >&2
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SECURING FILES AND DIRECTORIES
|
# SECURING FILES AND DIRECTORIES
|
||||||
|
@ -122,13 +91,24 @@ chown -R $app:www-data "$install_dir"
|
||||||
# Sauf certains dossiers includes, install, files et upload
|
# Sauf certains dossiers includes, install, files et upload
|
||||||
chown -R $app $install_dir/{includes,files,upload}
|
chown -R $app $install_dir/{includes,files,upload}
|
||||||
if [ -d "$install_dir/install" ]; then
|
if [ -d "$install_dir/install" ]; then
|
||||||
chown -R $app "$install_dir/install"
|
chown -R $app "$install_dir/install"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Restreint l'accès au dossier de backup
|
# Restreint l'accès au dossier de backup
|
||||||
mkdir -p $install_dir/backups
|
mkdir -p $install_dir/backups
|
||||||
chmod 750 $install_dir/backups
|
chmod 750 $install_dir/backups
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# PHP-FPM CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
|
||||||
|
|
||||||
|
ynh_add_fpm_config
|
||||||
|
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue