1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wekan_ynh.git synced 2024-09-03 20:36:09 +02:00

[enh] Upgrade all the package, backup script

This commit is contained in:
ljf 2017-10-02 02:07:41 +02:00
parent 1f5f441280
commit 6447c00312
14 changed files with 3373 additions and 308 deletions

2646
LICENSE

File diff suppressed because it is too large Load diff

View file

@ -8,9 +8,21 @@ For the moment it kind of works, but this is still experimental and has not been
The main drawback at the moment is that it's [not integrated with the LDAP](https://github.com/wekan/wekan/issues/119). So users have to create accounts (and can create infinite number of accounts) manually, and need to login manually specifically in Wekan.
## Infos
**Package by:** ljf & Aleks
**Categories:** Productivity, Task
**Upgrade this package:**
`sudo yunohost app upgrade --verbose LimeSurvey -u https://github.com/YunoHost-Apps/wekan_ynh`
**Multi-user:** Yes.
**Private/Public mode:** In private mode, only authorized YunoHost members can access to the wekan.
**SSO/LDAP:** SSO and LDAP are not configured.
## To-do
- Test / make it work on ARM
- LDAP is not yet integrated in Wekan, unfortunately... but some people did tweak things as discussed [here](https://github.com/wekan/wekan/issues/119#issuecomment-224319252)
- Upgrade, backup and restore scripts

36
check_process Normal file
View file

@ -0,0 +1,36 @@
# See here for more informations
# https://github.com/YunoHost/package_check#syntax-check_process-file
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
is_public=1 (PUBLIC|public=1|private=0)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
backup_restore=1
multi_instance=1
incorrect_path=1
port_already_use=1
change_url=1
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
# Level 4:
Level 4=0
# Level 5:
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=ljf+ynh-wekan@grimaud.me
Notification=down

6
conf/app.src Normal file
View file

@ -0,0 +1,6 @@
SOURCE_URL=https://github.com/wekan/wekan/releases/download/v0.45/wekan-0.45.tar.gz
SOURCE_SUM=4245f6674e407ad40bc899788058887213d5daf8d7620e0ae0c07af22b7c82aa
SOURCE_SUM_PRG=sha256sum
ARCH_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=wekan-0.45.tar.gz

View file

@ -1,6 +1,10 @@
location YNH_WWW_PATH
location __PATH__
{
proxy_pass http://127.0.0.1:8081;
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
proxy_pass http://127.0.0.1:__PORT__;
proxy_http_version 1.1;
# allow websockets
@ -10,6 +14,9 @@ location YNH_WWW_PATH
# preserve client IP
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
#proxy_buffering off;
# this setting allows the browser to cache the application in
# a way compatible with Meteor.
# on every applicaiton update the name of CSS and JS file is different,
@ -19,4 +26,7 @@ location YNH_WWW_PATH
{
expires 30d;
}
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}

View file

@ -1,25 +0,0 @@
[Unit]
Description=Wekan Server
Wants=mongod.service
After=network.target mongod.service
[Service]
Type=simple
WorkingDirectory=WEKAN_INSTALL_PATH
ExecStart=WEKAN_NODEJS_PATH main.js
Environment=NODE_ENV=production
Environment=MONGO_URL=mongodb://127.0.0.1:27017/WEKAN_DB_NAME
Environment=ROOT_URL=http://127.0.0.1:WEKAN_PORTWEKAN_URI PORT=WEKAN_PORT
User=wekan
Restart=on-failure
#StartLimitInterval=86400
#StartLimitBurst=5
RestartSec=10
ExecReload=/bin/kill -USR1 $MAINPID
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=wekan
[Install]
WantedBy=multi-user.target

28
conf/systemd.service Normal file
View file

@ -0,0 +1,28 @@
[Unit]
Description=Wekan, task board
Wants=mongod.service
After=network.target mongod.service
[Service]
Type=simple
User=__APP__
Group=__APP__
ExecStartPre=__NODEJS__
Environment="PATH=__ENV_PATH__"
Environment=NODE_ENV=production
Environment=MONGO_URL=mongodb://127.0.0.1:27017/__DB_NAME__
Environment=ROOT_URL=http://127.0.0.1:__PORT____URI__ PORT=__PORT__
WorkingDirectory=__FINALPATH__
ExecStart=/opt/node_n/bin/node __FINALPATH__/main.js
Restart=on-failure
#StartLimitInterval=86400
#StartLimitBurst=5
RestartSec=10
ExecReload=/bin/kill -USR1 $MAINPID
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=__APP__
[Install]
WantedBy=multi-user.target

View file

@ -2,25 +2,25 @@
"name": "Wekan",
"id": "wekan",
"packaging_format": 1,
"version": "0.45-1",
"description": {
"en": "Trello-like kanban",
"fr": "Un kanban similaire à Trello"
},
"url": "https://wekan.io",
"license": "free",
"license": "MIT",
"maintainer": {
"name": "alexAubin",
"email": "alex.aubin@mailoo.org",
"url": "https://github.com/alexAubin/"
},
"requirements": {
"yunohost": ">> 2.4.0"
"yunohost": ">= 2.7.2"
},
"multi_instance": false,
"multi_instance": true,
"services": [
"nginx",
"php5-fpm",
"mysql"
"mongod"
],
"arguments": {
"install" : [
@ -43,15 +43,6 @@
"example": "/wekan",
"default": "/wekan"
},
{
"name": "admin",
"type": "user",
"ask": {
"en": "Choose an admin user",
"fr": "Choisissez ladministrateur"
},
"example": "johndoe"
},
{
"name": "is_public",
"type": "boolean",
@ -60,15 +51,6 @@
"fr": "Est-ce une application publique ?"
},
"default": false
},
{
"name": "language",
"ask": {
"en": "Choose the application language",
"fr": "Choisissez la langue de l'application"
},
"choices": ["fr", "en"],
"default": "fr"
}
]
}

211
scripts/_future.sh Normal file
View file

@ -0,0 +1,211 @@
log() {
echo "${1}"
}
info() {
log "[INFO] ${1}"
}
warn() {
log "[WARN] ${1}"
}
err() {
log "[ERR] ${1}"
}
to_logs() {
# When yunohost --verbose or bash -x
if $_ISVERBOSE; then
cat
else
cat > /dev/null
fi
}
read_json () {
sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])"
}
read_manifest () {
if [ -f '../manifest.json' ] ; then
read_json '../manifest.json' "$1"
else
read_json '../settings/manifest.json' "$1"
fi
}
abort_if_up_to_date () {
version=$(read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" 'version' 2> /dev/null || echo '20160501-7')
last_version=$(read_manifest 'version')
if [ "${version}" = "${last_version}" ]; then
info "Up-to-date, nothing to do"
ynh_die "" 0
fi
}
#=================================================
# NODEJS
#=================================================
# INFOS
# n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser.
# C'est ainsi qu'il change de version
# ynh_install_nodejs installe la version de nodejs demandée en argument, avec n
# ynh_use_nodejs active une version de nodejs dans le script courant
# 3 variables sont mises à disposition, et 2 sont stockées dans la config de l'app
# - nodejs_path: Le chemin absolu de cette version de node
# Utilisé pour des appels directs à node.
# - nodejs_version: Simplement le numéro de version de nodejs pour cette application
# - nodejs_use_version: Un alias pour charger une version de node dans le shell courant.
# Utilisé pour démarrer un service ou un script qui utilise node ou npm
# Dans ce cas, c'est $PATH qui contient le chemin de la version de node. Il doit être propagé sur les autres shell si nécessaire.
n_install_dir="/opt/node_n"
node_version_path="/opt/node_n/n/versions/node"
# N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n.
export N_PREFIX="$n_install_dir"
ynh_use_nodejs () {
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"; N_PREFIX="$n_install_dir""
nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version"
# "Load" a version of node
eval $load_n_path; $nodejs_use_version
# Get the absolute path of this version of node
nodejs_path="$(n bin $nodejs_version)"
# Make an alias for node use
ynh_node_exec="eval $load_n_path; n use $nodejs_version"
}
ynh_install_nodejs () {
# Use n, https://github.com/tj/n to manage the nodejs versions
nodejs_version="$1"
local n_install_script="https://git.io/n-install"
# Create $n_install_dir
mkdir -p "$n_install_dir"
# Load n path in PATH
CLEAR_PATH="$n_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of node has already setup.
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing node binary, to avoid to block n.
test -x /usr/bin/node && mv /usr/bin/node /usr/bin/node_n
test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n
# If n is not previously setup, install it
n --version > /dev/null 2>&1 || \
(curl -sL $n_install_script | N_PREFIX=$N_PREFIX bash -s -- -y - 2>&1 )
# Modify the default N_PREFIX in n script
ynh_replace_string "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$n_install_dir/bin/n"
# Restore /usr/local/bin in PATH
PATH=$CLEAR_PATH
# And replace the old node binary.
test -x /usr/bin/node_n && mv /usr/bin/node_n /usr/bin/node
test -x /usr/bin/npm_n && mv /usr/bin/npm_n /usr/bin/npm
# Install the requested version of nodejs
n $nodejs_version
# Find the last "real" version for this major version of node.
real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1)
real_nodejs_version=$(basename $real_nodejs_version)
# Create a symbolic link for this major version. If the file doesn't already exist
if [ ! -e "$node_version_path/$nodejs_version" ]
then
ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version
fi
# Store the ID of this app and the version of node requested for it
echo "$YNH_APP_ID:$nodejs_version" | tee --append "$n_install_dir/ynh_app_version"
# Store nodejs_version into the config of this app
ynh_app_setting_set $app nodejs_version $nodejs_version
# Build the update script and set the cronjob
ynh_cron_upgrade_node
ynh_use_nodejs
}
ynh_remove_nodejs () {
ynh_use_nodejs
# Remove the line for this app
sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$n_install_dir/ynh_app_version"
# If none another app uses this version of nodejs, remove it.
if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version"
then
n rm $nodejs_version
fi
# If none another app uses n, remove n
if [ ! -s "$n_install_dir/ynh_app_version" ]
then
ynh_secure_remove "$n_install_dir"
ynh_secure_remove "/usr/local/n"
sed --in-place "/N_PREFIX/d" /root/.bashrc
fi
}
ynh_cron_upgrade_node () {
# Build the update script
cat > "$n_install_dir/node_update.sh" << EOF
#!/bin/bash
version_path="$node_version_path"
n_install_dir="$n_install_dir"
# Log the date
date
# List all real installed version of node
all_real_version="\$(find \$version_path/* -maxdepth 0 -type d | sed "s@\$version_path/@@g")"
# Keep only the major version number of each line
all_real_version=\$(echo "\$all_real_version" | sed 's/\..*\$//')
# Remove double entries
all_real_version=\$(echo "\$all_real_version" | sort --unique)
# Read each major version
while read version
do
echo "Update of the version \$version"
sudo \$n_install_dir/bin/n \$version
# Find the last "real" version for this major version of node.
real_nodejs_version=\$(find \$version_path/\$version* -maxdepth 0 | sort --version-sort | tail --lines=1)
real_nodejs_version=\$(basename \$real_nodejs_version)
# Update the symbolic link for this version
sudo ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version
done <<< "\$(echo "\$all_real_version")"
EOF
chmod +x "$n_install_dir/node_update.sh"
# Build the cronjob
cat > "/etc/cron.daily/node_update" << EOF
#!/bin/bash
$n_install_dir/node_update.sh >> $n_install_dir/node_update.log
EOF
chmod +x "/etc/cron.daily/node_update"
}

41
scripts/backup Normal file
View file

@ -0,0 +1,41 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP OF THE MAIN DIR OF THE APP
#=================================================
ynh_backup "$final_path"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP OF MONGODB
#=================================================
mongodump --db "$app" -o "./dump"

View file

@ -1,195 +1,135 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# Arguments from manifest
readonly APP=$YNH_APP_INSTANCE_NAME
readonly DOMAIN=$YNH_APP_ARG_DOMAIN
readonly APP_URI=$YNH_APP_ARG_PATH
readonly APP_ADMIN=$YNH_APP_ARG_ADMIN
readonly APP_IS_PUBLIC=$YNH_APP_ARG_IS_PUBLIC
readonly APP_LANGUAGE=$YNH_APP_ARG_LANGUAGE
readonly APP_INSTALL_PATH="/var/www/wekan"
readonly SYSTEMD_CONF_TEMPLATE="$PWD/../conf/systemd.conf"
readonly NGINX_CONF_TEMPLATE="$PWD/../conf/nginx.conf"
readonly METEOR_INSTALL_DIR="/opt/meteor"
readonly NVM_INSTALL_DIR="/opt/nvm"
readonly METEOR_BIN="/usr/local/bin/meteor"
# Source YunoHost helpers
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _future.sh
source /usr/share/yunohost/helpers
function configure_app()
{
# Save app settings
ynh_app_setting_set "$APP" admin "$APP_ADMIN"
ynh_app_setting_set "$APP" is_public "$APP_IS_PUBLIC"
ynh_app_setting_set "$APP" language "$APP_LANGUAGE"
# Check domain/path availability
sudo yunohost app checkurl "${DOMAIN}${APP_URI}" -a "$APP" \
|| ynh_die "Path not available: ${DOMAIN}${APP_URI}"
}
function create_user_wekan()
{
if [[ -z $(sudo getent passwd wekan) ]]
then
sudo useradd wekan
fi
}
function install_node()
{
local nvm_install_script="https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh"
if [ ! -d "$NVM_INSTALL_DIR" ];
then
sudo mkdir $NVM_INSTALL_DIR
fi
sudo chown -R wekan $NVM_INSTALL_DIR
cd $NVM_INSTALL_DIR
# Install nvm
sudo curl -o- $nvm_install_script | sudo NVM_DIR=$NVM_INSTALL_DIR bash
# Install latest nodejs
sudo su -c ". $NVM_INSTALL_DIR/nvm.sh && nvm install 0.10"
}
function add_swap_if_needed()
{
local available_swap=$(free | tail -n 1 | awk '{print $2}')
local tmp_swap_file=/tmp/wekan_swapfile
if [ $available_swap -lt 1000000 ];
then
# It is NOT possible to setup a swap file on a tmpfs filesystem
if [[ ! -z $(mount | grep /tmp | grep tmpfs) ]];
then
tmp_swap_file=/var/cache/wekan_swapfile
fi
sudo dd if=/dev/zero of=$tmp_swap_file bs=1M count=1024
sudo chmod 600 $tmp_swap_file
sudo mkswap $tmp_swap_file
sudo swapon $tmp_swap_file
fi
}
function install_meteor()
{
# Install meteor
if [ ! -d "$METEOR_INSTALL_DIR" ];
then
sudo mkdir $METEOR_INSTALL_DIR
fi
sudo chown -R wekan $METEOR_INSTALL_DIR
cd $METEOR_INSTALL_DIR
sudo su -c "curl https://install.meteor.com/ | sh"
}
function install_and_build_wekan()
{
local npm_bin=`sudo su -c ". $NVM_INSTALL_DIR/nvm.sh && nvm use 0.10 >/dev/null && which npm"`
# Give all permissions to app dir to user wekan
if [ -d "$APP_INSTALL_PATH" ];
then
sudo rm -rf $APP_INSTALL_PATH
fi
sudo mkdir -p $APP_INSTALL_PATH
sudo chown -R wekan $APP_INSTALL_PATH
cd $APP_INSTALL_PATH
# Clone wekan github repo
sudo su wekan -c "git clone https://github.com/wekan/wekan.git ."
# Install dependencies with npm
sudo su wekan -c "$npm_bin install"
# Build with meteor
sudo rm -rf .build
sudo su wekan -c "$METEOR_BIN build .build --directory | tee /tmp/meteor_build.log"
# Install dependencies .. again ?
cd .build/bundle/programs/server
sudo su wekan -c "$npm_bin install"
}
function remove_swap()
{
local file1="/tmp/wekan_swapfile"
local file2="/var/cache/wekan_swapfile"
if [ -f $file1 ]; then
sudo swapoff $file1
sudo rm -f $file1
fi
if [ -f $file2 ]; then
sudo swapoff $file2
sudo rm -f $file2
fi
}
function install_mongodb()
{
# Install mongodb
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.2.11 mongodb-org-server=3.2.11 mongodb-org-shell=3.2.11 mongodb-org-mongos=3.2.11 mongodb-org-tools=3.2.11
sudo systemctl start mongod
sudo systemctl enable mongod
}
function setup_systemd_service()
{
# Install systemd conf
local node_bin=`sudo su -c ". $NVM_INSTALL_DIR/nvm.sh && nvm use 0.10 >/dev/null && which node"`
sed -i "s@WEKAN_INSTALL_PATH@$APP_INSTALL_PATH/.build/bundle@g" $SYSTEMD_CONF_TEMPLATE
sed -i "s@WEKAN_NODEJS_PATH@$node_bin@g" $SYSTEMD_CONF_TEMPLATE
sed -i "s@WEKAN_DOMAIN@$DOMAIN@g" $SYSTEMD_CONF_TEMPLATE
sed -i "s@WEKAN_URI@$APP_URI@g" $SYSTEMD_CONF_TEMPLATE
sed -i "s@WEKAN_DB_NAME@wekan@g" $SYSTEMD_CONF_TEMPLATE
sed -i "s@WEKAN_PORT@8081@g" $SYSTEMD_CONF_TEMPLATE
sudo cp $SYSTEMD_CONF_TEMPLATE /etc/systemd/system/wekan.service
# Start service
sudo systemctl daemon-reload
sudo systemctl start wekan
sudo systemctl enable wekan
}
function configure_nginx_and_ssowat()
{
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_WWW_PATH@$APP_URI@g" $NGINX_CONF_TEMPLATE
sed -i "s@YNH_WWW_ALIAS@$APP_INSTALL_PATH/@g" $NGINX_CONF_TEMPLATE
sudo cp $NGINX_CONF_TEMPLATE /etc/nginx/conf.d/$DOMAIN.d/$APP.conf
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $APP_IS_PUBLIC -eq 1 ]]; then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$APP" unprotected_uris "/"
fi
sudo service nginx reload
}
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
configure_app
create_user_wekan
install_node
add_swap_if_needed
install_meteor
install_and_build_wekan
remove_swap
install_mongodb
setup_systemd_service
configure_nginx_and_ssowat
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app is_public $is_public
#=================================================
# FIND AND OPEN A PORT
#=================================================
# Find a free port
port=$(ynh_find_port 8081)
ynh_app_setting_set $app port $port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_nodejs 4.8.4
# Install mongodb
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" > /etc/apt/sources.list.d/mongodb-org-3.2.list
ynh_install_app_dependencies "mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
# For this app sources are in app subdirectory
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app "$final_path"
#=================================================
# SPECIFIC SETUP
#=================================================
# Install wekan dependencies
chown -R $app $final_path
pushd $final_path/programs/server
ynh_use_nodejs
npm install
popd
# Start mogodb
systemctl start mongod
systemctl enable mongod
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_replace_string "__DB_NAME__" "$app" "../conf/systemd.service"
ynh_replace_string "__URI__" "$path_url" "../conf/systemd.service"
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set strong right permissions to app files
chown -R $app: "$final_path"
chmod -R 640 "$final_path"
find "$final_path" -type d -print0 | xargs -0 chmod 750
#=================================================
# ADD SERVICE IN ADMIN PANEL
#=================================================
yunohost service add mongod --log "/var/log/mongodb.log"
#=================================================
# SETUP SSOWAT
#=================================================
# Make app public if necessary or protect it
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx

View file

@ -1,83 +1,82 @@
#!/bin/bash
# Source YunoHost helpers
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _future.sh
source /usr/share/yunohost/helpers
# Retrieve app settings
readonly APP=$YNH_APP_INSTANCE_NAME
readonly DOMAIN=$(ynh_app_setting_get "$app" domain)
#=================================================
# LOAD SETTINGS
#=================================================
readonly app=$YNH_APP_INSTANCE_NAME
readonly domain=$(ynh_app_setting_get "$app" domain)
readonly final_path=$(ynh_app_setting_get "$app" final_path)
readonly APP_INSTALL_PATH="/var/www/wekan"
readonly NVM_INSTALL_DIR="/opt/nvm"
readonly METEOR_INSTALL_DIR="/opt/meteor"
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
function remove_node()
{
if [ -d "$NVM_INSTALL_DIR" ];
then
sudo rm -rf $NVM_INSTALL_DIR
fi
}
ynh_remove_systemd_config
function remove_meteor()
{
if [ -d "$METEOR_INSTALL_DIR" ];
then
sudo rm -rf $METEOR_INSTALL_DIR
fi
}
#=================================================
# DISABLE SERVICE IN ADMIN PANEL
#=================================================
function remove_wekan()
{
if [ -d "$APP_INSTALL_PATH" ];
then
sudo rm -rf $APP_INSTALL_PATH
fi
}
if yunohost service status | grep -q $app # Test l'existence du service dans Yunohost
then
echo "Remove $app service"
yunohost service remove $app
fi
#=================================================
# REMOVE DB
#=================================================
mongo $app --eval "db.dropDatabase()"
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_remove_app_dependencies
#=================================================
# REMOVE NODEJS
#=================================================
ynh_remove_nodejs
function remove_mongodb()
{
sudo systemctl stop mongod
sudo systemctl disable mongod
#=================================================
# REMOVE MONGODB
#=================================================
# TODO / FIXME : remove the keys added ?
#apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
#rm -f /etc/apt/sources.list.d/mongodb-org-3.2.list
# TODO / FIXME : remove the keys added ?
#sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
sudo apt-get remove -y mongodb-org=3.2.11 mongodb-org-server=3.2.11 mongodb-org-shell=3.2.11 mongodb-org-mongos=3.2.11 mongodb-org-tools=3.2.11
sudo apt-get update
sudo rm -f /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
}
#=================================================
# REMOVE THE MAIN DIR OF THE APP
#=================================================
function remove_systemd_service()
{
sudo systemctl stop wekan
sudo systemctl disable wekan
sudo rm -f /etc/systemd/system/wekan.service
sudo systemctl daemon-reload
}
ynh_secure_remove "/var/www/$app"
function remove_nginx_conf()
{
# Modify Nginx configuration file and copy it to Nginx conf directory
sudo rm -f /etc/nginx/conf.d/$DOMAIN.d/$APP.conf
sudo service nginx reload
}
#=================================================
# REMOVE THE NGINX CONFIGURATION
#=================================================
ynh_remove_nginx_config
#=================================================
# GENERIC FINALISATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_system_user_delete $app
function remove_user_wekan()
{
if [[ ! -z $(sudo getent passwd wekan) ]]
then
sudo userdel wekan
fi
}
remove_node
remove_meteor
remove_wekan
remove_mongodb
remove_systemd_service
remove_nginx_conf
remove_user_wekan

111
scripts/restore Normal file
View file

@ -0,0 +1,111 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_future.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path_url)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app final_path)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
yunohost app checkurl "${domain}${path_url}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORE STEPS
#=================================================
ynh_restore
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app "$final_path"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_nodejs 4.8.4
# Install mongodb
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" > /etc/apt/sources.list.d/mongodb-org-3.2.list
ynh_install_app_dependencies "mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools"
#=================================================
# RESTORE DB
#=================================================
# Start mogodb
systemctl start mongod
systemctl enable mongod
mongorestore --db $app ./dump
#=================================================
# SPECIFIC SETUP
#=================================================
# Install wekan dependencies
chown -R $app $final_path
pushd $final_path/bundle/programs/server
ynh_use_nodejs
npm install
popd
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set strong right permissions to app files
chown -R $app: "$final_path"
chmod -R 640 "$final_path"
find "$final_path" -type d -print0 | xargs -0 chmod 750
#=================================================
# ADD SERVICE IN ADMIN PANEL
#=================================================
yunohost service add mongod --log "/var/log/mongodb.log"
#=================================================
# SETUP SSOWAT
#=================================================
# Make app public if necessary or protect it
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx

70
scripts/upgrade Normal file
View file

@ -0,0 +1,70 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _future.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path_url)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app final_path)
#=================================================
# Check version
#=================================================
abort_if_up_to_date
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_backup_before_upgrade # Backup the current version of the app
ynh_clean_setup () {
ynh_restore_upgradebackup # restore it if the upgrade fails
}
ynh_abort_if_errors # Exit if an error occurs during the execution of the script
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
#if [ "${version}" = "20160501-7" ]; then
#fi
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Download, check integrity, uncompress and patch the source from app.src
# For this app sources are in app subdirectory
ynh_setup_source "$final_path"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set strong right permissions to app files
chown -R $app: "$final_path"
chmod -R 640 "$final_path"
find "$final_path" -type d -print0 | xargs -0 chmod 750
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx