From 7c9c3c365d5ad6f26b91c4b7a6febea8f9414942 Mon Sep 17 00:00:00 2001 From: anmol26s Date: Mon, 22 Feb 2021 00:01:28 +0530 Subject: [PATCH] Fix install and upgrade --- scripts/_common.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 23 +++++++++++++++++--- scripts/upgrade | 6 +++--- 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 7e55ac0..97fcd3f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -18,3 +18,56 @@ pkg_dependencies="deb1 deb2 php$YNH_DEFAULT_PHP_VERSION-deb1 php$YNH_DEFAULT_PHP #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +# Send an email to inform the administrator +# +# usage: ynh_send_readme_to_admin app_message [recipients] +# | arg: app_message - The message to send to the administrator. +# | arg: 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" +ynh_send_readme_to_admin() { + local app_message="${1:-...No specific information...}" + local recipients="${2:-root}" + + # 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") + + local mail_subject="☁️🆈🅽🅷☁️: \`$app\` has important message for you" + + local mail_message="This is an automated message from your beloved YunoHost server. Specific information for $app. +$app_message" + + # 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 + + # Send the email to the recipients + echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" +} \ No newline at end of file diff --git a/scripts/install b/scripts/install index 58ab20e..7701d48 100755 --- a/scripts/install +++ b/scripts/install @@ -95,9 +95,9 @@ ynh_script_progression --message="Setting up source files..." --weight=1 ynh_app_setting_set --app=$app --key=final_path --value=$final_path mkdir "$final_path" -cp -f ../conf/default.yml "$final_path/docker-compose.yml" -cp -f ../conf/default.yml "$final_path/lemmy.hjson" -cp -f ../conf/default.yml "$final_path/iframely.config.local.js" +cp -f ../conf/docker-compose.yml "$final_path/docker-compose.yml" +cp -f ../conf/lemmy.hjson "$final_path/lemmy.hjson" +cp -f ../conf/iframely.config.local.js "$final_path/iframely.config.local.js" pushd "$final_path" mkdir -p volumes/pictrs chown -R 991:991 volumes/pictrs @@ -151,6 +151,23 @@ ynh_systemd_action --service_name=nginx --action=reload cd "$final_path" && docker-compose up -d +#================================================= +# SEND A README FOR THE ADMIN +#================================================= + +message="Lemmy was successfully installed :) + +Please open https://$domain$path_url + +Your credentials for the admin panel are: +- admin username: $admin +- admin password: $password + +If you facing an issue or want to improve Lemmy, please open a new issue in this project: https://github.com/YunoHost-Apps/lemmy_ynh/issues" + +ynh_send_readme_to_admin "$message" + + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 435a637..9d8aa56 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -58,9 +58,9 @@ then ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src - cp -f ../conf/default.yml "$final_path/docker-compose.yml" - cp -f ../conf/default.yml "$final_path/lemmy.hjson" - cp -f ../conf/default.yml "$final_path/iframely.config.local.js" + cp -f ../conf/docker-compose.yml "$final_path/docker-compose.yml" + cp -f ../conf/lemmy.hjson "$final_path/lemmy.hjson" + cp -f ../conf/iframely.config.local.js "$final_path/iframely.config.local.js" pushd "$final_path" chown -R 991:991 volumes/pictrs popd