diff --git a/scripts/backup b/scripts/backup index 27e6444..3b36061 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,32 +8,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_print_info --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) - -#================================================= -# STOP SYSTEMD SERVICE -#================================================= - -ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --log_path="systemd" - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -48,19 +20,11 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$install_dir" --not_mandatory #================================================= -# BACKUP THE NGINX CONFIGURATION +# BACKUP THE SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# START SYSTEMD SERVICE -#================================================= - -ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 5016a21..1232e75 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,70 +7,12 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN -#REMOVEME? old_path=$YNH_APP_OLD_PATH - -#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN -#REMOVEME? new_path=$YNH_APP_NEW_PATH - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? # Needed for helper "ynh_add_nginx_config" -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) - -#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - #REMOVEME? ynh_clean_check_starting - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. -#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -#REMOVEME? change_domain=0 -#REMOVEME? if [ "$old_domain" != "$new_domain" ] -then - #REMOVEME? change_domain=1 -fi - -#REMOVEME? change_path=0 -#REMOVEME? if [ "$old_path" != "$new_path" ] -then - #REMOVEME? change_path=1 -fi - -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --log_path="systemd" +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" #================================================= # MODIFY URL IN NGINX CONF @@ -81,56 +21,24 @@ ynh_script_progression --message="Updating NGINX web server configuration..." ynh_change_url_nginx_config -#REMOVEME? 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 -#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper -#REMOVEME? domain="$old_domain" -#REMOVEME? path="$new_path" - # Create a dedicated NGINX config -#REMOVEME? 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 -#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path" -#REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location -#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi - -#================================================= -# SPECIFIC MODIFICATIONS #================================================= # MODIFY JENKINS SETUP #================================================= ynh_script_progression --message="Updating Jenkins setup..." -ynh_replace_string --match_string="Environment=\"JENKINS_PREFIX=$old_path\"" --replace_string="Environment=\"JENKINS_PREFIX=$new_path\"" --target_file="/lib/systemd/system/jenkins.service" +ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \ + --match_string="Environment=\"JENKINS_PREFIX=$old_path\"" \ + --replace_string="Environment=\"JENKINS_PREFIX=$new_path\"" + systemctl daemon-reload --quiet -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --line_match="Started" --log_path="systemd" - -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." - -#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 525b909..396a233 100644 --- a/scripts/install +++ b/scripts/install @@ -1,13 +1,10 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh -source ynh_send_readme_to_admin__2 source /usr/share/yunohost/helpers #================================================= @@ -15,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= jenkins_version=$(ynh_app_upstream_version) -ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1 +ynh_app_setting_set --app="$app" --key="overwrite_nginx" --value="1" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -29,8 +26,6 @@ ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$install_dir" chmod -R o-rwx "$install_dir" chown -R "$app:$app" "$install_dir" -#================================================= -# SPECIFIC SETUP #================================================= # INSTALL JENKINS #================================================= @@ -59,7 +54,7 @@ ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \ --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" systemctl daemon-reload --quiet -ynh_systemd_action --service_name="$app" --action="restart" --line_match="Started" --log_path="systemd" +ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" if [[ $dpkg_install_failed -ge 1 ]]; then dpkg --configure -a @@ -129,7 +124,7 @@ yunohost service add "$app" --description="Jenkins Continuous Integration Server ynh_script_progression --message="Starting a systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="restart" --line_match="Started" --log_path="systemd" +ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 4f6c8b7..05e04f1 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -19,7 +17,7 @@ if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then yunohost service remove "$app" fi -ynh_systemd_action --service_name="$app" --action="stop" --line_match="Stopped" --log_path="systemd" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" # Remove the dedicated NGINX config ynh_remove_nginx_config diff --git a/scripts/restore b/scripts/restore index ef942d7..b50f757 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,75 +1,21 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source ../settings/scripts/ynh_send_readme_to_admin__2 source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restoring the app main directory..." --weight=1 -#REMOVEME? ynh_clean_setup () { - # Clean installation remaining that are not handle by the remove script. - ynh_clean_check_starting - # Stop change_port() - ynh_exec_warn_less kill -s 15 $pid_change_port -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors +ynh_restore_file --origin_path="$install_dir" --not_mandatory -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." - -#REMOVEME? test ! -d $install_dir \ - || ynh_die --message="There is already a directory: $install_dir " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." - -# Define and install dependencies -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +chown -R "$app:www-data" "$install_dir" #================================================= # INSTALL JENKINS @@ -83,55 +29,29 @@ dpkg --install --force-confnew ../conf/jenkins.deb #================================================= # SETUP APPLICATION #================================================= -ynh_script_progression --message="Setuping application..." +ynh_script_progression --message="Setting up $app's service..." -ynh_replace_string --match_string="Environment=\"JENKINS_PORT=8080\"" --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" --target_file="/lib/systemd/system/jenkins.service" +ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \ + --match_string="Environment=\"JENKINS_PORT=8080\"" \ + --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" systemctl daemon-reload --quiet -ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd" +#================================================= +# RESTORE SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +yunohost service add "$app" --description="Jenkins Continuous Integration Server" #================================================= -# RESTORE THE APP MAIN DIR +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Restoring the app main directory..." +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 -ynh_restore_file --origin_path="$install_dir" --not_mandatory - -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --description="Jenkins Continuous Integration Server" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." - -ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd" - -#================================================= -# SEND A README FOR THE ADMIN -#================================================= - -# Get main domain and buid the url of the admin panel of the app. -admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" - -echo "You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. -You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. - -If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/jenkins_ynh__URL_TAG3__." > mail_to_send - -ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=restore - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 3a16436..6c657f2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,23 +1,18 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh -source ynh_send_readme_to_admin__2 source /usr/share/yunohost/helpers -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="stop" --line_match="Stopped" --log_path="systemd" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -68,7 +63,7 @@ ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \ --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" systemctl daemon-reload --quiet -ynh_systemd_action --service_name="$app" --action="restart" --line_match="Started" --log_path="systemd" +ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" #================================================= # UPGRADE PLUGINS @@ -99,9 +94,9 @@ yunohost service add "$app" --description="Jenkins Continuous Integration Server #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="restart" --line_match="Started" --log_path="systemd" +ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" #================================================= # END OF SCRIPT diff --git a/scripts/ynh_send_readme_to_admin__2 b/scripts/ynh_send_readme_to_admin__2 deleted file mode 100644 index 8b1edf1..0000000 --- a/scripts/ynh_send_readme_to_admin__2 +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/bash - -# 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. - -$(cat "$app_message")" - - # 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 "$" "
" mail_to_send - - # Insert starting HTML tags - sed --in-place '1s@^@\n\n\n\n@' mail_to_send - - # Keep tabulations - ynh_replace_string " " "\ \ " mail_to_send - ynh_replace_string "\t" "\ \ " mail_to_send - - # Insert url links tags - ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "\1" mail_to_send - - # Insert finishing HTML tags - echo -e "\n\n" >> 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 - 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" -}