From b13d9277a140b3e15252b6fe99c2b2c1b206bdd0 Mon Sep 17 00:00:00 2001 From: nemsia Date: Fri, 6 Apr 2018 13:26:46 +0200 Subject: [PATCH 01/45] upgrade-2.3.3 upgrade-2.3.3 git fetch with all tags forced --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 8e33ce8..50904f1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -43,7 +43,7 @@ sudo chown -R $app: $final_path/live # Download Mastodon sudo su - $app < Date: Fri, 6 Apr 2018 19:58:23 +0200 Subject: [PATCH 02/45] Rename .fonctions to _common.sh --- scripts/{.fonctions => _common.sh} | 0 scripts/backup | 8 ++++---- scripts/install | 2 +- scripts/remove | 8 ++++---- scripts/restore | 8 ++++---- scripts/upgrade | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) rename scripts/{.fonctions => _common.sh} (100%) diff --git a/scripts/.fonctions b/scripts/_common.sh similarity index 100% rename from scripts/.fonctions rename to scripts/_common.sh diff --git a/scripts/backup b/scripts/backup index e4a5bba..ffcac0e 100644 --- a/scripts/backup +++ b/scripts/backup @@ -3,13 +3,13 @@ # Exit on command errors and treat unset variables as an error set -eu -if [ ! -e .fonctions ]; then +if [ ! -e _common.sh ]; then # Get file fonction if not been to the current directory - sudo cp ../settings/scripts/.fonctions ./.fonctions - sudo chmod a+rx .fonctions + sudo cp ../settings/scripts/_common.sh ./_common.sh + sudo chmod a+rx _common.sh fi # Loads the generic functions usually used in the script -source .fonctions +source _common.sh # Source app helpers source /usr/share/yunohost/helpers diff --git a/scripts/install b/scripts/install index 3d5172f..a8f832c 100644 --- a/scripts/install +++ b/scripts/install @@ -3,7 +3,7 @@ # Exit on command errors and treat unset variables as an error set -eu -source .fonctions # Loads the generic functions usually used in the script +source _common.sh # Loads the generic functions usually used in the script source /usr/share/yunohost/helpers # Source app helpers CLEAN_SETUP () { diff --git a/scripts/remove b/scripts/remove index 1b2c405..6683c07 100644 --- a/scripts/remove +++ b/scripts/remove @@ -3,13 +3,13 @@ # Exit on command errors and treat unset variables as an error set -u -if [ ! -e .fonctions ]; then +if [ ! -e _common.sh ]; then # Get file fonction if not been to the current directory - sudo cp ../settings/scripts/.fonctions ./.fonctions - sudo chmod a+rx .fonctions + sudo cp ../settings/scripts/_common.sh ./_common.sh + sudo chmod a+rx _common.sh fi -source .fonctions # Loads the generic functions usually used in the script +source _common.sh # Loads the generic functions usually used in the script # Source app helpers source /usr/share/yunohost/helpers diff --git a/scripts/restore b/scripts/restore index 30666df..8ca0b5a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -4,13 +4,13 @@ # Exit on command errors and treat unset variables as an error set -eu -if [ ! -e .fonctions ]; then +if [ ! -e _common.sh ]; then # Get file fonction if not been to the current directory - sudo cp ../settings/scripts/.fonctions ./.fonctions - sudo chmod a+rx .fonctions + sudo cp ../settings/scripts/_common.sh ./_common.sh + sudo chmod a+rx _common.sh fi # Loads the generic functions usually used in the script -source .fonctions +source _common.sh # Source app helpers source /usr/share/yunohost/helpers diff --git a/scripts/upgrade b/scripts/upgrade index 50904f1..47b4712 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -4,7 +4,7 @@ set -eu # Loads the generic functions usually used in the script -source .fonctions +source _common.sh # Source YunoHost helpers source /usr/share/yunohost/helpers From eab38a2058989dfcbbab5dbd19612bc4f253267d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 6 Apr 2018 21:00:38 +0200 Subject: [PATCH 03/45] Improve manifest and check_process --- check_process | 8 ++++---- manifest.json | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/check_process b/check_process index 6952a12..273bc7a 100644 --- a/check_process +++ b/check_process @@ -4,7 +4,7 @@ domain="domain.tld" (DOMAIN) admin="john" (USER) path="/path" (PATH) - passwd="adminpassword" + passwd="():g9!co.'G{2+f/Wd\,e" ; Checks pkg_linter=1 setup_sub_dir=0 @@ -26,9 +26,9 @@ Level 1=auto Level 2=auto Level 3=auto - Level 4=na - Level 5=1 -# level 5: le test ne semble pas tout à fait savoir ce qu'est vraiment un "exit". +# Level 4: TODO: https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Enabling-LDAP-login.md + Level 4=0 + Level 5=auto Level 6=auto Level 7=auto Level 8=0 diff --git a/manifest.json b/manifest.json index 228fa4b..3c1b32b 100644 --- a/manifest.json +++ b/manifest.json @@ -3,15 +3,15 @@ "id": "mastodon", "packaging_format": 1, "requirements": { - "yunohost": ">= 2.4" + "yunohost": ">= 2.7.9" }, "description": { "en": "Mastodon is a free, open-source social network.", "fr": "Mastodon est un réseau social gratuit et open source." }, - "version": "2.2.0", + "version": "2.2.0-1", "url": "https://github.com/tootsuite/mastodon", - "license": "AGPL v3.0", + "license": "AGPL-3.0-or-later", "maintainer": { "name": "cyp, nemsia", "email": "cyp@rouquin.me, nemsia@nemsia.org" From 18b69b2fdfbd1178334b5ea5a3c9e75fb439a10f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 6 Apr 2018 21:01:26 +0200 Subject: [PATCH 04/45] Remove old-time specific functions and add multiple TODO --- scripts/_common.sh | 190 ----------------------- scripts/install | 367 +++++++++++++++++++++++++++------------------ 2 files changed, 224 insertions(+), 333 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 20f9ea0..39b0631 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,167 +1,5 @@ #!/bin/bash -ynh_version="2.4" - -YNH_VERSION () { # Returns the version number of the Yunohost moulinette - ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) -} - -CHECK_VAR () { # Verifies that the variable is not empty. - # $1 = Variable to be checked - # $2 = Display text on error - test -n "$1" || (echo "$2" >&2 && false) -} - -EXIT_PROPERLY () { # Causes the script to stop in the event of an error. And clean the residue. - trap '' ERR - echo -e "\e[91m \e[1m" # Shell in light red bold - echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!" >&2 - - if type -t CLEAN_SETUP > /dev/null; then # Checks the existence of the function before executing it. - CLEAN_SETUP # Call the specific cleanup function of the install script. - fi - - # Compensates the ssowat bug that does not remove the app's input in case of installation error. - sudo sed -i "\@\"$domain/\":@d" /etc/ssowat/conf.json - - if [ "$ynh_version" = "2.2" ]; then - /bin/bash $script_dir/remove - fi - - ynh_die -} - -TRAP_ON () { # Activate signal capture - trap EXIT_PROPERLY ERR # Capturing exit signals on error -} - -TRAP_OFF () { # Ignoring signal capture until TRAP_ON - trap '' ERR # Ignoring exit signals -} - -CHECK_USER () { # Check the validity of the user admin - # $1 = User admin variable - ynh_user_exists "$1" || (echo "Wrong admin" >&2 && false) -} - -CHECK_PATH () { # Checks / at the beginning of the path. And his absence at the end. - if [ "${path:0:1}" != "/" ]; then # If the first character is not / - path="/$path" # Add / at the beginning of path - fi - if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # If the last character is a / and it is not the only character. - path="${path:0:${#path}-1}" # Delete last character - fi -} - -CHECK_DOMAINPATH () { # Checks the availability of the path and domain. - sudo yunohost app checkurl $domain -a $app -} - -CHECK_FINALPATH () { # Checks that the destination folder is not already in use. - final_path=/opt/$app - if [ -e "$final_path" ] - then - echo "This path already contains a folder" >&2 - false - fi -} - -STORE_MD5_CONFIG () { # Saves the checksum of the config file - # $1 = Name of the conf file for storage in settings.yml - # $2 = Full name and path of the conf file. - ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1) -} - -CHECK_MD5_CONFIG () { # Created a backup of the config file if it was changed. - # $1 = Name of the conf file for storage in settings.yml - # $2 = Full name and path of the conf file.onf. - if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then - sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup. - fi -} - -FIND_PORT () { # Search free port - # $1 = Port number to start the search. - port=$1 - while ! sudo yunohost app checkport $port ; do - port=$((port+1)) - done - CHECK_VAR "$port" "port empty" -} - -SETUP_SOURCE () { # Download source, decompress and copu into $final_path - src=$(cat ../sources/source_md5 | awk -F' ' {'print $2'}) - sudo wget -nv -i ../sources/source_url -O $src - # Checks the checksum of the downloaded source. - # md5sum -c ../sources/source_md5 --status || ynh_die "Corrupt source" - # Decompress source - if [ "$(echo ${src##*.})" == "tgz" ]; then - tar -x -f $src - elif [ "$(echo ${src##*.})" == "zip" ]; then - unzip -q $src - else - false # Unsupported archive format. - fi - # Copy file source - sudo cp -a $(cat ../sources/source_dir)/. "$final_path/live" - # Copy additional file and modified - if test -e "../sources/ajouts"; then - sudo cp -a ../sources/ajouts/. "$final_path" - fi -} - -# Create user with special hack -CREATE_USER () { - sudo curl -kSs https://${domain}/auth/sign_up --cookie-jar cookie | grep csrf > token || true - token=$(sudo cat token | sed -n '/csrf-token/s/.*name="csrf-token"\s\+content="\([^"]\+\).*/\1/p') - sudo curl -kSs https://${domain}/auth --data "&user[account_attributes][username]=${admin_mastodon}&user[email]=${admin_mastodon}@${domain}&user[password]=${admin_pass}&user[password_confirmation]=${admin_pass}&authenticity_token=${token}" --cookie cookie -} - -### REMOVE SCRIPT - -REMOVE_NGINX_CONF () { # Delete nginx configuration - if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config - echo "Delete nginx config" - sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf" - sudo systemctl reload nginx - fi -} - -REMOVE_LOGROTATE_CONF () { # Delete logrotate configuration - if [ -e "/etc/logrotate.d/$app" ]; then - echo "Delete logrotate config" - sudo rm "/etc/logrotate.d/$app" - fi -} - -SECURE_REMOVE () { # Deleting a folder with variable verification - chaine="$1" # The argument must be given between simple quotes '', to avoid interpreting the variables. - no_var=0 - while (echo "$chaine" | grep -q '\$') # Loop as long as there are $ in the string - do - no_var=1 - global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole the first variable found. - only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole completely the variable by adding the $ at the beginning and keeping only the name of the variable. Mostly gets rid of / and a possible path behind. - real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` Allows to interpret a variable contained in a variable. - if test -z "$real_var" || [ "$real_var" = "/" ]; then - echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2 - return 1 - fi - chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # Replaces variable with its value in the string. - done - if [ "$no_var" -eq 1 ] - then - if [ -e "$chaine" ]; then - echo "Delete directory $chaine" - sudo rm -r "$chaine" - fi - return 0 - else - echo "No detected variable." >&2 - return 1 - fi -} - # Create a db without password # # usage: ynh_mysql_create_user user @@ -233,31 +71,3 @@ ynh_psql_drop_db() { ynh_psql_drop_user() { sudo su -c "dropuser ${1}" postgres } - -# Remove a file or a directory securely -# -# usage: ynh_secure_remove path_to_remove -# | arg: path_to_remove - File or directory to remove -ynh_secure_remove () { - path_to_remove=$1 - forbidden_path=" \ - /var/www \ - /home/yunohost.app" - - if [[ "$forbidden_path" =~ "$path_to_remove" \ - # Match all path or subpath in $forbidden_path - || "$path_to_remove" =~ ^/[[:alnum:]]+$ \ - # Match all first level path from / (Like /var, /root, etc...) - || "${path_to_remove:${#path_to_remove}-1}" = "/" ]] - # Match if the path finish by /. Because it's seems there is an empty variable - then - echo "Avoid deleting of $path_to_remove." >&2 - else - if [ -e "$path_to_remove" ] - then - sudo rm -R "$path_to_remove" - else - echo "$path_to_remove doesn't deleted because it's not exist." >&2 - fi - fi -} \ No newline at end of file diff --git a/scripts/install b/scripts/install index a8f832c..5b1acaa 100644 --- a/scripts/install +++ b/scripts/install @@ -1,17 +1,25 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -source _common.sh # Loads the generic functions usually used in the script -source /usr/share/yunohost/helpers # Source app helpers +source _common.sh +source /usr/share/yunohost/helpers -CLEAN_SETUP () { - # Clean installation residues that are not supported by the remove script. - # Clean hosts - echo "" -} -TRAP_ON # Active trap to stop the script if an error is detected. +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================ domain=$YNH_APP_ARG_DOMAIN admin_mastodon=$YNH_APP_ARG_ADMIN @@ -19,217 +27,290 @@ admin_mastodon_mail=$(ynh_user_get_info $admin_mastodon 'mail') admin_pass=$YNH_APP_ARG_PASSWD language=$YNH_APP_ARG_LANGUAGE +path_url="/" + app=$YNH_APP_INSTANCE_NAME -CHECK_VAR "$app" "app name not set" +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= -CHECK_USER "$admin_mastodon" +final_path=/var/www/$app +test ! -e "$final_path" || ynh_die "This path already contains a folder" -CHECK_DOMAINPATH +[[ ${#admin_pass} -gt 7 ]] || ynh_die "Password is too weak, must be longer than 7 characters" -CHECK_FINALPATH +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= ynh_app_setting_set $app domain $domain ynh_app_setting_set $app admin $admin_mastodon ynh_app_setting_set $app pass $admin_pass ynh_app_setting_set $app language $language +ynh_app_setting_set $app path $path_url -[[ ${#admin_pass} -gt 7 ]] || ynh_die \ -"The password is too weak, it must be longer than 7 characters" -# Create user unix -sudo adduser $app --home /opt/$app --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password --disabled-login +#================================================= +# STANDARD MODIFICATIONS +#================================================= -# Install debian package -ynh_package_install imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-transport-https pkg-config libprotobuf-dev protobuf-compiler libicu-dev libidn11-dev -# Install redis package -ynh_package_install redis-server redis-tools +#================================================= +# INSTALL DEPENDENCIES +#================================================= -# Install postgresql -ynh_package_install postgresql postgresql-contrib postgresql-server-dev-9.4 - -# Install Ruby -ynh_package_install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev +# TODO: add in a clean way backports and yarn # Import debian archive pubkey, need on ARM arch arch=$(uname -m) if [[ $arch = arm* ]]; then - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553 - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553 + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 fi # Install source.list debian package backports & yarn -sudo cp ../conf/backports.list /etc/apt/sources.list.d/ -sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - -sudo cp ../conf/yarn.list /etc/apt/sources.list.d/ +cp ../conf/backports.list /etc/apt/sources.list.d/ +curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +cp ../conf/yarn.list /etc/apt/sources.list.d/ ynh_package_update -# Install debian package backports -sudo apt-get -t jessie-backports -y install ffmpeg - # Creates the destination directory and stores its location. ynh_app_setting_set $app final_path $final_path # Install de Node.js -pushd /opt -curl -sL https://deb.nodesource.com/setup_6.x | sudo bash - -sudo apt-get -y install nodejs +# TODO: use https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_install_nodejs/ynh_install_nodejs +( + cd /opt + curl -sL https://deb.nodesource.com/setup_6.x | bash - + apt-get -y install nodejs +) -# Install Yarn -ynh_package_install yarn +# TODO: use the same mecanism with other files +ynh_install_app_dependencies \ + `# debian packages ` \ + imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-transport-https pkg-config libprotobuf-dev protobuf-compiler libicu-dev libidn11-dev \ + `# redis ` \ + redis-server redis-tools \ + `# postgresql ` \ + postgresql postgresql-contrib postgresql-server-dev-9.4 \ + `# Ruby ` \ + autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev \ + `# ffmpeg from backports ` \ + ffmpeg \ + `# Yarn ` \ + yarn +#================================================= +# CREATE A DATABASE +#================================================= + +# TODO: use non-official https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/postgres/postgres +# TODO: this commands doesn't looks like a requirement, you may fully remove it # Set UTF8 encoding by default -sudo su -c "psql" postgres <<< \ +su -c "psql" postgres <<< \ "update pg_database set datistemplate='false' where datname='template1';" -sudo su -c "psql" postgres <<< \ +su -c "psql" postgres <<< \ "drop database template1;" -sudo su -c "psql" postgres <<< \ +su -c "psql" postgres <<< \ "create database template1 encoding='UTF8' template template0;" -sudo su -c "psql" postgres <<< \ +su -c "psql" postgres <<< \ "update pg_database set datistemplate='true' where datname='template1';" # Create DB without password ynh_psql_create_db_without_password "$app" -sudo systemctl restart postgresql +systemctl restart postgresql +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +# TODO: dont su as $app, work root and set corrects rights at the end of install # Download all sources rbenv, ruby and mastodon -sudo su - $app <> ~/.profile -echo 'export PATH="/opt/mastodon/.rbenv/bin:/opt/mastodon/live/bin:$PATH"' >> ~/.bashrc -echo 'eval "\$(rbenv init -)"' >> ~/.profile -COMMANDS +( + su $app + cd ~/.rbenv + src/configure && make -C src + echo 'export PATH="/opt/mastodon/.rbenv/bin:/opt/mastodon/live/bin:$PATH"' >> ~/.profile + echo 'export PATH="/opt/mastodon/.rbenv/bin:/opt/mastodon/live/bin:$PATH"' >> ~/.bashrc + echo 'eval "\$(rbenv init -)"' >> ~/.profile +) # Install ruby-build -sudo su - $app <> .env.production -RAILS_ENV=production bin/bundle exec rails db:setup -RAILS_ENV=production bin/bundle exec rails --trace assets:precompile -CCOMMANDS +( + su $app + cd ~/live + echo "SAFETY_ASSURED=1">> .env.production + RAILS_ENV=production bin/bundle exec rails db:setup + RAILS_ENV=production bin/bundle exec rails --trace assets:precompile +) # init rbenv & create bundle -sudo su - $app < Date: Tue, 1 May 2018 10:52:42 +0200 Subject: [PATCH 05/45] use simplier password to prevent a bug in package_check --- check_process | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_process b/check_process index 273bc7a..5045355 100644 --- a/check_process +++ b/check_process @@ -4,7 +4,7 @@ domain="domain.tld" (DOMAIN) admin="john" (USER) path="/path" (PATH) - passwd="():g9!co.'G{2+f/Wd\,e" + passwd="12345678" ; Checks pkg_linter=1 setup_sub_dir=0 From f0b132281241bcfdc38be62dd79324b78a4972f2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Tue, 1 May 2018 11:29:25 +0200 Subject: [PATCH 06/45] Use latest PostgreSQL helpers --- scripts/_common.sh | 180 +++++++++++++++++++++++++++++++++------------ scripts/backup | 7 +- scripts/install | 47 ++++++------ scripts/remove | 5 +- scripts/restore | 17 ++--- 5 files changed, 171 insertions(+), 85 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 39b0631..dce035f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,73 +1,161 @@ #!/bin/bash -# Create a db without password +#================================================= # -# usage: ynh_mysql_create_user user -# | arg: user - the user name to create -ynh_psql_create_db_without_password() { - db=$1 - sudo su -c "psql" postgres <<< \ - "CREATE USER $db CREATEDB;" +# POSTGRES HELPERS +# +# Point of contact : Jean-Baptiste Holcroft +#================================================= + +# Create a master password and set up global settings +# Please always call this script in install and restore scripts +# +# usage: ynh_psql_test_if_first_run + +ynh_psql_test_if_first_run() { + if [ -f /etc/yunohost/psql ]; + then + echo "PostgreSQL is already installed, no need to create master password" + else + pgsql=$(ynh_string_random) + pg_hba="" + echo "$pgsql" >> /etc/yunohost/psql + + if [ -e /etc/postgresql/9.4/ ] + then + pg_hba=/etc/postgresql/9.4/main/pg_hba.conf + elif [ -e /etc/postgresql/9.6/ ] + then + pg_hba=/etc/postgresql/9.6/main/pg_hba.conf + else + ynh_die "postgresql shoud be 9.4 or 9.6" + fi + + systemctl start postgresql + sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$pgsql'" postgres + + # force all user to connect to local database using passwords + # https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF + # Note: we can't use peer since YunoHost create users with nologin + # See: https://github.com/YunoHost/yunohost/blob/unstable/data/helpers.d/user + sed -i '/local\s*all\s*all\s*peer/i \ + local all all password' "$pg_hba" + systemctl enable postgresql + systemctl reload postgresql + fi } -# Create a user +# Open a connection as a user # -# usage: ynh_mysql_create_user user pwd [host] -# | arg: user - the user name to create -# | arg: pwd - the password to identify user by -ynh_psql_create_user() { - sudo su -c "psql" postgres <<< \ - "CREATE USER ${1} WITH PASSWORD '${2}';" +# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;" +# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql +# +# usage: ynh_psql_connect_as user pwd [db] +# | arg: user - the user name to connect as +# | arg: pwd - the user password +# | arg: db - the database to connect to +ynh_psql_connect_as() { + user="$1" + pwd="$2" + db="$3" + sudo --login --user=postgres PGUSER="$user" PGPASSWORD="$pwd" psql "$db" } -# Create a user without password +# # Execute a command as root user # -# usage: ynh_mysql_create_user user pwd [host] -# | arg: user - the user name to create -ynh_psql_create_user_without_password() { - sudo su -c "psql" postgres <<< \ - "CREATE USER ${1};" +# usage: ynh_psql_execute_as_root sql [db] +# | arg: sql - the SQL command to execute +# | arg: db - the database to connect to +ynh_psql_execute_as_root () { + sql="$1" + sudo --login --user=postgres psql <<< "$sql" } -# Create a database and grant optionnaly privilegies to a user +# Execute a command from a file as root user # -# usage: ynh_mysql_create_db db [user [pwd]] +# usage: ynh_psql_execute_file_as_root file [db] +# | arg: file - the file containing SQL commands +# | arg: db - the database to connect to +ynh_psql_execute_file_as_root() { + file="$1" + db="$2" + sudo --login --user=postgres psql "$db" < "$file" +} + +# Create a database, an user and its password. Then store the password in the app's config +# +# After executing this helper, the password of the created database will be available in $db_pwd +# It will also be stored as "psqlpwd" into the app settings. +# +# usage: ynh_psql_setup_db user name [pwd] +# | arg: user - Owner of the database +# | arg: name - Name of the database +# | arg: pwd - Password of the database. If not given, a password will be generated +ynh_psql_setup_db () { + db_user="$1" + app="$1" + db_name="$2" + new_db_pwd=$(ynh_string_random) # Generate a random password + # If $3 is not given, use new_db_pwd instead for db_pwd. + db_pwd="${3:-$new_db_pwd}" + ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database + ynh_app_setting_set "$app" psqlpwd "$db_pwd" # Store the password in the app's config +} + +# Create a database and grant privilegies to a user +# +# usage: ynh_psql_create_db db [user [pwd]] # | arg: db - the database name to create # | arg: user - the user to grant privilegies -# | arg: pwd - the password to identify user by +# | arg: pwd - the user password ynh_psql_create_db() { - db=$1 - # grant all privilegies to user - if [[ $# -gt 1 ]]; then - ynh_psql_create_user ${2} "${3}" - sudo su -c "createdb -O ${2} $db" postgres - else - sudo su -c "createdb $db" postgres - fi - -} - -# Drop a role -# -# usage: ynh_mysql_drop_role db -# | arg: db - the database name to drop -ynh_psql_drop_role() { - sudo su -c "psql" postgres <<< \ - "DROP ROLE ${1};" + db="$1" + user="$2" + pwd="$3" + ynh_psql_create_user "$user" "$pwd" + sudo --login --user=postgres createdb --owner="$user" "$db" } # Drop a database # -# usage: ynh_mysql_drop_db db +# usage: ynh_psql_drop_db db # | arg: db - the database name to drop -ynh_psql_drop_db() { - sudo su -c "dropdb ${1}" postgres +# | arg: user - the user to drop +ynh_psql_remove_db() { + db="$1" + user="$2" + sudo --login --user=postgres dropdb "$db" + ynh_psql_drop_user "$user" +} + +# Dump a database +# +# example: ynh_psql_dump_db 'roundcube' > ./dump.sql +# +# usage: ynh_psql_dump_db db +# | arg: db - the database name to dump +# | ret: the psqldump output +ynh_psql_dump_db() { + db="$1" + sudo --login --user=postgres pg_dump "$db" +} + + +# Create a user +# +# usage: ynh_psql_create_user user pwd [host] +# | arg: user - the user name to create +ynh_psql_create_user() { + user="$1" + pwd="$2" + sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd'" postgres } # Drop a user # -# usage: ynh_mysql_drop_user user +# usage: ynh_psql_drop_user user # | arg: user - the user name to drop ynh_psql_drop_user() { - sudo su -c "dropuser ${1}" postgres + user="$1" + sudo --login --user=postgres dropuser "$user" } diff --git a/scripts/backup b/scripts/backup index ffcac0e..d4014c7 100644 --- a/scripts/backup +++ b/scripts/backup @@ -39,9 +39,8 @@ ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list" sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/${domain}.d/${app}.conf # Backup db -sudo su - postgres < mastodon_db.sql -COMMANDS -ynh_backup "/var/lib/postgresql/${app}_db.sql" "${app}_db.sql" +db_name=$(ynh_sanitize_dbid "$app") +ynh_psql_dump_db "$db_name" + # Fix backup fail on yunohost 2.6 #ynh_secure_remove /var/lib/postgresql/mastodon_db.sql diff --git a/scripts/install b/scripts/install index 5b1acaa..4a23715 100644 --- a/scripts/install +++ b/scripts/install @@ -116,31 +116,16 @@ ynh_install_app_dependencies \ # TODO: use non-official https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/postgres/postgres # TODO: this commands doesn't looks like a requirement, you may fully remove it # Set UTF8 encoding by default -su -c "psql" postgres <<< \ - "update pg_database set datistemplate='false' where datname='template1';" -su -c "psql" postgres <<< \ - "drop database template1;" -su -c "psql" postgres <<< \ - "create database template1 encoding='UTF8' template template0;" -su -c "psql" postgres <<< \ - "update pg_database set datistemplate='true' where datname='template1';" -# Create DB without password -ynh_psql_create_db_without_password "$app" -systemctl restart postgresql +ynh_psql_test_if_first_run + +db_user=$(ynh_sanitize_dbid "$app") +db_name=$(ynh_sanitize_dbid "$app") +db_pwd=$(ynh_string_random) +ynh_app_setting_set $app db_pwd $db_pwd +ynh_psql_setup_db "$db_user" "$db_name" "$db_pwd" -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -# TODO: dont su as $app, work root and set corrects rights at the end of install -# Download all sources rbenv, ruby and mastodon -( - su $app - git clone https://github.com/rbenv/rbenv.git $final_path/.rbenv - git clone https://github.com/rbenv/ruby-build.git $final_path/.rbenv/plugins/ruby-build - git clone https://github.com/tootsuite/mastodon.git $final_path/live -) #================================================= # NGINX CONFIGURATION @@ -161,6 +146,19 @@ cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # Create user unix adduser $app --home /opt/$app --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password --disabled-login +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +# TODO: dont su as $app, work root and set corrects rights at the end of install +# Download all sources rbenv, ruby and mastodon +( + su $app + git clone https://github.com/rbenv/rbenv.git $final_path/.rbenv + git clone https://github.com/rbenv/ruby-build.git $final_path/.rbenv/plugins/ruby-build + git clone https://github.com/tootsuite/mastodon.git $final_path/live +) + # Switch branch to tagged release cd $final_path/live version=$(curl -s https://api.github.com/repos/tootsuite/mastodon/releases/latest | grep tag_name | cut -d\" -f4) @@ -208,8 +206,9 @@ ln -s /opt/mastodon/.rbenv/versions/2.5.0/bin/ruby /usr/bin/ruby || true cp -a $final_path/live/.env.production.sample $final_path/live/.env.production sed -i "s@REDIS_HOST=redis@REDIS_HOST=127.0.0.1@g" "${final_path}/live/.env.production" sed -i "s@DB_HOST=db@DB_HOST=/var/run/postgresql@g" "${final_path}/live/.env.production" -sed -i "s@DB_USER=postgres@DB_USER=${app}@g" "${final_path}/live/.env.production" -sed -i "s@DB_NAME=postgres@DB_NAME=${app}_production@g" "${final_path}/live/.env.production" +sed -i "s@DB_USER=postgres@DB_USER=${db_user}@g" "${final_path}/live/.env.production" +sed -i "s@DB_NAME=postgres@DB_NAME=${db_name}@g" "${final_path}/live/.env.production" +sed -i "s@DB_PASS=@DB_PASS=${db_name}@g" "${final_path}/live/.env.production" sed -i "s@LOCAL_DOMAIN=example.com@LOCAL_DOMAIN=${domain}@g" "${final_path}/live/.env.production" language="$(echo $language | head -c 2)" diff --git a/scripts/remove b/scripts/remove index 6683c07..e60ed37 100644 --- a/scripts/remove +++ b/scripts/remove @@ -65,8 +65,9 @@ then fi # delete postgresql database & user -ynh_psql_drop_db "${app}_production" -ynh_psql_drop_role "${app}" +db_user=$(ynh_sanitize_dbid "$app") +db_name=$(ynh_sanitize_dbid "$app") +ynh_psql_remove_db "$db_name" "$db_user" # Remove Debian package sudo apt-get remove --purge -y yarn diff --git a/scripts/restore b/scripts/restore index 8ca0b5a..8bad156 100644 --- a/scripts/restore +++ b/scripts/restore @@ -107,15 +107,14 @@ sudo chown -R $app: "$final_path" # Debug sudo ls -alh "$final_path" -# Set UTF8 encoding by default -sudo su -c "psql" postgres <<< \ - "update pg_database set datistemplate='false' where datname='template1';" -sudo su -c "psql" postgres <<< \ - "drop database template1;" -sudo su -c "psql" postgres <<< \ - "create database template1 encoding='UTF8' template template0;" -sudo su -c "psql" postgres <<< \ - "update pg_database set datistemplate='true' where datname='template1';" +# Restore PostgreSQL database +db_user=$(ynh_sanitize_dbid "$app") +db_name=$(ynh_sanitize_dbid "$app") +db_pwd=$(ynh_app_setting_get "$app" db_pwd) + +ynh_psql_test_if_first_run +ynh_psql_setup_db "$db_name" "$db_name" "$db_pwd" +ynh_psql_execute_file_as_root ./db.sql "$db_name" # Install rbenv sudo su - $app < Date: Tue, 1 May 2018 18:48:06 +0200 Subject: [PATCH 07/45] Add helpers (multi-file systemd and exec_as) --- scripts/_common.sh | 14 +++++ scripts/_future.sh | 127 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 scripts/_future.sh diff --git a/scripts/_common.sh b/scripts/_common.sh index dce035f..7d4f823 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,5 +1,19 @@ #!/bin/bash + +# Execute a command as another user +# usage: exec_as USER COMMAND [ARG ...] +exec_as() { + local user=$1 + shift 1 + + if [[ $user = $(whoami) ]]; then + eval "$@" + else + sudo --login --user="$user" "$@" + fi +} + #================================================= # # POSTGRES HELPERS diff --git a/scripts/_future.sh b/scripts/_future.sh new file mode 100644 index 0000000..82f255c --- /dev/null +++ b/scripts/_future.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +# needed to have "service_name" as an option +# https://github.com/YunoHost/yunohost/commit/9c4ddcca39d9d6d92bd5f9a23978337e48d0a4e1 +ynh_add_systemd_config () { + local service_name="${1:-$app}" + + finalsystemdconf="/etc/systemd/system/$service_name.service" + ynh_backup_if_checksum_is_different "$finalsystemdconf" + sudo cp ../conf/${2:-systemd.service} "$finalsystemdconf" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${final_path:-}"; then + ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" + fi + if test -n "${app:-}"; then + ynh_replace_string "__APP__" "$app" "$finalsystemdconf" + fi + ynh_store_file_checksum "$finalsystemdconf" + + sudo chown root: "$finalsystemdconf" + sudo systemctl enable $service_name + sudo systemctl daemon-reload +} + +# needed to have "service_name" as an option +# https://github.com/YunoHost/yunohost/commit/9c4ddcca39d9d6d92bd5f9a23978337e48d0a4e1 +ynh_remove_systemd_config () { + local service_name="${1:-$app}" + + local finalsystemdconf="/etc/systemd/system/$service_name.service" + if [ -e "$finalsystemdconf" ]; then + sudo systemctl stop $service_name + sudo systemctl disable $service_name + ynh_secure_remove "$finalsystemdconf" + sudo systemctl daemon-reload + fi +} + + +# LOCAL ADDITION: +# save file locally if not in the cache +# +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source () { + local dest_dir=$1 + local src_id=${2:-app} # If the argument is not given, source_id equals "app" + + # Load value from configuration file (see above for a small doc about this file + # format) + local src_url=$(grep 'SOURCE_URL=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_sum=$(grep 'SOURCE_SUM=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_format=$(grep 'SOURCE_FORMAT=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + local src_filename=$(grep 'SOURCE_FILENAME=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) + + # Default value + src_sumprg=${src_sumprg:-sha256sum} + src_in_subdir=${src_in_subdir:-true} + src_format=${src_format:-tar.gz} + src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]') + if [ "$src_filename" = "" ] ; then + src_filename="${src_id}.${src_format}" + fi + local local_src="/var/cache/yunohost/ynh_setup_source/${YNH_APP_ID}/${src_filename}" + + # if cache file exists and the checksum isn't good, download it again + # if not, just download the file + + if test -e "$local_src" + then + echo "${src_sum} ${local_src}" | ${src_sumprg} -c --status \ + || wget -nv -O $local_src $src_url + else + mkdir -p "/var/cache/yunohost/ynh_setup_source/${YNH_APP_ID}" + wget -nv -O $local_src $src_url + fi + cp $local_src $src_filename + + # Check the control sum + echo "${src_sum} ${src_filename}" | ${src_sumprg} -c --status \ + || ynh_die "Corrupt source" + + # Extract source into the app dir + mkdir -p "$dest_dir" + if [ "$src_format" = "zip" ] + then + # Zip format + # Using of a temp directory, because unzip doesn't manage --strip-components + if $src_in_subdir ; then + local tmp_dir=$(mktemp -d) + unzip -quo $src_filename -d "$tmp_dir" + cp -a $tmp_dir/*/. "$dest_dir" + ynh_secure_remove "$tmp_dir" + else + unzip -quo $src_filename -d "$dest_dir" + fi + else + local strip="" + if $src_in_subdir ; then + strip="--strip-components 1" + fi + if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]] ; then + tar -xf $src_filename -C "$dest_dir" $strip + else + ynh_die "Archive format unrecognized." + fi + fi + + # Apply patches + if (( $(find $YNH_CWD/../sources/patches/ -type f -name "${src_id}-*.patch" 2> /dev/null | wc -l) > "0" )); then + local old_dir=$(pwd) + (cd "$dest_dir" \ + && for p in $YNH_CWD/../sources/patches/${src_id}-*.patch; do \ + patch -p1 < $p; done) \ + || ynh_die "Unable to apply patches" + cd $old_dir + fi + + # Add supplementary files + if test -e "$YNH_CWD/../sources/extra_files/${src_id}"; then + cp -a $YNH_CWD/../sources/extra_files/$src_id/. "$dest_dir" + fi +} + From 00a9710a4e97a4fae904d467854eb159af29d402 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Tue, 1 May 2018 18:49:10 +0200 Subject: [PATCH 08/45] Use helpers for systemd & package installation, lock version to 2.3.3 --- conf/app-mastodon.src | 6 ++ conf/app-rbenv.src | 6 ++ conf/app-ruby-build.src | 6 ++ conf/mastodon-sidekiq.service | 10 +-- conf/mastodon-streaming.service | 8 +- conf/mastodon-web.service | 10 +-- manifest.json | 2 +- scripts/install | 153 +++++++++++++------------------- 8 files changed, 94 insertions(+), 107 deletions(-) create mode 100644 conf/app-mastodon.src create mode 100644 conf/app-rbenv.src create mode 100644 conf/app-ruby-build.src diff --git a/conf/app-mastodon.src b/conf/app-mastodon.src new file mode 100644 index 0000000..62d10c6 --- /dev/null +++ b/conf/app-mastodon.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.3.3.tar.gz +SOURCE_SUM=b2b2e2ee7cc034e92258263500c423b900611407db67682777eef0526118f66e +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/app-rbenv.src b/conf/app-rbenv.src new file mode 100644 index 0000000..d60155b --- /dev/null +++ b/conf/app-rbenv.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/rbenv/rbenv/archive/v1.1.1.tar.gz +SOURCE_SUM=41f1a60714c55eceb21d692a469aee1ec4f46bba351d0dfcb0c660ff9cf1a1c9 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/app-ruby-build.src b/conf/app-ruby-build.src new file mode 100644 index 0000000..3041556 --- /dev/null +++ b/conf/app-ruby-build.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20180424.tar.gz +SOURCE_SUM=71dbaf87081369c1f5d27b6a94a927c1eeeb1f36bdffe7851f0a9c1ec87b9373 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/mastodon-sidekiq.service b/conf/mastodon-sidekiq.service index 34074ed..f788332 100644 --- a/conf/mastodon-sidekiq.service +++ b/conf/mastodon-sidekiq.service @@ -1,17 +1,17 @@ [Unit] - Description=mastodon-sidekiq + Description=__APP__-sidekiq After=network.target [Service] Type=simple - User=mastodon - WorkingDirectory=/opt/mastodon/live + User=__APP__ + WorkingDirectory=__FINALPATH__/live Environment="RAILS_ENV=production" Environment="DB_POOL=20" - ExecStart=/opt/mastodon/.rbenv/shims/bundle exec sidekiq -c 20 -q default -q mailers -q pull -q push + ExecStart=__FINALPATH__/live/bin/bundle exec sidekiq -c 20 -q default -q mailers -q pull -q push TimeoutSec=15 Restart=always StandardError=syslog [Install] - WantedBy=multi-user.target \ No newline at end of file + WantedBy=multi-user.target diff --git a/conf/mastodon-streaming.service b/conf/mastodon-streaming.service index 1716b00..443cac0 100644 --- a/conf/mastodon-streaming.service +++ b/conf/mastodon-streaming.service @@ -1,11 +1,11 @@ [Unit] - Description=mastodon-streaming + Description=__APP__-streaming After=network.target [Service] Type=simple - User=mastodon - WorkingDirectory=/opt/mastodon/live + User=__APP__ + WorkingDirectory=__FINALPATH__/live Environment="NODE_ENV=production" Environment="PORT=4000" ExecStart=/usr/bin/npm run start @@ -14,4 +14,4 @@ StandardError=syslog [Install] - WantedBy=multi-user.target \ No newline at end of file + WantedBy=multi-user.target diff --git a/conf/mastodon-web.service b/conf/mastodon-web.service index 4632031..06069f1 100644 --- a/conf/mastodon-web.service +++ b/conf/mastodon-web.service @@ -1,17 +1,17 @@ [Unit] - Description=mastodon-web + Description=__APP__-web After=network.target [Service] Type=simple - User=mastodon - WorkingDirectory=/opt/mastodon/live + User=__APP__ + WorkingDirectory=__FINALPATH__/live Environment="RAILS_ENV=production" Environment="PORT=3000" - ExecStart=/opt/mastodon/.rbenv/shims/bundle exec puma -C config/puma.rb + ExecStart=__FINALPATH__/live/bin/bundle exec puma -C config/puma.rb TimeoutSec=15 Restart=always StandardError=syslog [Install] - WantedBy=multi-user.target \ No newline at end of file + WantedBy=multi-user.target diff --git a/manifest.json b/manifest.json index 3c1b32b..dc1bde6 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,7 @@ "en": "Mastodon is a free, open-source social network.", "fr": "Mastodon est un réseau social gratuit et open source." }, - "version": "2.2.0-1", + "version": "2.3.3-1", "url": "https://github.com/tootsuite/mastodon", "license": "AGPL-3.0-or-later", "maintainer": { diff --git a/scripts/install b/scripts/install index 4a23715..56b8ef8 100644 --- a/scripts/install +++ b/scripts/install @@ -8,6 +8,7 @@ source _common.sh source /usr/share/yunohost/helpers +source _future.sh #================================================= # MANAGE SCRIPT FAILURE @@ -38,6 +39,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" +# TODO: remove this test, don't as password anymore, generate it and send it by email to admin with: https://github.com/YunoHost-Apps/Experimental_helpers/tree/master/send_readme_to_admin [[ ${#admin_pass} -gt 7 ]] || ynh_die "Password is too weak, must be longer than 7 characters" # Normalize the url path syntax @@ -72,7 +74,7 @@ ynh_app_setting_set $app path $path_url # Import debian archive pubkey, need on ARM arch arch=$(uname -m) -if [[ $arch = arm* ]]; then +if [[ "$arch" = arm* ]]; then apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 fi @@ -84,7 +86,7 @@ cp ../conf/yarn.list /etc/apt/sources.list.d/ ynh_package_update # Creates the destination directory and stores its location. -ynh_app_setting_set $app final_path $final_path +ynh_app_setting_set "$app" final_path "$final_path" # Install de Node.js # TODO: use https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_install_nodejs/ynh_install_nodejs @@ -125,13 +127,21 @@ db_pwd=$(ynh_string_random) ynh_app_setting_set $app db_pwd $db_pwd ynh_psql_setup_db "$db_user" "$db_name" "$db_pwd" +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +# Download all sources rbenv, ruby and mastodon + +ynh_setup_source "$final_path/.rbenv" "app-rbenv" +ynh_setup_source "$final_path/.rbenv/plugins/ruby-build" "app-ruby-build" +ynh_setup_source "$final_path/live" "app-mastodon" #================================================= # NGINX CONFIGURATION #================================================= -# TODO: use official helper +# TODO: use official helper ynh_add_nginx_config # Modify Nginx configuration file and copy it to Nginx conf directory sed -i "s@__PATH__@$app@g" ../conf/nginx.conf* sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf* @@ -141,74 +151,44 @@ cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # CREATE DEDICATED USER #================================================= -# TODO: use official helper -# TODO: AFAIK, no app should change should be in /opt don't use it +# TODO: use official helper ynh_system_user_create # Create user unix -adduser $app --home /opt/$app --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password --disabled-login +adduser $app --home $final_path --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= - -# TODO: dont su as $app, work root and set corrects rights at the end of install -# Download all sources rbenv, ruby and mastodon -( - su $app - git clone https://github.com/rbenv/rbenv.git $final_path/.rbenv - git clone https://github.com/rbenv/ruby-build.git $final_path/.rbenv/plugins/ruby-build - git clone https://github.com/tootsuite/mastodon.git $final_path/live -) - -# Switch branch to tagged release -cd $final_path/live -version=$(curl -s https://api.github.com/repos/tootsuite/mastodon/releases/latest | grep tag_name | cut -d\" -f4) - -( - su $app - cd ~/live - git checkout $version -) +chown -R "$app" "$final_path" +# TODO: try to use ynh_install_ruby from https://github.com/YunoHost-Apps/Experimental_helpers # Install de rbenv ( - su $app - cd ~/.rbenv + cd $final_path/.rbenv src/configure && make -C src - echo 'export PATH="/opt/mastodon/.rbenv/bin:/opt/mastodon/live/bin:$PATH"' >> ~/.profile - echo 'export PATH="/opt/mastodon/.rbenv/bin:/opt/mastodon/live/bin:$PATH"' >> ~/.bashrc - echo 'eval "\$(rbenv init -)"' >> ~/.profile + + echo "export PATH=\"$final_path/.rbenv/bin:$final_path/live/bin:\$PATH\" +eval \"\$(rbenv init -)\"" > $final_path/.profile + echo "export PATH=\"$final_path/.rbenv/bin:$final_path/live/bin:\$PATH\"" > $final_path/.bashrc ) # Install ruby-build -# TODO: /opt/mastodon looks like /opt/$app which is WRONG. ( - su $app - /opt/mastodon/.rbenv/bin/rbenv install 2.5.0 - /opt/mastodon/.rbenv/versions/2.5.0/bin/ruby -v + exec_as "$app" $final_path/.rbenv/bin/rbenv install 2.5.0 + exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.5.0 + exec_as "$app" $final_path/.rbenv/versions/2.5.0/bin/ruby -v ) # Create symlink for ruby rm /usr/bin/ruby || true -ln -s /opt/mastodon/.rbenv/versions/2.5.0/bin/ruby /usr/bin/ruby || true - -# Install Mastodon -# TODO: /opt/mastodon looks like /opt/$app which is WRONG. -( - su $app - cd ~/live - /opt/mastodon/.rbenv/versions/2.5.0/bin/gem install bundler - bin/bundle install --deployment --without development test - yarn install --production -) +ln -s $final_path/.rbenv/versions/2.5.0/bin/ruby /usr/bin/ruby || true # Adjust Mastodon config -# TODO: use official helper: ynh_replace_string +# TODO: use official helper ynh_replace_string +# TODO: save the config file in conf folder, to make replacement easier to read +# TODO: use ynh_string_random cp -a $final_path/live/.env.production.sample $final_path/live/.env.production sed -i "s@REDIS_HOST=redis@REDIS_HOST=127.0.0.1@g" "${final_path}/live/.env.production" sed -i "s@DB_HOST=db@DB_HOST=/var/run/postgresql@g" "${final_path}/live/.env.production" sed -i "s@DB_USER=postgres@DB_USER=${db_user}@g" "${final_path}/live/.env.production" sed -i "s@DB_NAME=postgres@DB_NAME=${db_name}@g" "${final_path}/live/.env.production" -sed -i "s@DB_PASS=@DB_PASS=${db_name}@g" "${final_path}/live/.env.production" +sed -i "s@DB_PASS=@DB_PASS=${db_pwd}@g" "${final_path}/live/.env.production" sed -i "s@LOCAL_DOMAIN=example.com@LOCAL_DOMAIN=${domain}@g" "${final_path}/live/.env.production" language="$(echo $language | head -c 2)" @@ -230,57 +210,46 @@ sed -i "s@#SMTP_AUTH_METHOD=plain@SMTP_AUTH_METHOD=none@g" "${final_path}/live/. sed -i "s@#SMTP_OPENSSL_VERIFY_MODE=peer@SMTP_OPENSSL_VERIFY_MODE=none@g" "${final_path}/live/.env.production" # Preconfig CSS & JS +# Install Mastodon ( - su $app - cd ~/live - echo "SAFETY_ASSURED=1">> .env.production - RAILS_ENV=production bin/bundle exec rails db:setup - RAILS_ENV=production bin/bundle exec rails --trace assets:precompile + cd "$final_path/live" + su mastodon <> .env.production +RAILS_ENV=production $final_path/live/bin/bundle exec rails db:migrate +RAILS_ENV=production $final_path/live/bin/bundle exec rails assets:precompile +INSTALL ) -# init rbenv & create bundle -( - su $app - . ~/.profile - type rbenv -) +# TODO: use ynh_find_port to have generic port selection for RAILS +ynh_add_systemd_config "$app-web" "mastodon-web.service" +# TODO: use ynh_find_port to have generic port selection for NODES +ynh_add_systemd_config "$app-sidekiq" "mastodon-sidekiq.service" +ynh_add_systemd_config "$app-streaming" "mastodon-streaming.service" -# TODO: use official helper ynh_add_systemd_config -cp ../conf/mastodon-web.service /etc/systemd/system/mastodon-web.service -chown root: /etc/systemd/system/mastodon-web.service -cp ../conf/mastodon-sidekiq.service /etc/systemd/system/mastodon-sidekiq.service -chown root: /etc/systemd/system/mastodon-sidekiq.service -cp ../conf/mastodon-streaming.service /etc/systemd/system/mastodon-streaming.service -chown root: /etc/systemd/system/mastodon-streaming.service - -systemctl daemon-reload -systemctl enable /etc/systemd/system/mastodon-*.service -systemctl start mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service -# debug -systemctl status mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service +systemctl start "$app-web.service" "$app-sidekiq.service" "$app-streaming.service" # Create user ( - su $app - cd ~/live - RAILS_ENV=production bundle exec rails c - account = Account.create!(username: '$admin_mastodon') - user = User.create!(email: '$admin_mastodon_mail', password: '$admin_pass', account: account) -) - -# Create administrator & confirm user -( - su $app - cd ~/live - RAILS_ENV=production bin/bundle exec rails mastodon:make_admin USERNAME=$admin_mastodon - RAILS_ENV=production bin/bundle exec rails mastodon:confirm_email USER_EMAIL=$admin_mastodon_mail + cd "$final_path/live" + su mastodon < Date: Tue, 1 May 2018 18:49:32 +0200 Subject: [PATCH 09/45] Standardization of removal --- scripts/remove | 164 ++++++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 77 deletions(-) diff --git a/scripts/remove b/scripts/remove index e60ed37..0c39054 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,104 +1,114 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -u - -if [ ! -e _common.sh ]; then - # Get file fonction if not been to the current directory - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh -fi +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= source _common.sh # Loads the generic functions usually used in the script # Source app helpers source /usr/share/yunohost/helpers +source _future.sh + + + +#================================================= +# LOAD SETTINGS +#================================================= -# Get multi-instances specific variables app=$YNH_APP_INSTANCE_NAME # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) - -# Stop mastodon-web -if [ -e "/etc/systemd/system/mastodon-web.service" ]; then - echo "Delete systemd script" - sudo systemctl stop mastodon-web.service - ynh_secure_remove "/etc/systemd/system/mastodon-web.service" - sudo systemctl disable mastodon-web.service -fi - -# Stop mastodon-sidekiq -if [ -e "/etc/systemd/system/mastodon-sidekiq.service" ]; then - echo "Delete systemd script" - sudo systemctl stop mastodon-sidekiq.service - ynh_secure_remove "/etc/systemd/system/mastodon-sidekiq.service" - sudo systemctl disable mastodon-sidekiq.service -fi - -# Stop mastodon-sidekiq -if [ -e "/etc/systemd/system/mastodon-streaming.service" ]; then - echo "Delete systemd script" - sudo systemctl stop mastodon-streaming.service - ynh_secure_remove "/etc/systemd/system/mastodon-streaming.service" - sudo systemctl disable mastodon-streaming.service -fi - -# Delete service on Yunohost monitoring -if sudo yunohost service status | grep -q mastodon-web -then - echo "Remove mastodon-web service" - sudo yunohost service remove mastodon-web -fi - -# Delete service on Yunohost monitoring -if sudo yunohost service status | grep -q mastodon-sidekiq -then - echo "Remove mastodon-sidekiq service" - sudo yunohost service remove mastodon-sidekiq -fi - -# Delete service on Yunohost monitoring -if sudo yunohost service status | grep -q mastodon-streaming -then - echo "Remove mastodon-streaming service" - sudo yunohost service remove mastodon-streaming -fi - -# delete postgresql database & user +db_name=$(ynh_app_setting_get "$app" db_name) db_user=$(ynh_sanitize_dbid "$app") db_name=$(ynh_sanitize_dbid "$app") +final_path=$(ynh_app_setting_get "$app" final_path) + +#================================================= +# STANDARD REMOVE +#================================================= +# STOP AND REMOVE SERVICE +#================================================= + +ynh_remove_systemd_config "$app-web" +ynh_remove_systemd_config "$app-sidekiq" +ynh_remove_systemd_config "$app-streaming" + +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#============================================== + +if yunohost service status | grep -q "$app-web" +then + echo "Remove $app-web service" + yunohost service remove "$app-web" +fi + +if yunohost service status | grep -q "$app-sidekiq" +then + echo "Remove $app-sidekiq service" + yunohost service remove "$app-sidekiq" +fi + +if yunohost service status | grep -q "$app-streaming" +then + echo "Remove $app-streaming service" + yunohost service remove "$app-streaming" +fi + +#================================================= +# REMOVE DEPENDENCIES +#================================================= + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + +#================================================= +# REMOVE THE PostgreSQL DATABASE +#================================================= + +# delete postgresql database & user ynh_psql_remove_db "$db_name" "$db_user" -# Remove Debian package -sudo apt-get remove --purge -y yarn -#sudo apt-get remove --purge -y imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file curl git -# Delete redis package -#sudo apt-get remove --purge -y redis-server redis-tools -# Delete postgresql package -#sudo apt-get remove --purge -y postgresql postgresql-contrib -# Delete Ruby package -#sudo apt-get remove --purge -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev +#================================================= +# REMOVE APP MAIN DIR +#================================================= -# Delete app directory and configurations -ynh_secure_remove /opt/$app -[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" +# Remove the app directory securely +ynh_secure_remove "$final_path" -# Delete nginx configuration -REMOVE_NGINX_CONF +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +ynh_secure_remove "/etc/nginx/conf.d/${domain}.d/${app}.conf" +systemctl reload nginx + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE THE CRON FILE +#================================================= # Delete cronlog ynh_secure_remove /etc/cron.d/$app -# Delete source.list + +#================================================= +# REMOVE source.list +#================================================= + ynh_secure_remove /etc/apt/sources.list.d/backports.list ynh_secure_remove /etc/apt/sources.list.d/yarn.list # Delete ruby exec ynh_secure_remove /usr/bin/ruby -# Remove user -sudo userdel -f $app +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= -# Reload services -sudo systemctl reload nginx - -echo -e "\e[0m" # Restore normal color +userdel -f $app From 6be35a9f26e0bae217a82d30b7754c49275eef0d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Tue, 1 May 2018 20:43:05 +0200 Subject: [PATCH 10/45] Standardization of restoration --- scripts/restore | 262 +++++++++++++++++++++--------------------------- 1 file changed, 117 insertions(+), 145 deletions(-) diff --git a/scripts/restore b/scripts/restore index 8bad156..b9798a7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,111 +1,124 @@ #!/bin/bash -# This restore script is adapted to Yunohost >=2.4 -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= if [ ! -e _common.sh ]; then - # Get file fonction if not been to the current directory - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh + # Get the _common.sh file if it's not in the current directory + cp ../settings/scripts/_common.sh ./_common.sh + cp ../settings/scripts/_future.sh ./_future.sh + chmod a+rx _common.sh _future.sh fi -# Loads the generic functions usually used in the script source _common.sh -# Source app helpers source /usr/share/yunohost/helpers +source _future.sh + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= -# The parameter $app is the id of the app instance ex: ynhexample__2 app=$YNH_APP_INSTANCE_NAME # Get old parameter of the app domain=$(ynh_app_setting_get $app domain) -path=$(ynh_app_setting_get $app path) +path_url=$(ynh_app_setting_get $app path) is_public=$(ynh_app_setting_get $app is_public) +final_path=$(ynh_app_setting_get "$app" final_path) -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= -# Check $final_path -final_path="/opt/${app}" -if [ -d $final_path ]; then - ynh_die "There is already a directory: $final_path" -fi +ynh_webpath_available $domain $path_url \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ +|| ynh_die "There is already a directory: $final_path " -# Check configuration files nginx -nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" -if [ -f $nginx_conf ]; then - ynh_die "The NGINX configuration already exists at '${nginx_conf}'. - You should safely delete it before restoring this app." -fi -# Check configuration files php-fpm -crontab_conf="/etc/cron.d/${app}" -if [ -f $crontab_conf ]; then - ynh_die "The CRONTAB configuration already exists at '${crontab_conf}'. - You should safely delete it before restoring this app." -fi +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= -# Restore services -web_systemd="/etc/systemd/system/${app}-web.service" -if [ -f "${web_systemd}" ]; then - ynh_die "The MASTODON WEB configuration already exists at '${web_systemd}'. - You should safely delete it before restoring this app." -fi -sidekiq_systemd="/etc/systemd/system/${app}-sidekiq.service" -if [ -f "${sidekiq_systemd}" ]; then - ynh_die "The MASTODON SIDEKIQ configuration already exists at '${sidekiq_systemd}'. - You should safely delete it before restoring this app." -fi -streaming_systemd="/etc/systemd/system/${app}-streaming.service" -if [ -f "${streaming_systemd}" ]; then - ynh_die "The MASTODON STREAMING configuration already exists at '${streaming_systemd}'. - You should safely delete it before restoring this app." -fi +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= + +ynh_restore_file "$final_path" + +#================================================= +# RECREATE THE DEDICATED USER +#================================================= # Create user unix -sudo adduser $app --home /opt/$app --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password --disabled-login +adduser $app --home $final_path --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password -# Reinstall dependencies - # Install debian package - ynh_package_install imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-transport-https pkg-config libprotobuf-dev protobuf-compiler +#================================================= +# RESTORE USER RIGHTS +#================================================= - # Install redis package - ynh_package_install redis-server redis-tools +# Restore permissions on app files +chown -R $app: $final_path - # Install postgresql - ynh_package_install postgresql postgresql-contrib +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= - # Install Ruby - ynh_package_install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev +# TODO: add in a clean way backports and yarn - # Install source.list debian package backports & yarn - sudo cp ./apt_backports.list /etc/apt/sources.list.d/backports.list - sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - - sudo cp ./apt_yarn.list /etc/apt/sources.list.d/yarn.list - ynh_package_update +# Import debian archive pubkey, need on ARM arch +arch=$(uname -m) +if [[ "$arch" = arm* ]]; then + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553 + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 +fi - # Install debian package backports - sudo apt-get -t jessie-backports -y install ffmpeg +# Install source.list debian package backports & yarn +cp ../conf/backports.list /etc/apt/sources.list.d/ +curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +cp ../conf/yarn.list /etc/apt/sources.list.d/ +ynh_package_update - # Install de Node.js - pushd /opt - curl -sL https://deb.nodesource.com/setup_6.x | sudo bash - - sudo apt-get -y install nodejs +# Install de Node.js +# TODO: use https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_install_nodejs/ynh_install_nodejs +( + cd /opt + curl -sL https://deb.nodesource.com/setup_6.x | bash - + apt-get -y install nodejs +) - # Install Yarn - ynh_package_install yarn +# TODO: use the same mecanism with other files +ynh_install_app_dependencies \ + `# debian packages ` \ + imagemagick libpq-dev libxml2-dev libxslt1-dev file curl apt-transport-https pkg-config libprotobuf-dev protobuf-compiler libicu-dev libidn11-dev \ + `# redis ` \ + redis-server redis-tools \ + `# postgresql ` \ + postgresql \ + `# Ruby ` \ + autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev \ + `# ffmpeg from backports ` \ + ffmpeg \ + `# Yarn ` \ + yarn - # Return to home - popd - - # Restore sources & data -sudo cp -a ./sources/. "$final_path" - -# Set permissions -sudo chown -R $app: "$final_path" - -# Debug -sudo ls -alh "$final_path" +#================================================= +# RESTORE THE PostgreSQL DATABASE +#================================================= # Restore PostgreSQL database db_user=$(ynh_sanitize_dbid "$app") @@ -116,75 +129,34 @@ ynh_psql_test_if_first_run ynh_psql_setup_db "$db_name" "$db_name" "$db_pwd" ynh_psql_execute_file_as_root ./db.sql "$db_name" -# Install rbenv -sudo su - $app <> ~/.profile -echo 'export PATH="/opt/mastodon/.rbenv/bin:/opt/mastodon/live/bin:$PATH"' >> ~/.bashrc -echo 'eval "\$(rbenv init -)"' >> ~/.profile -COMMANDS +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= -# Create user for db postgresql -ynh_psql_create_db_without_password "$app" +yunohost service add $app-web +yunohost service add $app-sidekiq +yunohost service add $app-streaming -# Setup database -#sudo su - $app < Date: Tue, 1 May 2018 20:43:49 +0200 Subject: [PATCH 11/45] Standardization of backup --- scripts/backup | 88 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 27 deletions(-) diff --git a/scripts/backup b/scripts/backup index d4014c7..5e134ac 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,46 +1,80 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= if [ ! -e _common.sh ]; then - # Get file fonction if not been to the current directory - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh + # Get the _common.sh file if it's not in the current directory + cp ../settings/scripts/_common.sh ./_common.sh + cp ../settings/scripts/_future.sh ./_future.sh + chmod a+rx _common.sh _future.sh fi -# Loads the generic functions usually used in the script source _common.sh -# Source app helpers source /usr/share/yunohost/helpers +source _future.sh + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= # Get multi-instances specific variables app=$YNH_APP_INSTANCE_NAME # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) +final_path=$(ynh_app_setting_get "$app" final_path) +db_name=$(ynh_sanitize_dbid "$app") -# Copy the app files -final_path="/opt/${app}" -ynh_backup "$final_path" "sources" 1 +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= -# final_path on nginx -sudo sed -i "s@$final_path@__FINALPATH__@g" /etc/nginx/conf.d/${domain}.d/${app}.conf +ynh_backup "$final_path" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= + +ynh_psql_dump_db "$db_name" > db.sql + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup "/etc/systemd/system/$app-web.service" +ynh_backup "/etc/systemd/system/$app-sidekiq.service" +ynh_backup "/etc/systemd/system/$app-streaming.service" + +#================================================= +# BACKUP THE CRON FILE +#================================================= # Copy the nginx conf files -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" -ynh_backup "/etc/cron.d/${app}" "cron.conf" -ynh_backup "/etc/systemd/system/mastodon-web.service" "systemd_web.service" -ynh_backup "/etc/systemd/system/mastodon-sidekiq.service" "systemd_sidekiq.service" -ynh_backup "/etc/systemd/system/mastodon-streaming.service" "systemd_streaming.service" +ynh_backup "/etc/cron.d/$app" + +#================================================= +# BACKUP THE sources.list FILES +#================================================= + ynh_backup "/etc/apt/sources.list.d/backports.list" "apt_backports.list" ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list" - -# final_path on nginx -sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/${domain}.d/${app}.conf - -# Backup db -db_name=$(ynh_sanitize_dbid "$app") -ynh_psql_dump_db "$db_name" - -# Fix backup fail on yunohost 2.6 -#ynh_secure_remove /var/lib/postgresql/mastodon_db.sql From 3004a1c0414e691ed2c771a5200c6359028a8e5e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Tue, 1 May 2018 20:44:54 +0200 Subject: [PATCH 12/45] Try to limit the log --- scripts/install | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/install b/scripts/install index 56b8ef8..8e505e7 100644 --- a/scripts/install +++ b/scripts/install @@ -103,7 +103,7 @@ ynh_install_app_dependencies \ `# redis ` \ redis-server redis-tools \ `# postgresql ` \ - postgresql postgresql-contrib postgresql-server-dev-9.4 \ + postgresql \ `# Ruby ` \ autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev \ `# ffmpeg from backports ` \ @@ -215,12 +215,12 @@ sed -i "s@#SMTP_OPENSSL_VERIFY_MODE=peer@SMTP_OPENSSL_VERIFY_MODE=none@g" "${fin cd "$final_path/live" su mastodon <> .env.production -RAILS_ENV=production $final_path/live/bin/bundle exec rails db:migrate -RAILS_ENV=production $final_path/live/bin/bundle exec rails assets:precompile +RAILS_ENV=production $final_path/live/bin/bundle exec rails db:migrate --quiet +RAILS_ENV=production $final_path/live/bin/bundle exec rails assets:precompile --quiet INSTALL ) From b67376ec30c52e5d0ff2014fb89149a5e8fd2215 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Tue, 1 May 2018 20:45:29 +0200 Subject: [PATCH 13/45] add support for ynh_backup_before_upgrade and ynh_abort_if_errors --- scripts/upgrade | 56 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 47b4712..54cdd8f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,13 +1,18 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Loads the generic functions usually used in the script source _common.sh -# Source YunoHost helpers source /usr/share/yunohost/helpers +#================================================= +# LOAD SETTINGS +#================================================= + # See comments in install script app=$YNH_APP_INSTANCE_NAME @@ -16,8 +21,23 @@ domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) admin=$(ynh_app_setting_get "$app" admin) language=$(ynh_app_setting_get "$app" language) +final_path=$(ynh_app_setting_get "$app" final_path) -CHECK_PATH # Checks and corrects the syntax of the path. +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +# If db_name doesn't exist, create it +if [ -z "$db_name" ]; then + db_name=$(ynh_sanitize_dbid "$app") + ynh_app_setting_set "$app" db_name "$db_name" +fi + +# If final_path doesn't exist, create it +if [ -z "$final_path" ]; then + final_path=/var/www/$app + ynh_app_setting_set "$app" final_path "$final_path" +fi # Check if admin is not null if [[ "$admin" = "" || "$language" = "" ]]; then @@ -25,7 +45,31 @@ if [[ "$admin" = "" || "$language" = "" ]]; then ynh_die fi -final_path=/opt/$app +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +# 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 + +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# TODO TODO TODO +#================================================= db_name=$app From 6c799ee0ea055f5cac7ccde0e863701b2096bd6f Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 15 May 2018 12:51:45 +0200 Subject: [PATCH 14/45] Update to 2.4.0rc2 --- conf/app-mastodon.src | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/app-mastodon.src b/conf/app-mastodon.src index 62d10c6..7dc2b6f 100644 --- a/conf/app-mastodon.src +++ b/conf/app-mastodon.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.3.3.tar.gz -SOURCE_SUM=b2b2e2ee7cc034e92258263500c423b900611407db67682777eef0526118f66e +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.0rc2.zip +SOURCE_SUM=fe2fbc865e6f174ab3dfaa7cc061b2134c75ff0fe43a577b0466c10642d50132 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true From 2a8c5cf78978f82266a7b510c55aac1222f9fa7c Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 15 May 2018 14:28:54 +0200 Subject: [PATCH 15/45] Update to 2.4.0rc3 --- conf/app-mastodon.src | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/app-mastodon.src b/conf/app-mastodon.src index 7dc2b6f..7f6864b 100644 --- a/conf/app-mastodon.src +++ b/conf/app-mastodon.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.0rc2.zip -SOURCE_SUM=fe2fbc865e6f174ab3dfaa7cc061b2134c75ff0fe43a577b0466c10642d50132 +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.0rc3.tar.gz +SOURCE_SUM=7e3a9ede97b15d4e3daf09bcc97bc00de7a88fd6d7fdc37dd124fa77b27c7d76 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true From 4d826e39e4b23996f1d91a190ced9561dd7a2d27 Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 15 May 2018 14:33:22 +0200 Subject: [PATCH 16/45] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 926ab36..103ebcd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mastodon for YunoHost -[![Latest Version](https://img.shields.io/badge/version-2.2.0-green.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/releases) +[![Latest Version](https://img.shields.io/badge/version-2.4.0-green.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/releases) [![Status](https://img.shields.io/badge/status-testing-yellow.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/milestones) [![Dependencies](https://img.shields.io/badge/dependencies-includes-lightgrey.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh#dependencies) [![GitHub license](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](https://raw.githubusercontent.com/YunoHost-Apps/mastodon_ynh/master/LICENSE) From a99ba70d0804ab7a77ec5fafdf5ec44b137ac913 Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 15 May 2018 14:33:51 +0200 Subject: [PATCH 17/45] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index dc1bde6..3e6e9b4 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,7 @@ "en": "Mastodon is a free, open-source social network.", "fr": "Mastodon est un réseau social gratuit et open source." }, - "version": "2.3.3-1", + "version": "2.4.0", "url": "https://github.com/tootsuite/mastodon", "license": "AGPL-3.0-or-later", "maintainer": { From ee5bc6a165e573b60c7657cee7ebc8f1646f1fa8 Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 15 May 2018 16:39:10 +0200 Subject: [PATCH 18/45] Make upgrade from sources --- scripts/upgrade | 116 ++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 54cdd8f..71f4e1b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,6 +15,7 @@ source /usr/share/yunohost/helpers # See comments in install script app=$YNH_APP_INSTANCE_NAME +db_name=$app # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) @@ -66,41 +67,11 @@ ynh_abort_if_errors path_url=$(ynh_normalize_url_path $path_url) #================================================= -# STANDARD UPGRADE STEPS +# INSTALL DEPENDENCIES #================================================= -# TODO TODO TODO -#================================================= - -db_name=$app - -# Modify Nginx configuration file and copy it to Nginx conf directory -sudo sed -i "s@__PATH__@$app@g" ../conf/nginx.conf* -sudo sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf* -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf - -# Stop Mastodon Services -sudo systemctl stop mastodon-*.service - -# Change owner of live folder -sudo chown -R $app: $final_path/live - -# Download Mastodon -sudo su - $app < Date: Tue, 15 May 2018 17:08:31 +0200 Subject: [PATCH 19/45] Add path_url --- scripts/upgrade | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/upgrade b/scripts/upgrade index 71f4e1b..e777d99 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,6 +23,7 @@ path=$(ynh_app_setting_get "$app" path) admin=$(ynh_app_setting_get "$app" admin) language=$(ynh_app_setting_get "$app" language) final_path=$(ynh_app_setting_get "$app" final_path) +path_url="/" #================================================= # ENSURE DOWNWARD COMPATIBILITY From 262af428f164a86451fe938f2526a1e9c9dc6071 Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 16 May 2018 09:13:01 +0200 Subject: [PATCH 20/45] Fix url_path checking --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index e777d99..83f1740 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -65,7 +65,7 @@ ynh_abort_if_errors #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) +#path_url=$(ynh_normalize_url_path $path_url) #================================================= # INSTALL DEPENDENCIES From e6589fa54b9f2e23320c9845648ea85cd5ba3d2f Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 16 May 2018 10:00:10 +0200 Subject: [PATCH 21/45] Fix rb install --- scripts/upgrade | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 83f1740..e34ef9d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -115,8 +115,8 @@ ynh_setup_source "$final_path/.rbenv/plugins/ruby-build" "app-ruby-build" # Install ruby 2.5.0 ( - exec_as "$app" $final_path/.rbenv/bin/rbenv install 2.5.0 - exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.5.0 + exec_as "$app" $final_path/.rbenv/bin/rbenv install 2.5.0 || true + exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.5.0 || true exec_as "$app" $final_path/.rbenv/versions/2.5.0/bin/ruby -v ) From 28cdf3a0c418ffebf388f7c1f695407469d47124 Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 16 May 2018 10:27:07 +0200 Subject: [PATCH 22/45] rb2.5.1 --- scripts/install | 10 +++++----- scripts/upgrade | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/install b/scripts/install index 8e505e7..81ce213 100644 --- a/scripts/install +++ b/scripts/install @@ -170,14 +170,14 @@ eval \"\$(rbenv init -)\"" > $final_path/.profile # Install ruby-build ( - exec_as "$app" $final_path/.rbenv/bin/rbenv install 2.5.0 - exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.5.0 - exec_as "$app" $final_path/.rbenv/versions/2.5.0/bin/ruby -v + exec_as "$app" $final_path/.rbenv/bin/rbenv install 2.5.1 + exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.5.1 + exec_as "$app" $final_path/.rbenv/versions/2.5.1/bin/ruby -v ) # Create symlink for ruby rm /usr/bin/ruby || true -ln -s $final_path/.rbenv/versions/2.5.0/bin/ruby /usr/bin/ruby || true +ln -s $final_path/.rbenv/versions/2.5.1/bin/ruby /usr/bin/ruby || true # Adjust Mastodon config # TODO: use official helper ynh_replace_string @@ -214,7 +214,7 @@ sed -i "s@#SMTP_OPENSSL_VERIFY_MODE=peer@SMTP_OPENSSL_VERIFY_MODE=none@g" "${fin ( cd "$final_path/live" su mastodon < Date: Wed, 16 May 2018 11:35:11 +0200 Subject: [PATCH 23/45] bundle 2.5.1 --- scripts/upgrade | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 9d7cc7c..34cff85 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -139,11 +139,11 @@ MCOMMANDS ( sudo su - $app < Date: Wed, 16 May 2018 12:07:46 +0200 Subject: [PATCH 24/45] fix bundle 2.5.1 --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 34cff85..3d5dcd3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -130,7 +130,7 @@ ln -s $final_path/.rbenv/versions/2.5.1/bin/ruby /usr/bin/ruby || true sudo su - $app < Date: Fri, 8 Jun 2018 10:29:44 +0200 Subject: [PATCH 25/45] Ready to Yunohost 3 and Debian Stretch --- conf/app-mastodon.src | 4 ++-- conf/crontab_mastodon | 7 ------- scripts/backup | 5 +++-- scripts/install | 17 +++++++++-------- scripts/remove | 7 ++++--- scripts/restore | 4 +++- scripts/upgrade | 6 +++++- 7 files changed, 26 insertions(+), 24 deletions(-) delete mode 100644 conf/crontab_mastodon diff --git a/conf/app-mastodon.src b/conf/app-mastodon.src index 7f6864b..84b72fb 100644 --- a/conf/app-mastodon.src +++ b/conf/app-mastodon.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.0rc3.tar.gz -SOURCE_SUM=7e3a9ede97b15d4e3daf09bcc97bc00de7a88fd6d7fdc37dd124fa77b27c7d76 +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.0.tar.gz +SOURCE_SUM=3d4904f30c28591333b1cf4c03173849dd6983ab00685f61e50e594160c672ee SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/crontab_mastodon b/conf/crontab_mastodon deleted file mode 100644 index 62caff0..0000000 --- a/conf/crontab_mastodon +++ /dev/null @@ -1,7 +0,0 @@ -@daily __APP__ cd /opt/__APP__/live && RAILS_ENV=production /opt/__APP__/.rbenv/shims/bundle exec rake mastodon:media:clear - -@daily __APP__ cd /opt/__APP__/live && RAILS_ENV=production /opt/__APP__/.rbenv/shims/bundle exec rake mastodon:push:refresh - -@daily __APP__ cd /opt/__APP__/live && RAILS_ENV=production /opt/__APP__/.rbenv/shims/bundle exec rake mastodon:feeds:clear - -@daily __APP__ cd /opt/__APP__/live && RAILS_ENV=production /opt/__APP__/.rbenv/shims/bundle exec rake mastodon:users:clear diff --git a/scripts/backup b/scripts/backup index 5e134ac..ab231b3 100644 --- a/scripts/backup +++ b/scripts/backup @@ -75,6 +75,7 @@ ynh_backup "/etc/cron.d/$app" #================================================= # BACKUP THE sources.list FILES #================================================= - -ynh_backup "/etc/apt/sources.list.d/backports.list" "apt_backports.list" +if [ "$(lsb_release --codename --short)" == "jessie" ]; then + ynh_backup "/etc/apt/sources.list.d/backports.list" "apt_backports.list" +fi ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list" diff --git a/scripts/install b/scripts/install index 81ce213..8058671 100644 --- a/scripts/install +++ b/scripts/install @@ -80,7 +80,9 @@ if [[ "$arch" = arm* ]]; then fi # Install source.list debian package backports & yarn -cp ../conf/backports.list /etc/apt/sources.list.d/ +if [ "$(lsb_release --codename --short)" == "jessie" ]; then +sudo cp ../conf/backports.list /etc/apt/sources.list.d/ +fi curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - cp ../conf/yarn.list /etc/apt/sources.list.d/ ynh_package_update @@ -214,13 +216,12 @@ sed -i "s@#SMTP_OPENSSL_VERIFY_MODE=peer@SMTP_OPENSSL_VERIFY_MODE=none@g" "${fin ( cd "$final_path/live" su mastodon <> .env.production -RAILS_ENV=production $final_path/live/bin/bundle exec rails db:migrate --quiet -RAILS_ENV=production $final_path/live/bin/bundle exec rails assets:precompile --quiet + $final_path/.rbenv/versions/2.5.1/bin/gem install bundler + $final_path/live/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test --quiet + yarn install --production --no-progress --non-interactive --silent + echo "SAFETY_ASSURED=1">> .env.production + RAILS_ENV=production $final_path/live/bin/bundle exec rails db:migrate --quiet + RAILS_ENV=production $final_path/live/bin/bundle exec rails assets:precompile --quiet INSTALL ) diff --git a/scripts/remove b/scripts/remove index 0c39054..e939908 100644 --- a/scripts/remove +++ b/scripts/remove @@ -98,12 +98,13 @@ ynh_secure_remove /etc/cron.d/$app #================================================= # REMOVE source.list #================================================= - -ynh_secure_remove /etc/apt/sources.list.d/backports.list +if [ "$(lsb_release --codename --short)" == "jessie" ]; then + ynh_secure_remove /etc/apt/sources.list.d/backports.list +fi ynh_secure_remove /etc/apt/sources.list.d/yarn.list # Delete ruby exec -ynh_secure_remove /usr/bin/ruby +#ynh_secure_remove /usr/bin/ruby #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index b9798a7..77cb229 100644 --- a/scripts/restore +++ b/scripts/restore @@ -88,7 +88,9 @@ if [[ "$arch" = arm* ]]; then fi # Install source.list debian package backports & yarn -cp ../conf/backports.list /etc/apt/sources.list.d/ +if [ "$(lsb_release --codename --short)" == "jessie" ]; then + cp ../conf/backports.list /etc/apt/sources.list.d/ +fi curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - cp ../conf/yarn.list /etc/apt/sources.list.d/ ynh_package_update diff --git a/scripts/upgrade b/scripts/upgrade index 3d5dcd3..c151b57 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -130,7 +130,11 @@ ln -s $final_path/.rbenv/versions/2.5.1/bin/ruby /usr/bin/ruby || true sudo su - $app < Date: Fri, 8 Jun 2018 10:59:14 +0200 Subject: [PATCH 26/45] Remove mastodon cron tasks --- scripts/backup | 7 ------- scripts/install | 4 ---- scripts/restore | 6 ------ 3 files changed, 17 deletions(-) diff --git a/scripts/backup b/scripts/backup index ab231b3..0846afe 100644 --- a/scripts/backup +++ b/scripts/backup @@ -65,13 +65,6 @@ ynh_backup "/etc/systemd/system/$app-web.service" ynh_backup "/etc/systemd/system/$app-sidekiq.service" ynh_backup "/etc/systemd/system/$app-streaming.service" -#================================================= -# BACKUP THE CRON FILE -#================================================= - -# Copy the nginx conf files -ynh_backup "/etc/cron.d/$app" - #================================================= # BACKUP THE sources.list FILES #================================================= diff --git a/scripts/install b/scripts/install index 8058671..cbce4e3 100644 --- a/scripts/install +++ b/scripts/install @@ -247,10 +247,6 @@ RAILS_ENV=production bin/bundle exec rails mastodon:confirm_email USER_EMAIL=$ad SETADMIN ) -# Install crontab -cp ../conf/crontab_mastodon /etc/cron.d/$app -sed -i "s@__APP__@$app@g" /etc/cron.d/$app - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 77cb229..a800966 100644 --- a/scripts/restore +++ b/scripts/restore @@ -148,12 +148,6 @@ ynh_restore_file "/etc/systemd/system/$app-sidekiq.service" ynh_restore_file "/etc/systemd/system/$app-streaming.service" systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" -#================================================= -# RESTORE THE CRON FILE -#================================================= - -ynh_restore_file "/etc/cron.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= From 7ca04c54256ccdd516a4869973f66b9f34cdf2ce Mon Sep 17 00:00:00 2001 From: nemsia Date: Fri, 8 Jun 2018 15:37:06 +0200 Subject: [PATCH 27/45] Fix Upgrade yarn not installed --- scripts/upgrade | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index c151b57..4ceea66 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -141,10 +141,11 @@ MCOMMANDS # Apply Mastodon upgrade ( -sudo su - $app < Date: Fri, 8 Jun 2018 16:10:26 +0200 Subject: [PATCH 28/45] Fix Upgrade --- scripts/upgrade | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index 4ceea66..3858ee8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -141,8 +141,10 @@ MCOMMANDS # Apply Mastodon upgrade ( +pushd $final_path/live RAILS_ENV=production $final_path/.rbenv/versions/2.5.1/bin/bundle exec rails assets:clean RAILS_ENV=production $final_path/.rbenv/versions/2.5.1/bin/bundle exec rails assets:precompile +popd sudo su - $app < Date: Tue, 12 Jun 2018 18:32:43 +0200 Subject: [PATCH 29/45] Testing 2.4 (#90) * Ready to Yunohost 3 and Debian Stretch * Remove mastodon cron tasks * Fix Upgrade yarn not installed * Fix Upgrade --- README.md | 2 +- conf/app-mastodon.src | 4 +- conf/crontab_mastodon | 7 --- manifest.json | 2 +- scripts/backup | 12 +--- scripts/install | 29 ++++----- scripts/remove | 7 ++- scripts/restore | 10 +-- scripts/upgrade | 138 +++++++++++++++++++++++++----------------- 9 files changed, 109 insertions(+), 102 deletions(-) delete mode 100644 conf/crontab_mastodon diff --git a/README.md b/README.md index 926ab36..103ebcd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mastodon for YunoHost -[![Latest Version](https://img.shields.io/badge/version-2.2.0-green.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/releases) +[![Latest Version](https://img.shields.io/badge/version-2.4.0-green.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/releases) [![Status](https://img.shields.io/badge/status-testing-yellow.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/milestones) [![Dependencies](https://img.shields.io/badge/dependencies-includes-lightgrey.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh#dependencies) [![GitHub license](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](https://raw.githubusercontent.com/YunoHost-Apps/mastodon_ynh/master/LICENSE) diff --git a/conf/app-mastodon.src b/conf/app-mastodon.src index 62d10c6..84b72fb 100644 --- a/conf/app-mastodon.src +++ b/conf/app-mastodon.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.3.3.tar.gz -SOURCE_SUM=b2b2e2ee7cc034e92258263500c423b900611407db67682777eef0526118f66e +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.0.tar.gz +SOURCE_SUM=3d4904f30c28591333b1cf4c03173849dd6983ab00685f61e50e594160c672ee SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/crontab_mastodon b/conf/crontab_mastodon deleted file mode 100644 index 62caff0..0000000 --- a/conf/crontab_mastodon +++ /dev/null @@ -1,7 +0,0 @@ -@daily __APP__ cd /opt/__APP__/live && RAILS_ENV=production /opt/__APP__/.rbenv/shims/bundle exec rake mastodon:media:clear - -@daily __APP__ cd /opt/__APP__/live && RAILS_ENV=production /opt/__APP__/.rbenv/shims/bundle exec rake mastodon:push:refresh - -@daily __APP__ cd /opt/__APP__/live && RAILS_ENV=production /opt/__APP__/.rbenv/shims/bundle exec rake mastodon:feeds:clear - -@daily __APP__ cd /opt/__APP__/live && RAILS_ENV=production /opt/__APP__/.rbenv/shims/bundle exec rake mastodon:users:clear diff --git a/manifest.json b/manifest.json index dc1bde6..3e6e9b4 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,7 @@ "en": "Mastodon is a free, open-source social network.", "fr": "Mastodon est un réseau social gratuit et open source." }, - "version": "2.3.3-1", + "version": "2.4.0", "url": "https://github.com/tootsuite/mastodon", "license": "AGPL-3.0-or-later", "maintainer": { diff --git a/scripts/backup b/scripts/backup index 5e134ac..0846afe 100644 --- a/scripts/backup +++ b/scripts/backup @@ -65,16 +65,10 @@ ynh_backup "/etc/systemd/system/$app-web.service" ynh_backup "/etc/systemd/system/$app-sidekiq.service" ynh_backup "/etc/systemd/system/$app-streaming.service" -#================================================= -# BACKUP THE CRON FILE -#================================================= - -# Copy the nginx conf files -ynh_backup "/etc/cron.d/$app" - #================================================= # BACKUP THE sources.list FILES #================================================= - -ynh_backup "/etc/apt/sources.list.d/backports.list" "apt_backports.list" +if [ "$(lsb_release --codename --short)" == "jessie" ]; then + ynh_backup "/etc/apt/sources.list.d/backports.list" "apt_backports.list" +fi ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list" diff --git a/scripts/install b/scripts/install index 8e505e7..cbce4e3 100644 --- a/scripts/install +++ b/scripts/install @@ -80,7 +80,9 @@ if [[ "$arch" = arm* ]]; then fi # Install source.list debian package backports & yarn -cp ../conf/backports.list /etc/apt/sources.list.d/ +if [ "$(lsb_release --codename --short)" == "jessie" ]; then +sudo cp ../conf/backports.list /etc/apt/sources.list.d/ +fi curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - cp ../conf/yarn.list /etc/apt/sources.list.d/ ynh_package_update @@ -170,14 +172,14 @@ eval \"\$(rbenv init -)\"" > $final_path/.profile # Install ruby-build ( - exec_as "$app" $final_path/.rbenv/bin/rbenv install 2.5.0 - exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.5.0 - exec_as "$app" $final_path/.rbenv/versions/2.5.0/bin/ruby -v + exec_as "$app" $final_path/.rbenv/bin/rbenv install 2.5.1 + exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.5.1 + exec_as "$app" $final_path/.rbenv/versions/2.5.1/bin/ruby -v ) # Create symlink for ruby rm /usr/bin/ruby || true -ln -s $final_path/.rbenv/versions/2.5.0/bin/ruby /usr/bin/ruby || true +ln -s $final_path/.rbenv/versions/2.5.1/bin/ruby /usr/bin/ruby || true # Adjust Mastodon config # TODO: use official helper ynh_replace_string @@ -214,13 +216,12 @@ sed -i "s@#SMTP_OPENSSL_VERIFY_MODE=peer@SMTP_OPENSSL_VERIFY_MODE=none@g" "${fin ( cd "$final_path/live" su mastodon <> .env.production -RAILS_ENV=production $final_path/live/bin/bundle exec rails db:migrate --quiet -RAILS_ENV=production $final_path/live/bin/bundle exec rails assets:precompile --quiet + $final_path/.rbenv/versions/2.5.1/bin/gem install bundler + $final_path/live/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test --quiet + yarn install --production --no-progress --non-interactive --silent + echo "SAFETY_ASSURED=1">> .env.production + RAILS_ENV=production $final_path/live/bin/bundle exec rails db:migrate --quiet + RAILS_ENV=production $final_path/live/bin/bundle exec rails assets:precompile --quiet INSTALL ) @@ -246,10 +247,6 @@ RAILS_ENV=production bin/bundle exec rails mastodon:confirm_email USER_EMAIL=$ad SETADMIN ) -# Install crontab -cp ../conf/crontab_mastodon /etc/cron.d/$app -sed -i "s@__APP__@$app@g" /etc/cron.d/$app - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/remove b/scripts/remove index 0c39054..e939908 100644 --- a/scripts/remove +++ b/scripts/remove @@ -98,12 +98,13 @@ ynh_secure_remove /etc/cron.d/$app #================================================= # REMOVE source.list #================================================= - -ynh_secure_remove /etc/apt/sources.list.d/backports.list +if [ "$(lsb_release --codename --short)" == "jessie" ]; then + ynh_secure_remove /etc/apt/sources.list.d/backports.list +fi ynh_secure_remove /etc/apt/sources.list.d/yarn.list # Delete ruby exec -ynh_secure_remove /usr/bin/ruby +#ynh_secure_remove /usr/bin/ruby #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index b9798a7..a800966 100644 --- a/scripts/restore +++ b/scripts/restore @@ -88,7 +88,9 @@ if [[ "$arch" = arm* ]]; then fi # Install source.list debian package backports & yarn -cp ../conf/backports.list /etc/apt/sources.list.d/ +if [ "$(lsb_release --codename --short)" == "jessie" ]; then + cp ../conf/backports.list /etc/apt/sources.list.d/ +fi curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - cp ../conf/yarn.list /etc/apt/sources.list.d/ ynh_package_update @@ -146,12 +148,6 @@ ynh_restore_file "/etc/systemd/system/$app-sidekiq.service" ynh_restore_file "/etc/systemd/system/$app-streaming.service" systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" -#================================================= -# RESTORE THE CRON FILE -#================================================= - -ynh_restore_file "/etc/cron.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 54cdd8f..3858ee8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,6 +15,7 @@ source /usr/share/yunohost/helpers # See comments in install script app=$YNH_APP_INSTANCE_NAME +db_name=$app # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) @@ -22,6 +23,7 @@ path=$(ynh_app_setting_get "$app" path) admin=$(ynh_app_setting_get "$app" admin) language=$(ynh_app_setting_get "$app" language) final_path=$(ynh_app_setting_get "$app" final_path) +path_url="/" #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -63,44 +65,14 @@ ynh_abort_if_errors #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) +#path_url=$(ynh_normalize_url_path $path_url) #================================================= -# STANDARD UPGRADE STEPS +# INSTALL DEPENDENCIES #================================================= -# TODO TODO TODO -#================================================= - -db_name=$app - -# Modify Nginx configuration file and copy it to Nginx conf directory -sudo sed -i "s@__PATH__@$app@g" ../conf/nginx.conf* -sudo sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf* -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf - -# Stop Mastodon Services -sudo systemctl stop mastodon-*.service - -# Change owner of live folder -sudo chown -R $app: $final_path/live - -# Download Mastodon -sudo su - $app < Date: Tue, 12 Jun 2018 21:43:34 +0200 Subject: [PATCH 30/45] Update to 2.4.1 + fixs *Fix upgrade,restore scripts * Readme and manifest to 2.4.1 --- README.md | 4 ++-- manifest.json | 2 +- scripts/restore | 4 ++-- scripts/upgrade | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 103ebcd..488481d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Mastodon for YunoHost -[![Latest Version](https://img.shields.io/badge/version-2.4.0-green.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/releases) +[![Latest Version](https://img.shields.io/badge/version-2.4.1-green.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/releases) [![Status](https://img.shields.io/badge/status-testing-yellow.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/milestones) [![Dependencies](https://img.shields.io/badge/dependencies-includes-lightgrey.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh#dependencies) [![GitHub license](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](https://raw.githubusercontent.com/YunoHost-Apps/mastodon_ynh/master/LICENSE) -[![Yunohost version](https://img.shields.io/badge/yunohost-2.7.7_tested-orange.svg?style=flat)](https://github.com/YunoHost/yunohost) +[![Yunohost version](https://img.shields.io/badge/yunohost-2.7.12_tested-orange.svg?style=flat)](https://github.com/YunoHost/yunohost) [![GitHub issues](https://img.shields.io/github/issues/YunoHost-Apps/mastodon_ynh.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/issues) [![Install Mastodon with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=mastodon) diff --git a/manifest.json b/manifest.json index 3e6e9b4..11c277b 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,7 @@ "en": "Mastodon is a free, open-source social network.", "fr": "Mastodon est un réseau social gratuit et open source." }, - "version": "2.4.0", + "version": "2.4.1", "url": "https://github.com/tootsuite/mastodon", "license": "AGPL-3.0-or-later", "maintainer": { diff --git a/scripts/restore b/scripts/restore index a800966..0d32504 100644 --- a/scripts/restore +++ b/scripts/restore @@ -89,10 +89,10 @@ fi # Install source.list debian package backports & yarn if [ "$(lsb_release --codename --short)" == "jessie" ]; then - cp ../conf/backports.list /etc/apt/sources.list.d/ + cp ../conf/apt_backports.list /etc/apt/sources.list.d/ fi curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -cp ../conf/yarn.list /etc/apt/sources.list.d/ +cp ../conf/apt_yarn.list /etc/apt/sources.list.d/yarn.list ynh_package_update # Install de Node.js diff --git a/scripts/upgrade b/scripts/upgrade index 3858ee8..53e1828 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -115,7 +115,7 @@ ynh_setup_source "$final_path/.rbenv/plugins/ruby-build" "app-ruby-build" # Install ruby 2.5.1 ( - exec_as "$app" $final_path/.rbenv/bin/rbenv install 2.5.1 || true + exec_as "$app" $final_path/.rbenv/bin/rbenv install -s 2.5.1 || true exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.5.1 || true exec_as "$app" $final_path/.rbenv/versions/2.5.1/bin/ruby -v ) From 1993c3b2eed04b3df8e518a5d5a2837997133949 Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 12 Jun 2018 21:44:45 +0200 Subject: [PATCH 31/45] db:Setup on install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index cbce4e3..9e8a873 100644 --- a/scripts/install +++ b/scripts/install @@ -220,7 +220,7 @@ sed -i "s@#SMTP_OPENSSL_VERIFY_MODE=peer@SMTP_OPENSSL_VERIFY_MODE=none@g" "${fin $final_path/live/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test --quiet yarn install --production --no-progress --non-interactive --silent echo "SAFETY_ASSURED=1">> .env.production - RAILS_ENV=production $final_path/live/bin/bundle exec rails db:migrate --quiet + RAILS_ENV=production $final_path/live/bin/bundle exec rails db:setup --quiet RAILS_ENV=production $final_path/live/bin/bundle exec rails assets:precompile --quiet INSTALL ) From f102d956921286ba066473a325b18b1416af030a Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 12 Jun 2018 21:58:05 +0200 Subject: [PATCH 32/45] Mastodon Sources 2.4.1 --- conf/app-mastodon.src | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/app-mastodon.src b/conf/app-mastodon.src index 84b72fb..61c7260 100644 --- a/conf/app-mastodon.src +++ b/conf/app-mastodon.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.0.tar.gz -SOURCE_SUM=3d4904f30c28591333b1cf4c03173849dd6983ab00685f61e50e594160c672ee +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.1.tar.gz +SOURCE_SUM=d90b573e16359f63f7b2834f1078ecfdd7d78cd5a26acd8293a314dd2b6ff1ec SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true From ae04282b9e5bb3a2dff513b1c37c0ff54fd95db4 Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 12 Jun 2018 22:53:03 +0200 Subject: [PATCH 33/45] Change db_name on all scripts to mastodon_production --- scripts/backup | 6 +++++- scripts/install | 4 +++- scripts/remove | 5 ++++- scripts/restore | 6 +++++- scripts/upgrade | 4 ++-- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/scripts/backup b/scripts/backup index 0846afe..f32dfdd 100644 --- a/scripts/backup +++ b/scripts/backup @@ -33,7 +33,11 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) final_path=$(ynh_app_setting_get "$app" final_path) -db_name=$(ynh_sanitize_dbid "$app") +db_name=$(ynh_app_setting_get "$app" db_name) +if [ -z "$db_name" ]; then + db_name="${app}_production" + ynh_app_setting_set "$app" db_name "$db_name" +fi #================================================= # STANDARD BACKUP STEPS diff --git a/scripts/install b/scripts/install index 9e8a873..90a8dfc 100644 --- a/scripts/install +++ b/scripts/install @@ -124,8 +124,10 @@ ynh_install_app_dependencies \ ynh_psql_test_if_first_run db_user=$(ynh_sanitize_dbid "$app") -db_name=$(ynh_sanitize_dbid "$app") +db_name="${app}_production" +db_name=$(ynh_sanitize_dbid "$db_name") db_pwd=$(ynh_string_random) +ynh_app_setting_set $app db_name $db_name ynh_app_setting_set $app db_pwd $db_pwd ynh_psql_setup_db "$db_user" "$db_name" "$db_pwd" diff --git a/scripts/remove b/scripts/remove index e939908..470455e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -22,8 +22,11 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) db_name=$(ynh_app_setting_get "$app" db_name) +if [ -z "$db_name" ]; then + db_name="${app}_production" + ynh_app_setting_set "$app" db_name "$db_name" +fi db_user=$(ynh_sanitize_dbid "$app") -db_name=$(ynh_sanitize_dbid "$app") final_path=$(ynh_app_setting_get "$app" final_path) #================================================= diff --git a/scripts/restore b/scripts/restore index 0d32504..b41b9cd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -124,7 +124,11 @@ ynh_install_app_dependencies \ # Restore PostgreSQL database db_user=$(ynh_sanitize_dbid "$app") -db_name=$(ynh_sanitize_dbid "$app") +db_name=$(ynh_app_setting_get "$app" db_name) +if [ -z "$db_name" ]; then + db_name="${app}_production" + ynh_app_setting_set "$app" db_name "$db_name" +fi db_pwd=$(ynh_app_setting_get "$app" db_pwd) ynh_psql_test_if_first_run diff --git a/scripts/upgrade b/scripts/upgrade index 53e1828..d50b729 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers # See comments in install script app=$YNH_APP_INSTANCE_NAME -db_name=$app +db_name=$(ynh_app_setting_get "$app" db_name) # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) @@ -31,7 +31,7 @@ path_url="/" # If db_name doesn't exist, create it if [ -z "$db_name" ]; then - db_name=$(ynh_sanitize_dbid "$app") + db_name="${app}_production" ynh_app_setting_set "$app" db_name "$db_name" fi From ae84054e6af9d9650a6d3a3cdd977665b33e29d3 Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 13 Jun 2018 00:23:05 +0200 Subject: [PATCH 34/45] Fix db_user create --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 7d4f823..89ace8a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -162,7 +162,7 @@ ynh_psql_dump_db() { ynh_psql_create_user() { user="$1" pwd="$2" - sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd'" postgres + sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd';" postgres } # Drop a user From 28e87db2b44de048e98cf1eb9c9ce82820c660f7 Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 13 Jun 2018 00:29:34 +0200 Subject: [PATCH 35/45] Fix Testing 2.4 (#91) * Fix db_user create --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 7d4f823..89ace8a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -162,7 +162,7 @@ ynh_psql_dump_db() { ynh_psql_create_user() { user="$1" pwd="$2" - sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd'" postgres + sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd';" postgres } # Drop a user From 8e1d57d0dd69faa66280f3a7ba2ed93d7dee00db Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 13 Jun 2018 11:30:51 +0200 Subject: [PATCH 36/45] db:migrate on install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 90a8dfc..22abeff 100644 --- a/scripts/install +++ b/scripts/install @@ -222,7 +222,7 @@ sed -i "s@#SMTP_OPENSSL_VERIFY_MODE=peer@SMTP_OPENSSL_VERIFY_MODE=none@g" "${fin $final_path/live/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test --quiet yarn install --production --no-progress --non-interactive --silent echo "SAFETY_ASSURED=1">> .env.production - RAILS_ENV=production $final_path/live/bin/bundle exec rails db:setup --quiet + RAILS_ENV=production $final_path/live/bin/bundle exec rails db:migrate --quiet RAILS_ENV=production $final_path/live/bin/bundle exec rails assets:precompile --quiet INSTALL ) From a961856c7ec1a131cad408fd8133251607af688e Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 13 Jun 2018 12:19:22 +0200 Subject: [PATCH 37/45] Add createdb right to mastodon postgre role --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 89ace8a..df631ad 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -162,7 +162,7 @@ ynh_psql_dump_db() { ynh_psql_create_user() { user="$1" pwd="$2" - sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd';" postgres + sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd' CREATEDB;" postgres } # Drop a user From d0e9f2e753886ef22bdb2447b4031fd72bded3b6 Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 13 Jun 2018 13:13:08 +0200 Subject: [PATCH 38/45] Fix Restore Script --- scripts/restore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/restore b/scripts/restore index b41b9cd..8cd72ed 100644 --- a/scripts/restore +++ b/scripts/restore @@ -89,10 +89,10 @@ fi # Install source.list debian package backports & yarn if [ "$(lsb_release --codename --short)" == "jessie" ]; then - cp ../conf/apt_backports.list /etc/apt/sources.list.d/ + cp ./apt_backports.list /etc/apt/sources.list.d/ fi curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -cp ../conf/apt_yarn.list /etc/apt/sources.list.d/yarn.list +cp ./apt_yarn.list /etc/apt/sources.list.d/yarn.list ynh_package_update # Install de Node.js From 4e3f28968c4d746a9ffbce43f98cc9c5783f204f Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 13 Jun 2018 13:59:47 +0200 Subject: [PATCH 39/45] Replace reload on restore script --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index 8cd72ed..f8c6e66 100644 --- a/scripts/restore +++ b/scripts/restore @@ -158,5 +158,5 @@ systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" # RELOAD NGINX AND PHP-FPM #================================================= -systemctl reload "$app-web" "$app-sidekiq" "$app-streaming" +systemctl restart "$app-web" "$app-sidekiq" "$app-streaming" systemctl reload nginx From 816d7d6e3566c30acd2ebe7ad5f5853590d298c2 Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 13 Jun 2018 15:49:18 +0200 Subject: [PATCH 40/45] Fix postgresql restore script --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index f8c6e66..feded36 100644 --- a/scripts/restore +++ b/scripts/restore @@ -132,7 +132,7 @@ fi db_pwd=$(ynh_app_setting_get "$app" db_pwd) ynh_psql_test_if_first_run -ynh_psql_setup_db "$db_name" "$db_name" "$db_pwd" +ynh_psql_setup_db "$db_user" "$db_name" "$db_pwd" ynh_psql_execute_file_as_root ./db.sql "$db_name" #================================================= From d740e4e0f38e13f88383a508da2199a2e7cae737 Mon Sep 17 00:00:00 2001 From: nemsia Date: Wed, 13 Jun 2018 16:22:27 +0200 Subject: [PATCH 41/45] Fix backport.list restore --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index feded36..785d057 100644 --- a/scripts/restore +++ b/scripts/restore @@ -89,7 +89,7 @@ fi # Install source.list debian package backports & yarn if [ "$(lsb_release --codename --short)" == "jessie" ]; then - cp ./apt_backports.list /etc/apt/sources.list.d/ + cp ./apt_backports.list /etc/apt/sources.list.d/backports.list fi curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - cp ./apt_yarn.list /etc/apt/sources.list.d/yarn.list From d592fe5cac9722ab931960bf9e95785d1e55f083 Mon Sep 17 00:00:00 2001 From: nemsia Date: Thu, 14 Jun 2018 15:19:48 +0200 Subject: [PATCH 42/45] Remove backports and yarn repo files --- conf/backports.list | 1 - conf/yarn.list | 1 - scripts/backup | 4 +--- scripts/install | 4 ++-- scripts/remove | 1 + scripts/restore | 4 ++-- scripts/upgrade | 8 ++++++++ 7 files changed, 14 insertions(+), 9 deletions(-) delete mode 100644 conf/backports.list delete mode 100644 conf/yarn.list diff --git a/conf/backports.list b/conf/backports.list deleted file mode 100644 index b8c3f51..0000000 --- a/conf/backports.list +++ /dev/null @@ -1 +0,0 @@ -deb http://httpredir.debian.org/debian jessie-backports main \ No newline at end of file diff --git a/conf/yarn.list b/conf/yarn.list deleted file mode 100644 index 842ebb9..0000000 --- a/conf/yarn.list +++ /dev/null @@ -1 +0,0 @@ -deb https://dl.yarnpkg.com/debian/ stable main \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index f32dfdd..be3b0a4 100644 --- a/scripts/backup +++ b/scripts/backup @@ -72,7 +72,5 @@ ynh_backup "/etc/systemd/system/$app-streaming.service" #================================================= # BACKUP THE sources.list FILES #================================================= -if [ "$(lsb_release --codename --short)" == "jessie" ]; then - ynh_backup "/etc/apt/sources.list.d/backports.list" "apt_backports.list" -fi + ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list" diff --git a/scripts/install b/scripts/install index 22abeff..3d4d458 100644 --- a/scripts/install +++ b/scripts/install @@ -81,10 +81,10 @@ fi # Install source.list debian package backports & yarn if [ "$(lsb_release --codename --short)" == "jessie" ]; then -sudo cp ../conf/backports.list /etc/apt/sources.list.d/ + echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list fi curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -cp ../conf/yarn.list /etc/apt/sources.list.d/ +echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list ynh_package_update # Creates the destination directory and stores its location. diff --git a/scripts/remove b/scripts/remove index 470455e..0ea12df 100644 --- a/scripts/remove +++ b/scripts/remove @@ -103,6 +103,7 @@ ynh_secure_remove /etc/cron.d/$app #================================================= if [ "$(lsb_release --codename --short)" == "jessie" ]; then ynh_secure_remove /etc/apt/sources.list.d/backports.list + ynh_secure_remove /etc/apt/sources.list.d/jessie-backports.list fi ynh_secure_remove /etc/apt/sources.list.d/yarn.list diff --git a/scripts/restore b/scripts/restore index 785d057..a8dc79f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -89,10 +89,10 @@ fi # Install source.list debian package backports & yarn if [ "$(lsb_release --codename --short)" == "jessie" ]; then - cp ./apt_backports.list /etc/apt/sources.list.d/backports.list + echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list fi curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -cp ./apt_yarn.list /etc/apt/sources.list.d/yarn.list +echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list ynh_package_update # Install de Node.js diff --git a/scripts/upgrade b/scripts/upgrade index d50b729..a0ca482 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -47,6 +47,14 @@ if [[ "$admin" = "" || "$language" = "" ]]; then ynh_die fi +if [ "$(lsb_release --codename --short)" == "jessie" ]; then + echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list + ynh_secure_remove /etc/apt/sources.list.d/backports.list +fi + +# Add yarn repo +echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= From c9429cbf23826fb6552582708c1673b58644ff3f Mon Sep 17 00:00:00 2001 From: nemsia Date: Thu, 14 Jun 2018 15:25:03 +0200 Subject: [PATCH 43/45] Fix Upgrade --- scripts/upgrade | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index a0ca482..18f4d8e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -47,14 +47,6 @@ if [[ "$admin" = "" || "$language" = "" ]]; then ynh_die fi -if [ "$(lsb_release --codename --short)" == "jessie" ]; then - echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list - ynh_secure_remove /etc/apt/sources.list.d/backports.list -fi - -# Add yarn repo -echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -69,11 +61,17 @@ ynh_clean_setup () { ynh_abort_if_errors #================================================= -# CHECK THE PATH +# Remove repo Files #================================================= -# Normalize the URL path syntax -#path_url=$(ynh_normalize_url_path $path_url) +if [ "$(lsb_release --codename --short)" == "jessie" ]; then + echo "deb http://httpredir.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list + ynh_secure_remove /etc/apt/sources.list.d/backports.list +fi + +# Add yarn repo +echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + #================================================= # INSTALL DEPENDENCIES From 2bd8279988875c5469f397dcd13259c3c26a4883 Mon Sep 17 00:00:00 2001 From: nemsia Date: Mon, 18 Jun 2018 15:15:27 +0200 Subject: [PATCH 44/45] Add pg user pass on upgrade --- scripts/upgrade | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index 18f4d8e..5585e03 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -16,6 +16,7 @@ source /usr/share/yunohost/helpers # See comments in install script app=$YNH_APP_INSTANCE_NAME db_name=$(ynh_app_setting_get "$app" db_name) +db_pwd=$(ynh_app_setting_get "$app" db_pwd) # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) @@ -47,6 +48,15 @@ if [[ "$admin" = "" || "$language" = "" ]]; then ynh_die fi +# If db_pwd doesn't exist, create it +if [[ -z "$db_pwd" ]]; then + db_pwd=$(ynh_string_random) + ynh_app_setting_set $app db_pwd $db_pwd + ynh_psql_test_if_first_run + sudo --login --user=postgres psql -c"ALTER user $app WITH PASSWORD '$db_pwd'" postgres + sed -i "s@DB_PASS=@DB_PASS=${db_pwd}@g" "${final_path}/live/.env.production" +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= From ea65ebe0a1dfda010cd030c6861dd30e0c2b43f7 Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 19 Jun 2018 10:22:04 +0200 Subject: [PATCH 45/45] Update to 2.4.2 --- README.md | 2 +- conf/app-mastodon.src | 4 ++-- manifest.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 488481d..bcfa53c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mastodon for YunoHost -[![Latest Version](https://img.shields.io/badge/version-2.4.1-green.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/releases) +[![Latest Version](https://img.shields.io/badge/version-2.4.2-green.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/releases) [![Status](https://img.shields.io/badge/status-testing-yellow.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh/milestones) [![Dependencies](https://img.shields.io/badge/dependencies-includes-lightgrey.svg?style=flat)](https://github.com/YunoHost-Apps/mastodon_ynh#dependencies) [![GitHub license](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](https://raw.githubusercontent.com/YunoHost-Apps/mastodon_ynh/master/LICENSE) diff --git a/conf/app-mastodon.src b/conf/app-mastodon.src index 61c7260..fa0e2eb 100644 --- a/conf/app-mastodon.src +++ b/conf/app-mastodon.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.1.tar.gz -SOURCE_SUM=d90b573e16359f63f7b2834f1078ecfdd7d78cd5a26acd8293a314dd2b6ff1ec +SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v2.4.2.tar.gz +SOURCE_SUM=2de73e57e4f3da4b046b8b1d8c90a03d1bdd8f9abddca8f5329d02a34ed821a5 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/manifest.json b/manifest.json index 11c277b..ddb2479 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,7 @@ "en": "Mastodon is a free, open-source social network.", "fr": "Mastodon est un réseau social gratuit et open source." }, - "version": "2.4.1", + "version": "2.4.2", "url": "https://github.com/tootsuite/mastodon", "license": "AGPL-3.0-or-later", "maintainer": {