1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dont-code_ynh.git synced 2024-09-03 18:26:34 +02:00

regroup code into common.sh

This commit is contained in:
Salamandar 2024-01-05 16:27:40 +01:00
parent dd69364d91
commit 51e94e2719
5 changed files with 30 additions and 37 deletions

View file

@ -22,13 +22,31 @@ ynh_java="/usr/lib/jvm/java-${java_version}-openjdk-amd64/bin/java"
# PERSONAL HELPERS
#=================================================
append_uri() {
local return="";
if [[ $1 == */ ]]; then
return=$1$2;
else
return=$1/$2
fi
echo "$return";
local return="";
if [[ $1 == */ ]]; then
return=$1$2;
else
return=$1/$2
fi
echo "$return";
}
_install_restart_script_and_sudoers() {
# Enable restarting of services from ssh
ynh_add_config --template="restart-services.sh" --destination="$install_dir/restart-services.sh"
chown "$app:$app" "$install_dir/restart-services.sh"
chmod o-rwx,gu=rwx "$install_dir/restart-services.sh"
# Add sudoers file for this specific command
ynh_add_config --template="dont-code-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
}
_remove_restart_script_and_sudoers() {
if [ -f "/etc/sudoers.d/$app-sudoers" ]; then
ynh_secure_remove --file="/etc/sudoers.d/$app-sudoers"
fi
}
#=================================================

View file

@ -66,15 +66,7 @@ if [ -n "$public_key" ]; then
chmod 700 "$install_dir/.ssh"
chmod 600 "$install_dir/.ssh/authorized_keys"
# Enable restarting of services from ssh
ynh_add_config --template="restart-services.sh" --destination="$install_dir/restart-services.sh"
chown "$app:$app" "$install_dir/restart-services.sh"
chmod o-rwx,gu=rwx "$install_dir/restart-services.sh"
# Add sudoers file for this specific command
ynh_add_config --template="dont-code-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
_install_restart_script_and_sudoers
fi
#=================================================

View file

@ -42,9 +42,7 @@ done
# Remove mongo itself if not used anymore
ynh_remove_mongo
if [ -f "/etc/sudoers.d/$app-sudoers" ]; then
ynh_secure_remove --file="/etc/sudoers.d/$app-sudoers"
fi
_remove_restart_script_and_sudoers
# Remove the log files
ynh_secure_remove --file="/var/log/$app"

View file

@ -48,14 +48,7 @@ if [ -n "$public_key" ]; then
chmod 700 "$install_dir/.ssh"
chmod 600 "$install_dir/.ssh/authorized_keys"
# Enable restart of services for the dont-code user
chown "$app:$app" "$install_dir/restart-services.sh"
chmod o-rwx,gu=rwx "$install_dir/restart-services.sh"
# Add sudoers file for this specific command
ynh_restore_file --origin_path="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
_install_restart_script_and_sudoers
fi
#=================================================
@ -76,6 +69,7 @@ ynh_mongo_setup_db --db_user=$db_user --db_name=${MONGO_DB_LIST[0]} --db_pwd=$db
for db_name in "${MONGO_DB_LIST[@]}"; do
ynh_mongo_restore_db --database="$db_name" < "./dump-${db_name}.bson"
done
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================

View file

@ -91,16 +91,7 @@ chown "$app:www-data" "$data_dir"
if [ -n "$public_key" ]; then
ynh_script_progression --message="Upgrading ssh access for dev..." --weight=1
# Enable restarting of services from ssh
ynh_add_config --template="restart-services.sh" --destination="$install_dir/restart-services.sh"
chown "$app:$app" "$install_dir/restart-services.sh"
chmod o-rwx,gu=rwx "$install_dir/restart-services.sh"
# Add sudoers file for this specific command
ynh_add_config --template="dont-code-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
_install_restart_script_and_sudoers
fi
#=================================================