2016-10-25 00:00:01 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-10-25 00:00:01 +02:00
|
|
|
|
2017-09-26 21:08:01 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE FAILURE OF THE SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2016-10-25 00:00:01 +02:00
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2017-10-09 17:08:29 +02:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2016-10-25 00:00:01 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
2017-10-13 18:06:42 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
|
|
#=================================================
|
2016-10-25 00:00:01 +02:00
|
|
|
|
2017-10-09 17:11:05 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
# Normalize the url path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
if [ "$path_url" != "/" ]; then
|
|
|
|
ynh_die "Only / is allowed"
|
|
|
|
fi
|
|
|
|
|
2017-10-09 17:11:05 +02:00
|
|
|
# Check web path availability
|
|
|
|
ynh_webpath_available $domain $path_url
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set $app domain "$domain"
|
|
|
|
ynh_app_setting_set $app is_public "$is_public"
|
2017-10-09 17:12:30 +02:00
|
|
|
ynh_app_setting_set $app path_url "$path_url"
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-13 19:07:49 +02:00
|
|
|
# Find a free port
|
2017-10-14 15:36:26 +02:00
|
|
|
port=$(ynh_find_port 7777)
|
2017-09-26 21:08:01 +02:00
|
|
|
ynh_app_setting_set $app port $port
|
2017-11-29 15:42:21 +01:00
|
|
|
echo "port=$port" >&2
|
|
|
|
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# INSTALL NODEJS
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
ynh_install_nodejs 4
|
2017-09-26 21:08:01 +02:00
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
#=================================================
|
|
|
|
# ADD SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2017-09-26 21:08:01 +02:00
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
|
|
|
|
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
|
|
|
ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" "../conf/systemd.service"
|
|
|
|
|
|
|
|
ynh_add_systemd_config
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# INSTALL HASTEBIN
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
ynh_use_nodejs
|
2016-10-25 00:00:01 +02:00
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
(cd "$final_path"
|
|
|
|
chown -R $app: "$final_path"
|
|
|
|
npm install)
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# CREATE DIRECTORY FOR DATA
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
data_path="/home/yunohost.app/$app"
|
|
|
|
mkdir -p "$data_path"
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# CONFIGURE HASTE
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
cp ../conf/config.js "$final_path/config.js"
|
|
|
|
ynh_replace_string "__PORT__" "$port" "$final_path/config.js"
|
|
|
|
ynh_replace_string "__YNH_DATA_PATH__" "$data_path" "$final_path/config.js"
|
|
|
|
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum "$final_path/config.js"
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# ADD HASTE AS A BINARY FILE
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
ynh_replace_string "__YNH_HASTE_URL__" "${domain}${path_url}" "../conf/haste.sh"
|
|
|
|
sudo cp ../conf/haste.sh /usr/bin/$app
|
|
|
|
sudo chmod +x /usr/bin/"$app"
|
|
|
|
echo "Please use 'cmd | $app' to paste the output of the command to your Haste server." >&2
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
chown -R root: $final_path
|
|
|
|
chown -R $app "$final_path/static"
|
|
|
|
chown -R $app "$data_path"
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# HANDLE LOG FILES AND SETUP LOGROTATE
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
mkdir -p /var/log/$app
|
|
|
|
touch /var/log/$app/$app.log
|
|
|
|
chown $app -R /var/log/$app
|
|
|
|
ynh_use_logrotate
|
2017-09-26 21:08:01 +02:00
|
|
|
|
2017-10-13 18:58:51 +02:00
|
|
|
#=================================================
|
2017-09-26 21:08:01 +02:00
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-13 18:22:29 +02:00
|
|
|
yunohost service add $app --log "/var/log/$app/$app.log"
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# START HASTEBIN
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-10-13 18:22:29 +02:00
|
|
|
systemctl start $app
|
2017-09-26 21:08:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ $is_public -eq 1 ];
|
|
|
|
then
|
2017-11-29 15:42:21 +01:00
|
|
|
ynh_app_setting_set $app skipped_uris "/"
|
2017-09-26 21:08:01 +02:00
|
|
|
fi
|
2016-10-25 00:00:01 +02:00
|
|
|
|
2017-09-26 21:08:01 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2016-10-25 00:00:01 +02:00
|
|
|
|
2017-10-13 18:22:29 +02:00
|
|
|
systemctl reload nginx
|