From cfce1f3c1942bb52150137169ddf6be8a5dc1686 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Fri, 6 Apr 2018 19:58:23 +0200 Subject: Rename .fonctions to _common.sh --- scripts/backup | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'scripts/backup') 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 -- cgit v1.2.3-70-g09d2 From f0b132281241bcfdc38be62dd79324b78a4972f2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Tue, 1 May 2018 11:29:25 +0200 Subject: Use latest PostgreSQL helpers --- scripts/_common.sh | 176 +++++++++++++++++++++++++++++++++++++++-------------- scripts/backup | 7 +-- scripts/install | 49 ++++++++------- scripts/remove | 5 +- scripts/restore | 17 +++--- 5 files changed, 170 insertions(+), 84 deletions(-) (limited to 'scripts/backup') 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" +} + +# Execute a command from a file as root user +# +# 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 and grant optionnaly privilegies to a user +# Create a database, an user and its password. Then store the password in the app's config # -# usage: ynh_mysql_create_db db [user [pwd]] +# 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 - + db="$1" + user="$2" + pwd="$3" + ynh_psql_create_user "$user" "$pwd" + sudo --login --user=postgres createdb --owner="$user" "$db" } -# Drop a role +# Drop a database # -# usage: ynh_mysql_drop_role db +# usage: ynh_psql_drop_db db # | arg: db - the database name to drop -ynh_psql_drop_role() { - sudo su -c "psql" postgres <<< \ - "DROP ROLE ${1};" +# | 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" } -# Drop a database +# Dump a database # -# usage: ynh_mysql_drop_db db -# | arg: db - the database name to drop -ynh_psql_drop_db() { - sudo su -c "dropdb ${1}" postgres +# 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 -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= +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" + -# 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 20:43:49 +0200 Subject: Standardization of backup --- scripts/backup | 88 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 27 deletions(-) (limited to 'scripts/backup') 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" -# 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/apt/sources.list.d/backports.list" "apt_backports.list" -ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list" +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= -# final_path on nginx -sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/${domain}.d/${app}.conf +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -# Backup db -db_name=$(ynh_sanitize_dbid "$app") -ynh_psql_dump_db "$db_name" +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= + +ynh_psql_dump_db "$db_name" > db.sql -# Fix backup fail on yunohost 2.6 -#ynh_secure_remove /var/lib/postgresql/mastodon_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/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" -- cgit v1.2.3-70-g09d2 From 982f3bbde2178906fd1b8244a2bc207281b8a4ea Mon Sep 17 00:00:00 2001 From: nemsia Date: Tue, 12 Jun 2018 18:32:43 +0200 Subject: 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 (limited to 'scripts/backup') 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 -#================================================= -# TODO TODO TODO +# INSTALL DEPENDENCIES #================================================= -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 22:53:03 +0200 Subject: 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(-) (limited to 'scripts/backup') 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 -- cgit v1.2.3-70-g09d2 From d592fe5cac9722ab931960bf9e95785d1e55f083 Mon Sep 17 00:00:00 2001 From: nemsia Date: Thu, 14 Jun 2018 15:19:48 +0200 Subject: 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 (limited to 'scripts/backup') 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 #================================================= -- cgit v1.2.3-70-g09d2