Add title for each part of code and use helper upstream_version

This commit is contained in:
Josué Tille 2018-02-11 01:20:58 +01:00
parent 3126849ae4
commit 494ca2e218
8 changed files with 132 additions and 59 deletions

View file

@ -1,66 +1,14 @@
#!/bin/bash #=================================================
# SET ALL CONSTANTS
#=================================================
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Detect the system architecture to download the right tarball
# NOTE: `uname -m` is more accurate and universal than `arch`
# See https://en.wikipedia.org/wiki/Uname
if [ -n "$(uname -m | grep 64)" ]; then
architecture="x86-64"
elif [ -n "$(uname -m | grep 86)" ]; then
architecture="i386"
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
else
ynh_die "Unable to detect your achitecture, please open a bug describing \
your hardware and the result of the command \"uname -m\"." 1
fi
# Read the value of a key in a ynh manifest file
#
# usage: ynh_read_manifest manifest key
# | arg: manifest - Path of the manifest to read
# | arg: key - Name of the key to find
ynh_read_manifest () {
manifest="$1"
key="$2"
python3 -c "import sys, json;print(json.load(open('$manifest'))['$key'])"
}
# Read the upstream version from the manifest
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
# For example : 4.3-2~ynh3
# This include the number before ~ynh
# In the last example it return 4.3-2
#
# usage: ynh_app_upstream_version
ynh_app_upstream_version () {
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
version_key=$(ynh_read_manifest "$manifest_path" "version")
echo "${version_key/~ynh*/}"
}
# Read package version from the manifest
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
# For example : 4.3-2~ynh3
# This include the number after ~ynh
# In the last example it return 3
#
# usage: ynh_app_package_version
ynh_app_package_version () {
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
version_key=$(ynh_read_manifest "$manifest_path" "version")
echo "${version_key/*~ynh/}"
}
seafile_version=$(ynh_app_upstream_version) seafile_version=$(ynh_app_upstream_version)
#=================================================
# DEFINE ALL COMMON FONCTIONS
#=================================================
get_configuration() { get_configuration() {
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
seafile_user=$(ynh_app_setting_get $app seafile_user) seafile_user=$(ynh_app_setting_get $app seafile_user)

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers
ynh_abort_if_errors ynh_abort_if_errors
# Import common cmd # Import common cmd
source ../settings/scripts/experimental_helper.sh
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
# Set configuration for user and final path # Set configuration for user and final path
@ -16,6 +21,10 @@ get_configuration
domain=$(ynh_app_setting_get ${app} domain) domain=$(ynh_app_setting_get ${app} domain)
db_pwd=$(ynh_app_setting_get ${app} mysqlpwd) db_pwd=$(ynh_app_setting_get ${app} mysqlpwd)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# # Backup app files # # Backup app files
ynh_backup $final_path ynh_backup $final_path
ynh_backup /home/yunohost.app/seafile-data "data" 1 ynh_backup /home/yunohost.app/seafile-data "data" 1

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers
ynh_abort_if_errors ynh_abort_if_errors
# Import common cmd # Import common cmd
source ./experimental_helper.sh
source ./_common.sh source ./_common.sh
# Retrive arguments # Retrive arguments
@ -53,7 +58,10 @@ then
change_path=1 change_path=1
fi fi
#=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf

View file

@ -0,0 +1,56 @@
# Detect the system architecture to download the right tarball
# NOTE: `uname -m` is more accurate and universal than `arch`
# See https://en.wikipedia.org/wiki/Uname
if [ -n "$(uname -m | grep 64)" ]; then
architecture="x86-64"
elif [ -n "$(uname -m | grep 86)" ]; then
architecture="i386"
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
else
ynh_die "Unable to detect your achitecture, please open a bug describing \
your hardware and the result of the command \"uname -m\"." 1
fi
# Read the value of a key in a ynh manifest file
#
# usage: ynh_read_manifest manifest key
# | arg: manifest - Path of the manifest to read
# | arg: key - Name of the key to find
ynh_read_manifest () {
manifest="$1"
key="$2"
python3 -c "import sys, json;print(json.load(open('$manifest'))['$key'])"
}
# Read the upstream version from the manifest
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
# For example : 4.3-2~ynh3
# This include the number before ~ynh
# In the last example it return 4.3-2
#
# usage: ynh_app_upstream_version
ynh_app_upstream_version () {
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
version_key=$(ynh_read_manifest "$manifest_path" "version")
echo "${version_key/~ynh*/}"
}
# Read package version from the manifest
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
# For example : 4.3-2~ynh3
# This include the number after ~ynh
# In the last example it return 3
#
# usage: ynh_app_package_version
ynh_app_package_version () {
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
version_key=$(ynh_read_manifest "$manifest_path" "version")
echo "${version_key/*~ynh/}"
}

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers
ynh_abort_if_errors ynh_abort_if_errors
# Import common cmd # Import common cmd
source ./experimental_helper.sh
source ./_common.sh source ./_common.sh
# Retrieve arguments # Retrieve arguments
@ -49,6 +54,10 @@ ynh_app_setting_set $app installed_version $seafile_version
# Retrieve admin email # Retrieve admin email
admin_email=$(yunohost user info $admin | grep mail: | sed "s/mail: //g") admin_email=$(yunohost user info $admin | grep mail: | sed "s/mail: //g")
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# Check dependencies # Check dependencies
install_dependance install_dependance
@ -142,6 +151,10 @@ ynh_replace_special_string "__ADMIN_PASSWORD__" $admin_password "$final_path/fir
su - $seafile_user -s /bin/bash -c "$final_path/first_launch.exp $final_path/seafile-server-$seafile_version $admin_email" su - $seafile_user -s /bin/bash -c "$final_path/first_launch.exp $final_path/seafile-server-$seafile_version $admin_email"
ynh_secure_remove "$final_path/first_launch.exp" ynh_secure_remove "$final_path/first_launch.exp"
#=================================================
# GENERIC FINALIZATION
#=================================================
# Add sso config to unprotect domain.tld/seafhttp + domain.tld/seafdav do in /etc/ssowat/conf.json.persistent # Add sso config to unprotect domain.tld/seafhttp + domain.tld/seafdav do in /etc/ssowat/conf.json.persistent
cp ../conf/add_sso_conf.py $final_path cp ../conf/add_sso_conf.py $final_path
cp ../conf/remove_sso_conf.py $final_path cp ../conf/remove_sso_conf.py $final_path

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers
set -u set -u
# Import common cmd # Import common cmd
source ./experimental_helper.sh
source ./_common.sh source ./_common.sh
# Init get Final path # Init get Final path
@ -15,6 +20,10 @@ get_configuration
# Retrieve arguments # Retrieve arguments
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
#=================================================
# STANDARD REMOVE
#=================================================
systemctl stop seafile-server.service systemctl stop seafile-server.service
# remove sso config to unprotect domain.tld/seafhttp in /etc/ssowat/conf.json.persistent # remove sso config to unprotect domain.tld/seafhttp in /etc/ssowat/conf.json.persistent

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers
ynh_abort_if_errors ynh_abort_if_errors
# Import common cmd # Import common cmd
source ../settings/scripts/experimental_helper.sh
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
# Retrieve arguments # Retrieve arguments
@ -18,6 +23,10 @@ seafile_data=/home/yunohost.app/seafile-data
# Check domain/path availability # Check domain/path availability
ynh_webpath_available $domain $path || ynh_die "$domain/$path is not available, please use an other domain or path." ynh_webpath_available $domain $path || ynh_die "$domain/$path is not available, please use an other domain or path."
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# Restore dependencies # Restore dependencies
install_dependance install_dependance
@ -39,6 +48,10 @@ su -c "mysql -u ${app} -p$db_pwd ccnetdb < ${YNH_CWD}/ccnetdb.dmp"
su -c "mysql -u ${app} -p$db_pwd seafiledb < ${YNH_CWD}/seafiledb.dmp" su -c "mysql -u ${app} -p$db_pwd seafiledb < ${YNH_CWD}/seafiledb.dmp"
su -c "mysql -u ${app} -p$db_pwd seahubdb < ${YNH_CWD}/seahubdb.dmp" su -c "mysql -u ${app} -p$db_pwd seahubdb < ${YNH_CWD}/seahubdb.dmp"
#=================================================
# GENERIC FINALIZATION
#=================================================
# Restore sso persistent config # Restore sso persistent config
python $final_path/add_sso_conf.py python $final_path/add_sso_conf.py

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -7,6 +11,7 @@ source /usr/share/yunohost/helpers
ynh_abort_if_errors ynh_abort_if_errors
# Import common cmd # Import common cmd
source ./experimental_helper.sh
source ./_common.sh source ./_common.sh
# Init get Final path # Init get Final path
@ -30,6 +35,10 @@ set_path_2
# stop seafile server # stop seafile server
systemctl stop seafile-server.service systemctl stop seafile-server.service
#=================================================
# MIGRATION FROM OLD VERSION
#=================================================
# extract new version # extract new version
test -e $final_path/seafile-server-$seafile_version && ynh_secure_remove "$final_path/seafile-server-$seafile_version" test -e $final_path/seafile-server-$seafile_version && ynh_secure_remove "$final_path/seafile-server-$seafile_version"
install_source install_source
@ -130,6 +139,10 @@ fi
# Fix local warning # Fix local warning
ynh_replace_string en_US.UTF-8 $LANG $final_path/seafile-server-$seafile_version/seahub.sh ynh_replace_string en_US.UTF-8 $LANG $final_path/seafile-server-$seafile_version/seahub.sh
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# Config nginx # Config nginx
config_nginx config_nginx
@ -141,6 +154,10 @@ ynh_replace_string SEAFILE_USER $seafile_user /etc/init.d/seafile-server
chmod +x /etc/init.d/seafile-server chmod +x /etc/init.d/seafile-server
systemctl daemon-reload systemctl daemon-reload
#=================================================
# GENERIC FINALIZATION
#=================================================
# restore correct permissions # restore correct permissions
chown -R $seafile_user:$seafile_user $final_path chown -R $seafile_user:$seafile_user $final_path