mirror of
https://github.com/YunoHost-Apps/mastodon_ynh.git
synced 2024-09-03 19:46:02 +02:00
ba3ce5d001
* upgrade-2.3.3 upgrade-2.3.3 git fetch with all tags forced * Upgrade 2.4.0 (#21) * Upgrade 2.4 (#79) * Upgrade rb to 2.5.1 * Update upgrade * Fix 2.3.3 * Add trace on assets:precompile * Yarn install and precompile Update 2.4 need root to yarn install and precompile, Temporary bad fix. * Update upgrade * Fix migrate * Update README.md * Update manifest.json * Upgrade yarn to 1.7.0 * Restart postgresql on upgrade * Ready to Debian Stretch (#22) * Ready to Debian Stretch * rb 2.5.1 on install * Yarn install on root * rails precompile fix * Fix backup on stretch * clean * fix backup stretch * Change systemd mastodon service restart * Change systemd script for stretch * Ready to mastodon 2.4.1 * Fix migrated stretch (#23) * Force bundle re-install * Add check debian on upgrade and clean check
207 lines
6.8 KiB
Bash
207 lines
6.8 KiB
Bash
#!/bin/bash
|
|
# This restore script is adapted to Yunohost >=2.4
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
set -eu
|
|
|
|
if [ ! -e .fonctions ]; then
|
|
# Get file fonction if not been to the current directory
|
|
sudo cp ../settings/scripts/.fonctions ./.fonctions
|
|
sudo chmod a+rx .fonctions
|
|
fi
|
|
# Loads the generic functions usually used in the script
|
|
source .fonctions
|
|
# Source app helpers
|
|
source /usr/share/yunohost/helpers
|
|
|
|
# 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)
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
# Check domain/path availability
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
|
|
|
# Check $final_path
|
|
final_path="/opt/${app}"
|
|
if [ -d $final_path ]; then
|
|
ynh_die "There is already a directory: $final_path"
|
|
fi
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
# Create user unix
|
|
sudo adduser $app --home /opt/$app --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password --disabled-login
|
|
|
|
# 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 libicu-dev libidn11-dev
|
|
|
|
# Install redis package
|
|
ynh_package_install redis-server redis-tools
|
|
|
|
# Install postgresql
|
|
ynh_package_install postgresql postgresql-contrib postgresql-server-dev-all
|
|
|
|
# Install Ruby
|
|
ynh_package_install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
|
|
|
|
# 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
|
|
fi
|
|
|
|
# Install source.list debian yarn package
|
|
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
|
|
|
|
# Install source.list debian jessie package backports
|
|
if [ "$(lsb_release --codename --short)" == "jessie" ]; then
|
|
sudo cp ./apt_backports.list /etc/apt/sources.list.d/backports.list
|
|
ynh_package_update
|
|
sudo apt-get -t jessie-backports -y install ffmpeg
|
|
else
|
|
ynh_package_update
|
|
ynh_package_install ffmpeg
|
|
fi
|
|
|
|
# Install Yarn
|
|
ynh_package_install yarn
|
|
|
|
# Install de Node.js
|
|
pushd /opt
|
|
curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
|
|
sudo apt-get -y install nodejs
|
|
popd
|
|
|
|
# Restore sources & data
|
|
sudo cp -a ./sources/. "$final_path"
|
|
|
|
# Set permissions
|
|
sudo chown -R $app: "$final_path"
|
|
|
|
# Debug
|
|
sudo ls -alh "$final_path"
|
|
|
|
# Restart postgresql
|
|
sudo systemctl restart postgresql
|
|
|
|
# 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';"
|
|
|
|
# Install rbenv
|
|
sudo su - $app <<COMMANDS
|
|
pushd ~/.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
|
|
COMMANDS
|
|
|
|
# Create user for db postgresql
|
|
ynh_psql_create_db_without_password "$app"
|
|
|
|
# Setup database
|
|
#sudo su - $app <<SCOMMANDS
|
|
#cd ~/live
|
|
#RAILS_ENV=production bin/bundle exec rails db:setup
|
|
#SCOMMANDS
|
|
|
|
# copy database dump
|
|
sudo cp $YNH_APP_BACKUP_DIR/mastodon_db.sql $final_path
|
|
sudo chmod a+r $final_path/mastodon_db.sql
|
|
|
|
# Restore database dump
|
|
sudo su - $app <<RECOMMANDS
|
|
dropdb mastodon_production
|
|
createdb mastodon_production
|
|
psql mastodon_production < $final_path/mastodon_db.sql
|
|
RECOMMANDS
|
|
|
|
# Remove dump
|
|
ynh_secure_remove $final_path/mastodon_db.sql
|
|
|
|
# Create symlink for ruby 2.5.1
|
|
sudo rm /usr/bin/ruby || true
|
|
sudo ln -s /opt/mastodon/.rbenv/versions/2.5.1/bin/ruby /usr/bin/ruby || true
|
|
|
|
# Install Mastodon
|
|
sudo su - $app <<MCOMMANDS
|
|
pushd ~/live
|
|
$final_path/.rbenv/versions/2.5.1/bin/gem install bundler
|
|
$final_path/.rbenv/versions/2.5.1/bin/bundle install --deployment --without development test
|
|
MCOMMANDS
|
|
|
|
pushd $final_path/live
|
|
yarn install --pure-lockfile
|
|
systemctl restart postgresql
|
|
popd
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
sudo sed -i "s@__PATH__@$app@g" ./nginx.conf
|
|
sudo sed -i "s@__FINALPATH__@$final_path@g" ./nginx.conf
|
|
sudo cp -a ./nginx.conf "$nginx_conf"
|
|
# Restore crontab
|
|
sudo cp -a ./cron.conf "$crontab_conf"
|
|
|
|
sudo cp ./systemd_web.service /etc/systemd/system/mastodon-web.service
|
|
sudo chown root: /etc/systemd/system/mastodon-web.service
|
|
sudo cp ./systemd_sidekiq.service /etc/systemd/system/mastodon-sidekiq.service
|
|
sudo chown root: /etc/systemd/system/mastodon-sidekiq.service
|
|
sudo cp ./systemd_streaming.service /etc/systemd/system/mastodon-streaming.service
|
|
sudo chown root: /etc/systemd/system/mastodon-streaming.service
|
|
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service
|
|
sudo systemctl start mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service
|
|
# debug
|
|
sudo systemctl status mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service
|
|
|
|
# Add service YunoHost
|
|
sudo yunohost service add mastodon-web
|
|
sudo yunohost service add mastodon-sidekiq
|
|
sudo yunohost service add mastodon-streaming
|
|
|
|
# Reload services
|
|
sudo systemctl reload nginx
|