mirror of
https://github.com/YunoHost-Apps/snweb_ynh.git
synced 2024-09-03 20:26:22 +02:00
Upgrade to 3.5.11, Optimations
This commit is contained in:
parent
cd1235a55a
commit
c369ecdd74
9 changed files with 135 additions and 545 deletions
|
@ -1,5 +1,5 @@
|
|||
SOURCE_URL=https://github.com/standardnotes/web/archive/3.0.14.tar.gz
|
||||
SOURCE_SUM=6f9884772c77c84a7ad764a036784796425cecdedb6cf7a8cb37358889dcc26a
|
||||
SOURCE_URL=https://github.com/standardnotes/web/archive/3.5.11.tar.gz
|
||||
SOURCE_SUM=6f3cbc638c9ba357696da52be2b9cbfadcc1d0b75d62355b182047b527086b09
|
||||
SOURCE_SUM_PRG=sha256sum
|
||||
SOURCE_FORMAT=tar.gz
|
||||
SOURCE_IN_SUBDIR=true
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
|
||||
# Rails Settings
|
||||
RAILS_ENV=__RAILS_ENV__
|
||||
EXPOSED_PORT=__EXPOSED_PORT__
|
||||
SECRET_KEY_BASE=__SECRET_KEY__
|
||||
RAILS_ENV=development
|
||||
PORT=3001
|
||||
WEB_CONCURRENCY=0
|
||||
RAILS_LOG_TO_STDOUT=true
|
||||
RAILS_SERVE_STATIC_FILES=true
|
||||
SECRET_KEY_BASE=test
|
||||
APP_HOST=http://localhost:3001
|
||||
|
||||
# Extensions Settings
|
||||
EXTENSIONS_MANAGER_LOCATION=__EXTENSIONS_MANAGER_LOCATION__
|
||||
BATCH_MANAGER_LOCATION=__BATCH_MANAGER_LOCATION__
|
||||
EXTENSIONS_MANAGER_LOCATION=extensions/extensions-manager/dist/index.html
|
||||
BATCH_MANAGER_LOCATION=extensions/batch-manager/dist/index.min.html
|
||||
SF_DEFAULT_SERVER=http://localhost:3000
|
||||
|
||||
SF_DEFAULT_SERVER=__SF_DEFAULT_SERVER__
|
||||
# Datadog
|
||||
DATADOG_ENABLED=false
|
||||
|
||||
# Development options
|
||||
DEV_DEFAULT_SYNC_SERVER=https://sync.standardnotes.org
|
||||
DEV_EXTENSIONS_MANAGER_LOCATION=public/extensions/extensions-manager/dist/index.html
|
||||
DEV_BATCH_MANAGER_LOCATION=public/extensions/batch-manager/dist/index.min.html
|
||||
|
|
|
@ -1,28 +1,19 @@
|
|||
[Unit]
|
||||
Description=__APP__ service
|
||||
Description=__APP__
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=__APP__
|
||||
Group=__APP__
|
||||
WorkingDirectory=__FINALPATH__/live
|
||||
Environment=RAILS_ENV=production
|
||||
Environment="PORT=__PORT_WEB__"
|
||||
#ExecStart=/opt/yunohost/snserver/rails s >> /var/log/snserver/snserver.log 2>&1
|
||||
#ExecStart=__FINALPATH__/bin/rails s -e production >> /var/log/__APP__/__APP__.log 2>&1
|
||||
#ExecStart=/opt/rbenv/versions/2.6.5/bin/bundle exec puma -C config/puma.rb
|
||||
#ExecStart=/opt/rbenv/versions/2.6.5/bin/rails s -b 0.0.0.0 >> /var/log/__APP__/__APP__.log 2>&1
|
||||
ExecStart=/opt/rbenv/versions/2.6.5/bin/rails s -b 0.0.0.0
|
||||
ExecReload=/bin/kill -SIGUSR1 $MAINPID
|
||||
StandardError=syslog
|
||||
EnvironmentFile=__FINALPATH__/live/.env
|
||||
Environment=__ENV_PATH__
|
||||
WorkingDirectory=__FINALPATH__/live/
|
||||
ExecStart=/opt/rbenv/versions/__RUBY_VERSION__/bin/bundle exec puma -C config/puma.rb -p __PORT__ -e production
|
||||
StandardOutput=append:/var/log/__APP__/snweb.log
|
||||
StandardError=append:/var/log/__APP__/snweb.log
|
||||
SyslogIdentifier=__APP__
|
||||
Restart=always
|
||||
RestartSec=15
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -71,18 +71,16 @@
|
|||
"fr": "Choisissez la langue de l'application",
|
||||
"de": "Wähle die Application Sprache"
|
||||
},
|
||||
"choices": ["en", "fr", "de"],
|
||||
"default": "en"
|
||||
},
|
||||
{
|
||||
"name": "server_domain",
|
||||
"name": "snserver_domain",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "Choose a server domain name for snweb",
|
||||
"fr": "Choisissez un server domaine pour snweb",
|
||||
"de": "Wähle einen Server Domain Namen für snweb"
|
||||
"en": "Choose the default Standard Notes Syncing Server",
|
||||
"de": "Wähle den Standard Notes Syncing Server"
|
||||
},
|
||||
"example": "sync.standardnotes.org"
|
||||
"default": "sync.standardnotes.org"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -5,10 +5,19 @@
|
|||
#=================================================
|
||||
|
||||
# dependencies used by the app
|
||||
#pkg_dependencies="ruby ruby-dev rails zlib1g-dev libsqlite3-dev default-libmysqlclient-dev libssl-dev libreadline-dev"
|
||||
#pkg_dependencies=" zlib1g-dev libsqlite3-dev default-libmysqlclient-dev libssl-dev libreadline-dev"
|
||||
#pkg_dependencies="libssl-dev libreadline-dev zlib1g-dev"
|
||||
pkg_dependencies="git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev"
|
||||
#pkg_dependencies="libsqlite3-dev default-libmysqlclient-dev"
|
||||
pkg_dependencies="\
|
||||
zlib1g-dev \
|
||||
libssl-dev \
|
||||
libjemalloc-dev \
|
||||
git \
|
||||
"
|
||||
|
||||
RUBY_VERSION="2.7.2"
|
||||
NODEJS_VERSION="10"
|
||||
|
||||
SOURCE="https://github.com/standardnotes/web"
|
||||
COMMIT="31676f1cc61898147b363d442593870ae880d3e5"
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
|
@ -17,14 +26,14 @@ pkg_dependencies="git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison
|
|||
# Execute a command as another user with login
|
||||
# (hence in user home dir, with prior loading of .profile, etc.)
|
||||
# usage: exec_login_as USER COMMAND [ARG ...]
|
||||
ynh_exec_login_as() {
|
||||
exec_login_as() {
|
||||
local user=$1
|
||||
shift 1
|
||||
exec_as $user --login "$@"
|
||||
}
|
||||
# Execute a command as another user
|
||||
# usage: exec_as USER COMMAND [ARG ...]
|
||||
ynh_exec_as() {
|
||||
exec_as() {
|
||||
local user=$1
|
||||
shift 1
|
||||
|
||||
|
|
283
scripts/install
Executable file → Normal file
283
scripts/install
Executable file → Normal file
|
@ -7,8 +7,7 @@
|
|||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source ynh_install_ruby__2
|
||||
source ynh_add_extra_apt_repos__3
|
||||
source ynh_install_ruby
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -26,327 +25,215 @@ ynh_abort_if_errors
|
|||
#=================================================
|
||||
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
#path_url=$YNH_APP_ARG_PATH
|
||||
path_url="/"
|
||||
admin=$YNH_APP_ARG_ADMIN
|
||||
path_url=$YNH_APP_ARG_PATH
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
language=$YNH_APP_ARG_LANGUAGE
|
||||
admin_mail=$(ynh_user_get_info $admin 'mail')
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
server_domain=$YNH_APP_ARG_SERVER_DOMAIN
|
||||
snserver_domain=$YNH_APP_ARG_SNSERVER_DOMAIN
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
### About --weight and --time
|
||||
### ynh_script_progression will show to your final users the progression of each scripts.
|
||||
### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script.
|
||||
### --time is a packager option, it will show you the execution time since the previous call.
|
||||
### This option should be removed before releasing your app.
|
||||
### Use the execution time, given by --time, to estimate the weight of a step.
|
||||
### A common way to do it is to set a weight equal to the execution time in second +1.
|
||||
### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
|
||||
ynh_script_progression --message="Validating installation parameters..." --time --weight=2
|
||||
ynh_script_progression --message="Validating installation parameters..."
|
||||
|
||||
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
|
||||
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
|
||||
final_path=/var/www/$app
|
||||
#final_path=/opt/yunohost/$app
|
||||
final_path=/opt/yunohost/$app
|
||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||
|
||||
mkdir -p "$final_path/live"
|
||||
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
|
||||
# Register (book) web path
|
||||
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
||||
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Storing installation settings..." --time --weight=2
|
||||
ynh_script_progression --message="Storing installation settings..."
|
||||
|
||||
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
||||
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
||||
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
||||
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
||||
ynh_app_setting_set --app=$app --key=language --value=$language
|
||||
ynh_app_setting_set --app=$app --key=snserver_domain --value=$snserver_domain
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# FIND AND OPEN A PORT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring firewall..." --time --weight=1
|
||||
|
||||
### Use these lines if you have to open a port for the application
|
||||
### `ynh_find_port` will find the first available port starting from the given port.
|
||||
### If you're not using these lines:
|
||||
### - Remove the section "CLOSE A PORT" in the remove script
|
||||
ynh_script_progression --message="Configuring firewall..."
|
||||
|
||||
# Find an available port
|
||||
port_web=$(ynh_find_port --port=3000)
|
||||
# Open the port
|
||||
ynh_app_setting_set --app=$app --key=port_web --value=$port_web
|
||||
|
||||
# Optional: Expose this port publicly
|
||||
# (N.B. : you only need to do this if the app actually needs to expose the port publicly.
|
||||
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
|
||||
|
||||
# Open the port
|
||||
# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
|
||||
port=$(ynh_find_port --port=3000)
|
||||
ynh_app_setting_set --app=$app --key=port --value=$port
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..." --time --weight=7
|
||||
ynh_script_progression --message="Installing dependencies..."
|
||||
|
||||
### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
|
||||
### Those deb packages will be installed as dependencies of this package.
|
||||
### If you're not using this helper:
|
||||
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
|
||||
### - Remove the variable "pkg_dependencies" in _common.sh
|
||||
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
|
||||
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
|
||||
|
||||
ynh_install_nodejs --nodejs_version="8"
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
||||
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
|
||||
|
||||
#=================================================
|
||||
# CREATE A MYSQL DATABASE
|
||||
#=================================================
|
||||
#ynh_script_progression --message="Creating a MySQL database..." --time ---weight=2
|
||||
|
||||
### Use these lines if you need a database for the application.
|
||||
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
|
||||
### The password will be stored as 'mysqlpwd' into the app settings,
|
||||
### and will be available as $db_pwd
|
||||
### If you're not using these lines:
|
||||
### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script
|
||||
### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script
|
||||
### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script
|
||||
|
||||
#db_name=$(ynh_sanitize_dbid --db_name=$app)
|
||||
#db_user=$db_name
|
||||
#ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
||||
#ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up source files..." --time --weight=2
|
||||
ynh_script_progression --message="Setting up source files..."
|
||||
|
||||
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
|
||||
### downloaded from an upstream source, like a git repository.
|
||||
### `ynh_setup_source` use the file conf/app.src
|
||||
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
mkdir $final_path
|
||||
ynh_setup_source --dest_dir="$final_path/live"
|
||||
git clone $SOURCE "$final_path/live" --quiet
|
||||
pushd "$final_path/live"
|
||||
git checkout $COMMIT --quiet
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring nginx web server..." --time --weight=2
|
||||
|
||||
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
||||
ynh_replace_string --match_string="__PORT__" --replace_string="$port_web" --target_file="../conf/nginx.conf"
|
||||
ynh_script_progression --message="Configuring nginx web server..."
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
ynh_add_nginx_config "port"
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring system user..." --time --weight=2
|
||||
ynh_script_progression --message="Configuring system user..."
|
||||
|
||||
# Create a system user
|
||||
#ynh_system_user_create --username=$app
|
||||
# Create a system user allowing login
|
||||
ynh_system_user_create $app $final_path 1
|
||||
# Create a system user
|
||||
#ynh_system_user_create --username=$app --home_dir=$final_path
|
||||
|
||||
ynh_system_user_create --username=$app --home_dir=$final_path
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
# INSTALLING RUBY AND BUNDLER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing Ruby..." --time --weight=321
|
||||
ynh_script_progression --message="Installing Ruby..." --weight=331
|
||||
|
||||
ruby_version="2.6.5"
|
||||
ynh_install_ruby --ruby_version=$ruby_version
|
||||
|
||||
/opt/rbenv/versions/$ruby_version/bin/gem update --system
|
||||
/opt/rbenv/versions/$ruby_version/bin/gem install bundler:1.17.1 --no-document
|
||||
/opt/rbenv/versions/$ruby_version/bin/gem install bundle --no-document
|
||||
/opt/rbenv/versions/$ruby_version/bin/gem install rails --no-document
|
||||
/opt/rbenv/versions/$ruby_version/bin/gem install haml --no-document
|
||||
/opt/rbenv/versions/$ruby_version/bin/gem install sass --no-document
|
||||
ynh_install_ruby --ruby_version=$RUBY_VERSION
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Modifying a config file..." --time --weight=2
|
||||
### `ynh_replace_string` is used to replace a string in a file.
|
||||
### (It's compatible with sed regular expressions syntax)
|
||||
|
||||
config_file="$final_path/live/.env"
|
||||
cp -f ../conf/env.sample $config_file
|
||||
|
||||
cp -f ../conf/env.sample "$final_path/live/.env.production"
|
||||
config_file="$final_path/live/.env.production"
|
||||
|
||||
ynh_replace_string --match_string="__EXPOSED_PORT__" --replace_string="$port_web" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="RAILS_ENV=development" --replace_string="RAILS_ENV=production" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="PORT=3001" --replace_string="PORT=$port" --target_file="$config_file"
|
||||
secret_key=$(ynh_string_random --length=48 | base64)
|
||||
ynh_replace_string --match_string="__SECRET_KEY__" --replace_string="$secret_key" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__RAILS_ENV__" --replace_string="production" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__EXTENSIONS_MANAGER_LOCATION__" --replace_string="extensions/extensions-manager/dist/index.html" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__BATCH_MANAGER_LOCATION__" --replace_string="extensions/batch-manager/dist/index.min.html" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="__SF_DEFAULT_SERVER__" --replace_string="https://$server_domain" --target_file="$config_file"
|
||||
ynh_replace_string --match_string="SECRET_KEY_BASE=test" --replace_string="SECRET_KEY_BASE=$secret_key" --target_file="$config_file"
|
||||
|
||||
|
||||
if [ "$snserver_domain" = "" ]; then
|
||||
snserver_domain="sync.standardnotes.org"
|
||||
fi
|
||||
ynh_replace_string --match_string="SF_DEFAULT_SERVER=http://localhost:3000" --replace_string="SF_DEFAULT_SERVER=https://$snserver_domain" --target_file="$config_file"
|
||||
|
||||
#=================================================
|
||||
# INSTALLING Standard Notes - Synicing Server
|
||||
# BUILDING
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing Standard Notes - Synicing Server..." --time --weight=153
|
||||
ynh_script_progression --message="Building..."
|
||||
|
||||
chown -R "$app": "$final_path"
|
||||
ENV_PATH="$ynh_node_load_PATH:/opt/rbenv/versions/$RUBY_VERSION/bin"
|
||||
|
||||
chown -R $app: "$final_path"
|
||||
|
||||
pushd "$final_path/live"
|
||||
ynh_use_nodejs
|
||||
ynh_exec_as "$app" env "PATH=$PATH" /opt/rbenv/versions/$ruby_version/bin/bundle install --path "vendor/bundle"
|
||||
ynh_exec_as "$app" env "PATH=$PATH:/opt/rbenv/versions/$ruby_version/bin:/var/www/snweb/live/vendor/bundle:/var/www/snweb/live/bin:$nodejs_path" yarn run build
|
||||
ynh_exec_as "$app" env "PATH=$PATH" /opt/rbenv/versions/$ruby_version/bin/rails assets:precompile
|
||||
#exec_as $app $ENV_PATH $ynh_npm run setup
|
||||
exec_as $app $ENV_PATH $ynh_npm ci
|
||||
env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/gem install bundler
|
||||
env PATH=$ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundler install
|
||||
exec_as $app $ENV_PATH $ynh_npm run bundle
|
||||
exec_as $app $ENV_PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring a systemd service..." --time --weight=2
|
||||
ynh_script_progression --message="Configuring a systemd service..."
|
||||
|
||||
### `ynh_systemd_config` is used to configure a systemd script for an app.
|
||||
### It can be used for apps that use sysvinit (with adaptation) or systemd.
|
||||
### Have a look at the app to be sure this app needs a systemd script.
|
||||
### `ynh_systemd_config` will use the file conf/systemd.service
|
||||
### If you're not using these lines:
|
||||
### - You can remove those files in conf/.
|
||||
### - Remove the section "BACKUP SYSTEMD" in the backup script
|
||||
### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script
|
||||
### - As well as the section "RESTORE SYSTEMD" in the restore script
|
||||
### - And the section "SETUP SYSTEMD" in the upgrade script
|
||||
|
||||
# Create a dedicated systemd config
|
||||
#ynh_add_systemd_config
|
||||
ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/systemd.service"
|
||||
ynh_add_systemd_config --service="$app" --template="systemd.service"
|
||||
ynh_add_systemd_config --others_var="\
|
||||
port \
|
||||
ENV_PATH \
|
||||
RUBY_VERSION \
|
||||
"
|
||||
|
||||
#=================================================
|
||||
# STORE THE CONFIG FILE CHECKSUM
|
||||
#=================================================
|
||||
|
||||
### `ynh_store_file_checksum` is used to store the checksum of a file.
|
||||
### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`,
|
||||
### you can make a backup of this file before modifying it again if the admin had modified it.
|
||||
ynh_script_progression --message="Storing the config file checksum..."
|
||||
|
||||
# Calculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum --file="$config_file"
|
||||
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Securing files and directories..." --time --weight=1
|
||||
### For security reason, any app should set the permissions to root: before anything else.
|
||||
### Then, if write authorization is needed, any access should be given only to directories
|
||||
### that really need such authorization.
|
||||
ynh_script_progression --message="Securing files and directories..."
|
||||
|
||||
# Set permissions to app files
|
||||
chown -R root: $final_path
|
||||
chown $app: $final_path
|
||||
chown $app: $final_path/live/
|
||||
chown -R $app: $final_path/live/log/
|
||||
chown -R $app: $final_path/live/tmp/
|
||||
chown -R root:root "$final_path"
|
||||
chown $app: "$final_path"
|
||||
mkdir -p $app: "$final_path/.config"
|
||||
chown $app: "$final_path/.config"
|
||||
mkdir -p "$final_path/live/log"
|
||||
chown -R $app: "$final_path/live/log"
|
||||
mkdir -p "$final_path/live/public"
|
||||
chown -R $app: "$final_path/live/public"
|
||||
mkdir -p "$final_path/live/tmp"
|
||||
chown -R $app: "$final_path/live/tmp"
|
||||
chown $app: "$final_path/live/Gemfile.lock"
|
||||
|
||||
mkdir -p "/var/log/$app"
|
||||
chown -R $app: "/var/log/$app"
|
||||
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring log rotation..." --time --weight=2
|
||||
|
||||
### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
|
||||
### Use this helper only if there is effectively a log file for this app.
|
||||
### If you're not using this helper:
|
||||
### - Remove the section "BACKUP LOGROTATE" in the backup script
|
||||
### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
|
||||
### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
|
||||
### - And the section "SETUP LOGROTATE" in the upgrade script
|
||||
ynh_script_progression --message="Configuring log rotation..."
|
||||
|
||||
# Use logrotate to manage application logfile(s)
|
||||
ynh_use_logrotate
|
||||
ynh_use_logrotate --logfile="$final_path/live/log/production.log"
|
||||
ynh_use_logrotate --logfile="/var/log/$app/snweb.log"
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrate service in admin panel..." --time --weight=3
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
|
||||
### `yunohost service add` integrates a service in YunoHost. It then gets
|
||||
### displayed in the admin interface and through the others `yunohost service` commands.
|
||||
### (N.B. : this line only makes sense if the app adds a service to the system!)
|
||||
### If you're not using these lines:
|
||||
### - You can remove these files in conf/.
|
||||
### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script
|
||||
### - As well as the section "ADVERTISE SERVICE IN ADMIN PANEL" in the restore script
|
||||
|
||||
yunohost service add $app --description "Standard Notes - Syncing Server"
|
||||
|
||||
### With YunoHost 3.8 you will then be able to:
|
||||
### - specify a list of ports that needs to be publicly exposed (c.f. --needs_exposed_ports)
|
||||
### which will then be checked by YunoHost's diagnosis system
|
||||
### - specify a custom command to check the status of the service (c.f. --test_status)
|
||||
### though it's only needed for weird cases where 'systemctl status' doesn't do a good job
|
||||
### - specify a custom command to check / validate the configuration of the service (c.f. --test_conf)
|
||||
### for example, the command to check the configuration of nginx is "nginx -t"
|
||||
yunohost service add $app --description "Standard Notes - Web Frontend"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
|
||||
|
||||
### `ynh_systemd_action` is used to start a systemd service for an app.
|
||||
### Only needed if you have configure a systemd service
|
||||
### If you're not using these lines:
|
||||
### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script
|
||||
### - As well as the section "START SYSTEMD SERVICE" in the restore script
|
||||
### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script
|
||||
### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script
|
||||
ynh_script_progression --message="Starting a systemd service..."
|
||||
|
||||
# Start a systemd service
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
# SETUP FAIL2BAN
|
||||
#=================================================
|
||||
#ynh_script_progression --message="Configuring fail2ban..." --time --weight=1
|
||||
|
||||
# Create a dedicated fail2ban config
|
||||
#ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
|
||||
ynh_systemd_action --service_name=$app --action="start"
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
|
||||
ynh_script_progression --message="Configuring SSOwat..."
|
||||
|
||||
# Make app public if necessary
|
||||
if [ $is_public -eq 1 ]
|
||||
then
|
||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
||||
# Create the visitors permission if needed
|
||||
ynh_permission_update --permission "main" --add "visitors"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
||||
ynh_script_progression --message="Reloading nginx web server..."
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
|
@ -354,5 +241,7 @@ ynh_systemd_action --service_name=nginx --action=reload
|
|||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Installation of $app completed" --time --last
|
||||
ynh_script_progression --message="Installation of $app completed"
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source ynh_install_ruby__2
|
||||
source ynh_install_ruby
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -18,9 +18,7 @@ ynh_script_progression --message="Loading installation settings..." --time --wei
|
|||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
port_web=$(ynh_app_setting_get --app=$app --key=port_web)
|
||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
db_user=$db_name
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
|
@ -44,14 +42,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..."
|
|||
# Remove the dedicated systemd config
|
||||
ynh_remove_systemd_config --service="$app"
|
||||
|
||||
#=================================================
|
||||
# REMOVE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
#ynh_script_progression --message="Removing the MySQL database..." --time --weight=1
|
||||
|
||||
# Remove a database if it exists, along with the associated user
|
||||
#ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
|
|
|
@ -1,294 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Pin a repository.
|
||||
#
|
||||
# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append]
|
||||
# | arg: -p, --package - Packages concerned by the pin. Or all, *.
|
||||
# | arg: -i, --pin - Filter for the pin.
|
||||
# | arg: -p, --priority - Priority for the pin
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -a, --append - Do not overwrite existing files.
|
||||
#
|
||||
# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning.
|
||||
#
|
||||
ynh_pin_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pirna
|
||||
declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append )
|
||||
local package
|
||||
local pin
|
||||
local priority
|
||||
local name
|
||||
local append
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
package="${package:-*}"
|
||||
priority=${priority:-50}
|
||||
name="${name:-$app}"
|
||||
append=${append:-0}
|
||||
|
||||
if [ $append -eq 1 ]
|
||||
then
|
||||
append="tee -a"
|
||||
else
|
||||
append="tee"
|
||||
fi
|
||||
|
||||
mkdir -p "/etc/apt/preferences.d"
|
||||
echo "Package: $package
|
||||
Pin: $pin
|
||||
Pin-Priority: $priority" \
|
||||
| $append "/etc/apt/preferences.d/$name"
|
||||
}
|
||||
|
||||
# Add a repository.
|
||||
#
|
||||
# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append]
|
||||
# | arg: -u, --uri - Uri of the repository.
|
||||
# | arg: -s, --suite - Suite of the repository.
|
||||
# | arg: -c, --component - Component of the repository.
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -a, --append - Do not overwrite existing files.
|
||||
#
|
||||
# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable
|
||||
# uri suite component
|
||||
# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable
|
||||
#
|
||||
ynh_add_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=uscna
|
||||
declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append )
|
||||
local uri
|
||||
local suite
|
||||
local component
|
||||
local name
|
||||
local append
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
name="${name:-$app}"
|
||||
append=${append:-0}
|
||||
|
||||
if [ $append -eq 1 ]
|
||||
then
|
||||
append="tee -a"
|
||||
else
|
||||
append="tee"
|
||||
fi
|
||||
|
||||
mkdir -p "/etc/apt/sources.list.d"
|
||||
# Add the new repo in sources.list.d
|
||||
echo "deb $uri $suite $component" \
|
||||
| $append "/etc/apt/sources.list.d/$name.list"
|
||||
}
|
||||
|
||||
# Add an extra repository correctly, pin it and get the key.
|
||||
#
|
||||
# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append]
|
||||
# | arg: -r, --repo - Complete url of the extra repository.
|
||||
# | arg: -k, --key - url to get the public key.
|
||||
# | arg: -p, --priority - Priority for the pin
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
# | arg: -a, --append - Do not overwrite existing files.
|
||||
ynh_install_extra_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=rkpna
|
||||
declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append )
|
||||
local repo
|
||||
local key
|
||||
local priority
|
||||
local name
|
||||
local append
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
name="${name:-$app}"
|
||||
append=${append:-0}
|
||||
key=${key:-0}
|
||||
priority=${priority:-}
|
||||
|
||||
if [ $append -eq 1 ]
|
||||
then
|
||||
append="--append"
|
||||
wget_append="tee -a"
|
||||
else
|
||||
append=""
|
||||
wget_append="tee"
|
||||
fi
|
||||
|
||||
# Split the repository into uri, suite and components.
|
||||
# Remove "deb " at the beginning of the repo.
|
||||
repo="${repo#deb }"
|
||||
|
||||
# Get the uri
|
||||
local uri="$(echo "$repo" | awk '{ print $1 }')"
|
||||
|
||||
# Get the suite
|
||||
local suite="$(echo "$repo" | awk '{ print $2 }')"
|
||||
|
||||
# Get the components
|
||||
local component="${repo##$uri $suite }"
|
||||
|
||||
# Add the repository into sources.list.d
|
||||
ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append
|
||||
|
||||
# Pin the new repo with the default priority, so it won't be used for upgrades.
|
||||
# Build $pin from the uri without http and any sub path
|
||||
local pin="${uri#*://}"
|
||||
pin="${pin%%/*}"
|
||||
# Set a priority only if asked
|
||||
if [ -n "$priority" ]
|
||||
then
|
||||
priority="--priority=$priority"
|
||||
fi
|
||||
ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append
|
||||
|
||||
# Get the public key for the repo
|
||||
if [ -n "$key" ]
|
||||
then
|
||||
mkdir -p "/etc/apt/trusted.gpg.d"
|
||||
wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null
|
||||
fi
|
||||
|
||||
# Update the list of package with the new repo
|
||||
ynh_package_update
|
||||
}
|
||||
|
||||
# Remove an extra repository and the assiociated configuration.
|
||||
#
|
||||
# usage: ynh_remove_extra_repo [--name=name]
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
ynh_remove_extra_repo () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=n
|
||||
declare -Ar args_array=( [n]=name= )
|
||||
local name
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
name="${name:-$app}"
|
||||
|
||||
ynh_secure_remove "/etc/apt/sources.list.d/$name.list"
|
||||
ynh_secure_remove "/etc/apt/preferences.d/$name"
|
||||
ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg"
|
||||
ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc"
|
||||
|
||||
# Update the list of package to exclude the old repo
|
||||
ynh_package_update
|
||||
}
|
||||
|
||||
# Install packages from an extra repository properly.
|
||||
#
|
||||
# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name]
|
||||
# | arg: -r, --repo - Complete url of the extra repository.
|
||||
# | arg: -p, --package - The packages to install from this extra repository
|
||||
# | arg: -k, --key - url to get the public key.
|
||||
# | arg: -n, --name - Name for the files for this repo, $app as default value.
|
||||
ynh_install_extra_app_dependencies () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=rpkn
|
||||
declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= )
|
||||
local repo
|
||||
local package
|
||||
local key
|
||||
local name
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
name="${name:-$app}"
|
||||
key=${key:-0}
|
||||
|
||||
# Set a key only if asked
|
||||
if [ -n "$key" ]
|
||||
then
|
||||
key="--key=$key"
|
||||
fi
|
||||
# Add an extra repository for those packages
|
||||
ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name
|
||||
|
||||
# Install requested dependencies from this extra repository.
|
||||
ynh_add_app_dependencies --package="$package"
|
||||
|
||||
# Remove this extra repository after packages are installed
|
||||
ynh_remove_extra_repo --name=$app
|
||||
}
|
||||
|
||||
#=================================================
|
||||
|
||||
# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies
|
||||
|
||||
# Define and install dependencies with a equivs control file
|
||||
# This helper can/should only be called once per app
|
||||
#
|
||||
# usage: ynh_install_app_dependencies dep [dep [...]]
|
||||
# | arg: dep - the package name to install in dependence
|
||||
# You can give a choice between some package with this syntax : "dep1|dep2"
|
||||
# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5"
|
||||
# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5)
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_install_app_dependencies () {
|
||||
local dependencies=$@
|
||||
dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')"
|
||||
dependencies=${dependencies//|/ | }
|
||||
local manifest_path="../manifest.json"
|
||||
if [ ! -e "$manifest_path" ]; then
|
||||
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
||||
fi
|
||||
|
||||
local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file.
|
||||
if [ ${#version} -eq 0 ]; then
|
||||
version="1.0"
|
||||
fi
|
||||
local dep_app=${app//_/-} # Replace all '_' by '-'
|
||||
|
||||
# Handle specific versions
|
||||
if [[ "$dependencies" =~ [\<=\>] ]]
|
||||
then
|
||||
# Replace version specifications by relationships syntax
|
||||
# https://www.debian.org/doc/debian-policy/ch-relationships.html
|
||||
# Sed clarification
|
||||
# [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice.
|
||||
# [\<=\>] matches < = or >
|
||||
# \+ matches one or more occurence of the previous characters, for >= or >>.
|
||||
# [^,]\+ matches all characters except ','
|
||||
# Ex: package>=1.0 will be replaced by package (>= 1.0)
|
||||
dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')"
|
||||
fi
|
||||
|
||||
cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
|
||||
Section: misc
|
||||
Priority: optional
|
||||
Package: ${dep_app}-ynh-deps
|
||||
Version: ${version}
|
||||
Depends: ${dependencies}
|
||||
Architecture: all
|
||||
Description: Fake package for $app (YunoHost app) dependencies
|
||||
This meta-package is only responsible of installing its dependencies.
|
||||
EOF
|
||||
ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \
|
||||
|| ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies
|
||||
rm /tmp/${dep_app}-ynh-deps.control
|
||||
ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies"
|
||||
}
|
||||
|
||||
ynh_add_app_dependencies () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=pr
|
||||
declare -Ar args_array=( [p]=package= [r]=replace)
|
||||
local package
|
||||
local replace
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
replace=${replace:-0}
|
||||
|
||||
local current_dependencies=""
|
||||
if [ $replace -eq 0 ]
|
||||
then
|
||||
local dep_app=${app//_/-} # Replace all '_' by '-'
|
||||
if ynh_package_is_installed --package="${dep_app}-ynh-deps"
|
||||
then
|
||||
current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) "
|
||||
fi
|
||||
|
||||
current_dependencies=${current_dependencies// | /|}
|
||||
fi
|
||||
|
||||
ynh_install_app_dependencies "${current_dependencies}${package}"
|
||||
}
|
|
@ -22,8 +22,8 @@ SOURCE_SUM=80ad89ffe04c0b481503bd375f05c212bbc7d44ef5f5e649e0acdf25eba86736" > "
|
|||
|
||||
# Build an app.src for ruby-build
|
||||
mkdir -p "../conf"
|
||||
echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20191004.tar.gz
|
||||
SOURCE_SUM=6f053957acb0af6d621ebf2b9dacc9c265844b2dc6842a021eb10f0a70094fe8" > "../conf/ruby-build.src"
|
||||
echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20201210.tar.gz
|
||||
SOURCE_SUM=256c7c29afe9ec01850e788ce4e4f496a215ab10083ea7cc9cad6dd8f03b6c5e" > "../conf/ruby-build.src"
|
||||
# Download and extract ruby-build
|
||||
ynh_setup_source "$rbenv_install_dir/plugins/ruby-build" ruby-build
|
||||
|
Loading…
Add table
Reference in a new issue