1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00

YunoHost 2.2 compatibility and backport 2.4 helpers

This commit is contained in:
src386 2016-07-11 18:41:22 +02:00
parent 836623cd71
commit 96bce7d455
10 changed files with 159 additions and 39 deletions

View file

@ -1,7 +1,13 @@
**Changelog** **Changelog**
1.8.1 2016-05-30 2.0 2016?
- Update to movim 0.9 git2016-05-30 - Major code improvement thanks to @jeromelebleu, #28 :
- Download and update source code using git (fixed HEAD COMMIT though)
- Make use of new YunoHost helpers coming with the 2.4 version
- Add backup and restore scripts
- Redirect to the SSO on logging out
- YunoHost 2.4 helpers backport if 2.2 detected (_helpers.sh)
- Update to movim 0.9 git 2016-07-10
1.8 2016-04-15 1.8 2016-04-15
- Update to movim 0.9 git2016-04-15 - Update to movim 0.9 git2016-04-15

View file

@ -5,7 +5,7 @@ Movim is a decentralized social network, written in PHP and HTML5 and based on t
It is recommended to use a "valid" certificate to use Movim, auto-signed is sometimes problematic. You might want to take a look a StartSSL or Let's Encrypt. It is recommended to use a "valid" certificate to use Movim, auto-signed is sometimes problematic. You might want to take a look a StartSSL or Let's Encrypt.
Provided Movim version : 0.9 git2016-05-30 Provided Movim version : 0.9 git2016-07-10
Please read CHANGELOG. Please read CHANGELOG.

View file

@ -17,9 +17,6 @@
"mysql", "mysql",
"metronome" "metronome"
], ],
"requirements": {
"yunohost": ">= 2.4.0"
},
"multi_instance": false, "multi_instance": false,
"arguments": { "arguments": {
"install" : [ "install" : [
@ -71,12 +68,12 @@
}, },
{ {
"name": "ssoenabled", "name": "ssoenabled",
"type": "boolean",
"ask": { "ask": {
"en": "Enable SSO support (autologin)?", "en": "Enable SSO support (autologin) ?",
"fr": "Activer le support du SSO (connexion auto) ?" "fr": "Activer le support SSO (connexin auto) ?"
}, },
"default": true "choices": ["Yes", "No"],
"default": "Yes"
}, },
{ {
"name": "port", "name": "port",

View file

@ -6,7 +6,7 @@
GIT_REPO="https://github.com/movim/movim" GIT_REPO="https://github.com/movim/movim"
# Commit to checkout # Commit to checkout
HEAD_COMMIT="512523576b03c2c8952305e70681ed31172b9fd2" HEAD_COMMIT="8f56192582e83f4b1dbaa00aab8feb55031598e4"
# Source code destination directory # Source code destination directory
DESTDIR="/var/www/movim" DESTDIR="/var/www/movim"

78
scripts/_helpers.sh Normal file
View file

@ -0,0 +1,78 @@
#
# Yunohost helpers
#
ynh_die() {
echo "$1" 1>&2
exit "${2:-1}"
}
ynh_user_exists() {
sudo yunohost user info $admin
}
ynh_system_user_exists() {
getent passwd "$1" &>/dev/null
}
ynh_app_setting_get() {
sudo yunohost app setting "$1" "$2"
}
ynh_app_setting_set() {
sudo yunohost app setting "$1" "$2" -v "$3"
}
ynh_app_setting_delete() {
sudo yunohost app setting -d "$1" "$2"
}
ynh_string_random() {
dd if=/dev/urandom bs=1 count=200 2> /dev/null \
| tr -c -d '[A-Za-z0-9]' \
| sed -n 's/\(.\{'"${1:-24}"'\}\).*/\1/p'
}
MYSQL_ROOT_PWD_FILE=/etc/yunohost/mysql
ynh_mysql_create_db() {
db=$1
sql="CREATE DATABASE ${db};"
# grant all privilegies to user
if [[ $# -gt 1 ]]; then
sql+=" GRANT ALL PRIVILEGES ON ${db}.* TO '${2}'@'localhost'"
[[ -n ${3:-} ]] && sql+=" IDENTIFIED BY '${3}'"
sql+=" WITH GRANT OPTION;"
fi
ynh_mysql_execute_as_root "$sql"
}
ynh_mysql_drop_db() {
ynh_mysql_execute_as_root "DROP DATABASE ${1};"
}
ynh_mysql_drop_user() {
ynh_mysql_execute_as_root "DROP USER '${1}'@'localhost';"
}
ynh_mysql_execute_as_root() {
ynh_mysql_connect_as "root" "$(sudo cat $MYSQL_ROOT_PWD_FILE)" \
"${2:-}" <<< "$1"
}
ynh_mysql_connect_as() {
mysql -u "$1" --password="$2" -B "${3:-}"
}
ynh_package_install() {
ynh_apt -o Dpkg::Options::=--force-confdef \
-o Dpkg::Options::=--force-confold install $@
}
ynh_apt() {
DEBIAN_FRONTEND=noninteractive sudo apt-get -y -qq $@
}

View file

@ -7,8 +7,16 @@ app="movim"
db_user=$app db_user=$app
db_name=$app db_name=$app
# Source YunoHost helpers # Source local helpers
source /usr/share/yunohost/helpers source ./_common.sh
# Source YunoHost helpers if exists.
# If not, source backported helpers from file.
if [ -d "/usr/share/yunohost/helpers" ]; then
source /usr/share/yunohost/helpers
else
source ./_helpers.sh
fi
# Retrieve app settings # Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get "$app" domain)

View file

@ -15,10 +15,17 @@ ssoenabled=$6
port=$7 port=$7
timezone=`cat /etc/timezone` timezone=`cat /etc/timezone`
# Source YunoHost and local helpers # Source local helpers
source /usr/share/yunohost/helpers
source ./_common.sh source ./_common.sh
# Source YunoHost helpers if exists.
# If not, source backported helpers from file.
if [ -d "/usr/share/yunohost/helpers" ]; then
source /usr/share/yunohost/helpers
else
source ./_helpers.sh
fi
# Check domain/path availability # Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \ sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| exit 1 || exit 1
@ -63,8 +70,8 @@ ynh_package_install php5-gd php5-curl php5-imagick php5-cli
# Download Movim source code # Download Movim source code
tmp_path=/tmp/movim-git tmp_path=/tmp/movim-git
sudo rm -rf "$tmp_path" sudo rm -rf "$tmp_path"
(git clone --quiet "$GIT_REPO" "$tmp_path" \ (git clone "$GIT_REPO" "$tmp_path" \
&& cd "$tmp_path" && git checkout --quiet "$HEAD_COMMIT") \ && cd "$tmp_path" && git checkout "$HEAD_COMMIT") \
|| ynh_die "Unable to download Movim source code." || ynh_die "Unable to download Movim source code."
# Set database configuration # Set database configuration
@ -89,9 +96,9 @@ sudo chmod 400 "${DESTDIR}/config/db.inc.php"
# Install PHP dependencies using composer # Install PHP dependencies using composer
(curl -sS https://getcomposer.org/installer \ (curl -sS https://getcomposer.org/installer \
| exec_cmd php -- --quiet --install-dir="$DESTDIR" \ | exec_cmd php -- --install-dir="$DESTDIR" \
&& exec_cmd php composer.phar config --global discard-changes true \ && exec_cmd php composer.phar config --global discard-changes true \
&& exec_cmd php composer.phar install --quiet --no-interaction) \ && exec_cmd php composer.phar install --no-interaction) \
|| ynh_die "Unable to install Movim dependencies." || ynh_die "Unable to install Movim dependencies."
# Set Movim database and configuration # Set Movim database and configuration
@ -106,9 +113,9 @@ sudo sed -i "s@YHDIR@${DESTDIR}@g" ../conf/movim.{service,init}
sudo sed -i "s@YHPORT@${port}@g" ../conf/movim.{service,init} sudo sed -i "s@YHPORT@${port}@g" ../conf/movim.{service,init}
if [ -d /run/systemd/system ]; then if [ -d /run/systemd/system ]; then
sudo cp ../conf/movim.service /etc/systemd/system/ sudo cp ../conf/movim.service /etc/systemd/system/
sudo systemctl --quiet daemon-reload sudo systemctl daemon-reload
sudo systemctl --quiet enable movim.service sudo systemctl enable movim.service
sudo systemctl --quiet start movim.service sudo systemctl start movim.service
else else
sudo cp ../conf/movim.init /etc/init.d/movim sudo cp ../conf/movim.init /etc/init.d/movim
sudo chmod 755 /etc/init.d/movim sudo chmod 755 /etc/init.d/movim
@ -128,7 +135,7 @@ sed -i "s@//ws/@/ws/@g" ../conf/nginx.conf # Avoid duplicate /
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/movim.conf sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/movim.conf
# SSOwat configuration # SSOwat configuration
if [[ "$ssoenabled" = "0" ]]; then if [[ "$ssoenabled" = "No" ]]; then
ynh_app_setting_set "$app" skipped_uris "/" ynh_app_setting_set "$app" skipped_uris "/"
exec_cmd php mud.php config --xmppwhitelist="$domain" exec_cmd php mud.php config --xmppwhitelist="$domain"
else else

View file

@ -2,8 +2,16 @@
app="movim" app="movim"
# Source YunoHost helpers # Source local helpers
source /usr/share/yunohost/helpers source ./_common.sh
# Source YunoHost helpers if exists.
# If not, source backported helpers from file.
if [ -d "/usr/share/yunohost/helpers" ]; then
source /usr/share/yunohost/helpers
else
source ./_helpers.sh
fi
# Retrieve app settings # Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get "$app" domain)

View file

@ -7,8 +7,16 @@ app="movim"
db_name=$app db_name=$app
db_user=$app db_user=$app
# Source YunoHost helpers # Source local helpers
source /usr/share/yunohost/helpers source ./_common.sh
# Source YunoHost helpers if exists.
# If not, source backported helpers from file.
if [ -d "/usr/share/yunohost/helpers" ]; then
source /usr/share/yunohost/helpers
else
source ./_helpers.sh
fi
# Retrieve old app settings # Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get "$app" domain)

View file

@ -5,10 +5,17 @@ set -eu
app="movim" app="movim"
# Source YunoHost and local helpers # Source local helpers
source /usr/share/yunohost/helpers
source ./_common.sh source ./_common.sh
# Source YunoHost helpers if exists.
# If not, source backported helpers from file.
if [ -d "/usr/share/yunohost/helpers" ]; then
source /usr/share/yunohost/helpers
else
source ./_helpers.sh
fi
# Retrieve app settings # Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path) path=$(ynh_app_setting_get "$app" path)
@ -28,8 +35,8 @@ if [ ! -d "${DESTDIR}/.git" ]; then
sudo rm -rf "$tmp_path" sudo rm -rf "$tmp_path"
# Download Movim source code # Download Movim source code
(git clone --quiet "$GIT_REPO" "$tmp_path" \ (git clone "$GIT_REPO" "$tmp_path" \
&& cd "$tmp_path" && git checkout --quiet "$HEAD_COMMIT") \ && cd "$tmp_path" && git checkout "$HEAD_COMMIT") \
|| ynh_die "Unable to download Movim source code." || ynh_die "Unable to download Movim source code."
sudo cp "${DESTDIR}/config/db.inc.php" "${tmp_path}/config/db.inc.php" sudo cp "${DESTDIR}/config/db.inc.php" "${tmp_path}/config/db.inc.php"
@ -40,12 +47,12 @@ if [ ! -d "${DESTDIR}/.git" ]; then
# Install composer for PHP dependencies # Install composer for PHP dependencies
curl -sS https://getcomposer.org/installer \ curl -sS https://getcomposer.org/installer \
| exec_cmd php -- --quiet --install-dir="$DESTDIR" | exec_cmd php -- --install-dir="$DESTDIR"
fi fi
# Update Movim source code # Update Movim source code
(exec_cmd git fetch --quiet origin \ (exec_cmd git fetch origin \
&& exec_cmd git reset --quiet --hard "$HEAD_COMMIT") \ && exec_cmd git reset --hard "$HEAD_COMMIT") \
|| ynh_die "Unable to download Movim source code." || ynh_die "Unable to download Movim source code."
## FIXME: consider installation in a subpath ## FIXME: consider installation in a subpath
exec_cmd sed -i "s@'/ws/'@'${path%/}/ws/'@g" \ exec_cmd sed -i "s@'/ws/'@'${path%/}/ws/'@g" \
@ -61,7 +68,7 @@ sudo chmod 400 "${DESTDIR}/config/db.inc.php"
# Update PHP dependencies using composer # Update PHP dependencies using composer
(exec_cmd php composer.phar config --global discard-changes true \ (exec_cmd php composer.phar config --global discard-changes true \
&& exec_cmd php composer.phar install --quiet --no-interaction) \ && exec_cmd php composer.phar install --no-interaction) \
|| ynh_die "Unable to update Movim dependencies." || ynh_die "Unable to update Movim dependencies."
# Upgrade Movim database as needed # Upgrade Movim database as needed
@ -75,16 +82,17 @@ sudo yunohost app clearaccess movim
# Replace old public_site variable (if exists) by ssoenabled # Replace old public_site variable (if exists) by ssoenabled
if [ ! -z "$public_site" ]; then if [ ! -z "$public_site" ]; then
[[ $public_site = "Yes" ]] \ [[ $public_site = "Yes" ]] \
&& ssoenabled=0 \ && ssoenabled="No" \
|| ssoenabled=1 || ssoenabled="Yes"
ynh_app_setting_delete "$app" public_site ynh_app_setting_delete "$app" public_site
ynh_app_setting_set "$app" ssoenabled "$ssoenabled" ynh_app_setting_set "$app" ssoenabled "$ssoenabled"
fi fi
# SSOwat configuration # SSOwat configuration
if [[ "$ssoenabled" =~ ^0|No$ ]]; then if [[ "$ssoenabled" = "No" ]]; then
ynh_app_setting_set "$app" skipped_uris "/" ynh_app_setting_set "$app" skipped_uris "/"
exec_cmd php mud.php config --xmppwhitelist=$domain exec_cmd php mud.php config --xmppwhitelist=$domain
sudo yunohost app ssowatconf
else else
ynh_app_setting_set "$app" unprotected_uris "/" ynh_app_setting_set "$app" unprotected_uris "/"
apply_sso_patch apply_sso_patch
@ -97,7 +105,7 @@ sudo sed -i "s@YHPORT@${port}@g" ../conf/movim.{service,init}
if [ -d /run/systemd/system ]; then if [ -d /run/systemd/system ]; then
sudo rm -f /lib/systemd/system/movim.service sudo rm -f /lib/systemd/system/movim.service
sudo cp ../conf/movim.service /etc/systemd/system/ sudo cp ../conf/movim.service /etc/systemd/system/
sudo systemctl --quiet daemon-reload sudo systemctl daemon-reload
else else
sudo /etc/init.d/movim stop sudo /etc/init.d/movim stop
sudo cp ../conf/movim.init /etc/init.d/movim sudo cp ../conf/movim.init /etc/init.d/movim