2016-10-25 00:00:01 +02:00
|
|
|
#
|
|
|
|
# Common variables
|
|
|
|
#
|
|
|
|
|
|
|
|
APPNAME="haste"
|
2016-10-25 23:34:42 +02:00
|
|
|
app=${YNH_APP_INSTANCE_NAME:-haste}
|
2016-10-25 00:00:01 +02:00
|
|
|
|
2016-10-25 23:34:42 +02:00
|
|
|
# Haste version
|
2016-10-25 00:00:01 +02:00
|
|
|
VERSION="master"
|
|
|
|
|
2016-10-25 23:34:42 +02:00
|
|
|
# set globals variables
|
|
|
|
DESTDIR="/opt/"${app}
|
|
|
|
DATA_PATH="/home/yunohost.app/"$app
|
|
|
|
|
2016-10-25 00:00:01 +02:00
|
|
|
# Remote URL to fetch Haste tarball
|
|
|
|
HASTE_URL="https://github.com/seejohnrun/haste-server/archive/"${VERSION}".zip"
|
|
|
|
|
2016-10-25 23:34:42 +02:00
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2016-10-25 00:00:01 +02:00
|
|
|
#
|
|
|
|
# Common helpers
|
|
|
|
#
|
|
|
|
|
2016-10-25 23:34:42 +02:00
|
|
|
check_or_install_npm() {
|
2016-10-26 00:28:51 +02:00
|
|
|
if ! dpkg -s npm | grep "installed" > /dev/null 2>&1 \
|
|
|
|
|| dpkg -s nodejs-legacy | grep "installed" > /dev/null 2>&1; then
|
2016-10-25 23:34:42 +02:00
|
|
|
sudo apt-get update
|
2016-10-26 00:28:51 +02:00
|
|
|
sudo apt-get install -y npm nodejs-legacy
|
2016-10-25 23:34:42 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
pre_inst_haste() {
|
|
|
|
# retrieve, extract, copy haste, add user if necessary
|
2016-10-25 00:00:01 +02:00
|
|
|
local TMPDIR=$(mktemp -d)
|
2016-10-25 23:34:42 +02:00
|
|
|
local HASTE_SOURCE=$1
|
|
|
|
|
|
|
|
# Check destination directory
|
|
|
|
[[ -d $DESTDIR ]] && ynh_die \
|
|
|
|
"The destination directory '$DESTDIR' already exists.\
|
|
|
|
You should safely delete it before restoring this app."
|
|
|
|
|
|
|
|
# Check configuration files
|
|
|
|
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|
|
|
[[ -f $nginx_conf ]] && ynh_die \
|
|
|
|
"The NGINX configuration already exists at '${nginx_conf}'.
|
|
|
|
You should safely delete it before restoring this app."
|
2016-10-25 00:00:01 +02:00
|
|
|
|
|
|
|
haste_tarball="/tmp/haste.zip"
|
|
|
|
rm -f "$haste_tarball"
|
2016-10-25 23:34:42 +02:00
|
|
|
if [ "$HASTE_SOURCE" = "backup" ]
|
|
|
|
then
|
|
|
|
# Restore the app and data files
|
|
|
|
sudo cp -a ./www "$DESTDIR"
|
|
|
|
sudo cp -a ./data/. "$DATA_PATH"
|
|
|
|
# Restore directories and permissions
|
|
|
|
sudo chown -R "$app":"$app" "$DESTDIR" "$DATA_PATH"
|
|
|
|
else
|
|
|
|
wget -q -O "$haste_tarball" "$HASTE_URL" \
|
|
|
|
|| ynh_die "Unable to download haste"
|
|
|
|
unzip -q "$haste_tarball" -d "$TMPDIR" \
|
|
|
|
|| ynh_die "Unable to extract haste"
|
|
|
|
sudo rsync -a "$TMPDIR"/haste-server-master/* "$DESTDIR"
|
|
|
|
fi
|
2016-10-25 00:00:01 +02:00
|
|
|
rm -rf "$haste_tarball" "$TMPDIR"
|
|
|
|
|
2016-10-25 23:34:42 +02:00
|
|
|
# Add user if not exist
|
|
|
|
id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet
|
|
|
|
id -u "$app" &>/dev/null || sudo adduser "$app" \
|
|
|
|
--ingroup "$app" --system --quiet --shell /bin/bash
|
|
|
|
|
|
|
|
# Configure init script
|
|
|
|
sudo cp ../conf/"$app".service /etc/systemd/system/
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl enable "$app".service
|
|
|
|
}
|
|
|
|
|
|
|
|
# Download, extract and install Haste to the given directory
|
|
|
|
# usage: install_haste DESTDIR
|
|
|
|
install_haste() {
|
|
|
|
local DOMAIN=$1
|
2016-10-26 00:05:54 +02:00
|
|
|
local YNH_PATH=$2
|
2016-10-25 23:34:42 +02:00
|
|
|
local IS_PUBLIC=$3
|
|
|
|
|
|
|
|
check_or_install_npm
|
2016-10-26 00:05:54 +02:00
|
|
|
pre_inst_haste none
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2016-10-25 00:00:01 +02:00
|
|
|
# install haste
|
|
|
|
current_dir=$(pwd)
|
|
|
|
cd "$DESTDIR"
|
|
|
|
sudo npm install
|
|
|
|
cd $current_dir
|
2016-10-25 23:34:42 +02:00
|
|
|
|
|
|
|
sudo mkdir -p $DATA_PATH
|
|
|
|
sudo chown -R "$app":"$app" $DESTDIR $DATA_PATH
|
|
|
|
|
|
|
|
# Configure haste with config.js file
|
|
|
|
sudo cp ../conf/config.js "$DESTDIR"/config.js
|
|
|
|
sudo sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$DESTDIR"/config.js
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
2016-10-26 00:05:54 +02:00
|
|
|
sed -i "s@PATHTOCHANGE@${YNH_PATH%/}@g" ../conf/nginx.conf
|
2016-10-25 23:34:42 +02:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/"$app".conf
|
|
|
|
|
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris
|
|
|
|
if [[ $IS_PUBLIC -eq 1 ]]; then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Reload services
|
|
|
|
sudo systemctl reload nginx.service
|
|
|
|
|
|
|
|
# install haste cli client
|
|
|
|
sed -i "s@YNH_HASTE_URL@${DOMAIN}${path%/}@g" ../conf/haste.sh
|
|
|
|
sudo cp ../conf/haste.sh /usr/bin/"$app"
|
|
|
|
sudo chmod +x /usr/bin/"$app"
|
2016-10-25 00:00:01 +02:00
|
|
|
}
|