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

Set rights (#274)

* Set rights
This commit is contained in:
Éric Gaspar 2021-09-16 11:39:20 +02:00 committed by GitHub
parent f2e7751449
commit 73f75150fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 86 deletions

View file

@ -19,7 +19,7 @@
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=202cc0725652d4b8fbca52630267247bd58c8de1
upgrade=1 from_commit=4fa3ee4ad82a6154f2eb858a3da285a35afecef8
backup_restore=1
multi_instance=1
port_already_use=0
@ -43,11 +43,11 @@
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=202cc0725652d4b8fbca52630267247bd58c8de1
upgrade=1 from_commit=4fa3ee4ad82a6154f2eb858a3da285a35afecef8
;;; Options
Email=kemenaran@gmail.com
Notification=none
;;; Upgrade options
; commit=202cc0725652d4b8fbca52630267247bd58c8de1
name=Merge pull request #196 from amyblais/patch-51
; commit=4fa3ee4ad82a6154f2eb858a3da285a35afecef8
name= Merge pull request #268 from YunoHost-Apps/testing

View file

@ -26,6 +26,7 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
@ -42,7 +43,7 @@ ynh_backup --src_path="$final_path"
# BACKUP THE APP DATA
#=================================================
ynh_backup --src_path="/home/yunohost.app/$app" --is_big
ynh_backup --src_path="$data_path" --is_big
#=================================================
# BACKUP THE NGINX CONFIGURATION

View file

@ -69,6 +69,14 @@ ynh_script_progression --message="Finding an available port..." --weight=3
port=$(ynh_find_port --port=8065)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
@ -76,18 +84,9 @@ ynh_script_progression --message="Creating a MySQL database..." --weight=10
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create --username=$app
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@ -104,17 +103,23 @@ elif [ "$version" = "Team" ]; then
ynh_setup_source --dest_dir="$final_path" --source_id="$architecture"
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# CREATE DIRECTORY FOR DATA
#=================================================
ynh_script_progression --message="Creating the data directory..." --weight=1
# Create datadir folder
mkdir -p "/home/yunohost.app/$app"
# Define app's data directory
data_path="/home/yunohost.app/$app"
# Give permission to the datadir
chown -R $app: "$data_path"
data_path=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=data_path --value=$data_path
mkdir -p $data_path
chmod 750 "$data_path"
chmod -R o-rwx "$data_path"
chown -R $app:www-data "$data_path"
#=================================================
# HANDLE LOG FILES AND LOGROTATE
@ -142,13 +147,6 @@ url=https://$domain$path_url
ynh_add_config --template="../conf/config.json" --destination="$final_path/config/config.json"
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
chown -R $app: $final_path
chmod -R g+w $final_path
#=================================================
# NGINX CONFIGURATION
#=================================================

View file

@ -20,6 +20,7 @@ port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
#=================================================
# STANDARD REMOVE
@ -59,7 +60,7 @@ ynh_script_progression --message="Removing $app main directory..." --weight=6
ynh_secure_remove --file="$final_path"
# We don't delete this dir as it is marked as is-big
# ynh_secure_remove --file="/home/yunohost.app/$app"
# ynh_secure_remove --file="$data_path"
#=================================================
# REMOVE NGINX CONFIGURATION

View file

@ -32,14 +32,13 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
@ -51,6 +50,14 @@ test ! -d $final_path \
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
@ -58,20 +65,22 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
ynh_restore_file --origin_path="$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# RESTORE THE APP DATA
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=4
ynh_restore_file --origin_path="/home/yunohost.app/$app" --not_mandatory
chown -R $app: "/home/yunohost.app/$app"
ynh_restore_file --origin_path="$data_path" --not_mandatory
mkdir -p $data_path
chmod 750 "$data_path"
chmod -R o-rwx "$data_path"
chown -R $app:www-data "$data_path"
#=================================================
# RESTORE THE MYSQL DATABASE
@ -86,10 +95,6 @@ ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R $app: $final_path
chmod -R g+w $final_path
logs_path="/var/log/$app"
mkdir -p $logs_path
chown -R $app: $logs_path

View file

@ -34,6 +34,7 @@ language=$(ynh_app_setting_get --app=$app --key=language)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
architecture=$(ynh_detect_arch)
version=$(ynh_app_setting_get --app=$app --key=version)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
#=================================================
# CHECK VERSION
@ -43,6 +44,20 @@ ynh_script_progression --message="Checking version..." --weight=1
previous_upstream_version="$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json")"
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# 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
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -70,6 +85,12 @@ if [ -z "$db_name" ]; then
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
# If final_path doesn't exist, create it
if [ -z "$data_path" ]; then
data_path="/home/yunohost.app/$app"
ynh_app_setting_set --app=$app --key=data_path --value=$data_path
fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
@ -77,20 +98,6 @@ if ynh_legacy_permissions_exists; then
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# 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
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
@ -100,6 +107,14 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@ -130,6 +145,10 @@ then
ynh_secure_remove --file="$tmpdir"
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
@ -138,14 +157,6 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." -
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# SETUP SYSTEMD
#=================================================
@ -154,26 +165,6 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# CREATE DIRECTORY FOR DATA
#=================================================
ynh_script_progression --message="Creating the data directory..." --weight=1
# Define app's data directory
data_path="/home/yunohost.app/$app"
# Create datadir folder
mkdir -p $data_path
# Give permission to the datadir
chown -R $app: "$data_path"
#=================================================
# RESTORE FILE PERMISSIONS
#=================================================
chown -R $app: $final_path
chmod -R g+w $final_path
chown -R $app: "/var/log/$app"
#=================================================
# SETUP LOGROTATE
#=================================================