mirror of
https://github.com/YunoHost-Apps/ethercalc_ynh.git
synced 2024-09-03 18:26:36 +02:00
Code refactoring
This commit is contained in:
parent
60b0eca12a
commit
fe3e122025
1 changed files with 195 additions and 79 deletions
274
scripts/install
274
scripts/install
|
@ -1,92 +1,208 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
app="ethercalc"
|
#=================================================
|
||||||
name="ether"
|
# GENERIC START
|
||||||
name+="calc"
|
#=================================================
|
||||||
instance_number=$(echo $app | sed 's/[^0-9]//g')
|
# IMPORT GENERIC HELPERS
|
||||||
# Retrieve arguments
|
#=================================================
|
||||||
domain=$1
|
|
||||||
path=$2
|
|
||||||
is_public=$3
|
|
||||||
expire=$4
|
|
||||||
port=$((instance_number+8000))
|
|
||||||
|
|
||||||
# Check domain/path availability
|
source _common.sh
|
||||||
sudo yunohost app checkurl $domain$path -a $app
|
source /usr/share/yunohost/helpers
|
||||||
if [[ ! $? -eq 0 ]]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Register configuration..."
|
#=================================================
|
||||||
sudo yunohost app setting $app is_public -v $is_public
|
# MANAGE SCRIPT FAILURE
|
||||||
sudo yunohost app setting $app port -v $port
|
#=================================================
|
||||||
sudo yunohost app setting $app expire -v $expire
|
|
||||||
|
|
||||||
# Remove trailing "/" for next commands
|
# Exit if an error occurs during the execution of the script
|
||||||
path=${path%/}
|
ynh_abort_if_errors
|
||||||
|
|
||||||
echo "Install dependencies..."
|
#=================================================
|
||||||
sudo apt-get update
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||||
sudo apt-get install nodejs-legacy npm redis-server -y
|
#=================================================
|
||||||
|
|
||||||
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
|
path_url=$YNH_APP_ARG_PATH
|
||||||
|
admin=$YNH_APP_ARG_ADMIN
|
||||||
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
|
language=$YNH_APP_ARG_LANGUAGE
|
||||||
|
|
||||||
|
# This is a multi-instance app, meaning it can be installed several times independently
|
||||||
|
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||||
|
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
||||||
|
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
||||||
|
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
||||||
|
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
||||||
|
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
||||||
|
# The app instance name is probably what you are interested the most, since this is
|
||||||
|
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
||||||
|
# db names, ...
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Normalize the url path syntax
|
||||||
|
path_url=$(ynh_normalize_url_path $path_url)
|
||||||
|
|
||||||
|
# Check web path availability
|
||||||
|
ynh_webpath_available $domain $path_url
|
||||||
|
# Register (book) web path
|
||||||
|
ynh_webpath_register $app $domain $path_url
|
||||||
|
|
||||||
echo "Installing EtherCalc with NPM..."
|
|
||||||
final_path=/var/www/$app
|
final_path=/var/www/$app
|
||||||
sudo mkdir -p $final_path
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
sudo useradd -d $final_path $app
|
|
||||||
sudo chown -R $app: $final_path
|
|
||||||
sudo su --shell /bin/bash --command "cd $final_path/ && npm install --production $name" $app
|
|
||||||
|
|
||||||
echo "Cleaning up install tree..."
|
#=================================================
|
||||||
sudo rm -rf $final_path/.npm
|
# STORE SETTINGS FROM MANIFEST
|
||||||
find $final_path -type d | grep "test$" | xargs sudo rm -rf
|
#=================================================
|
||||||
find $final_path -type d | grep "tests$" | xargs sudo rm -rf
|
|
||||||
|
|
||||||
echo "Setting up permissions"
|
ynh_app_setting_set $app domain $domain
|
||||||
|
ynh_app_setting_set $app path $path_url
|
||||||
|
ynh_app_setting_set $app admin $admin
|
||||||
|
ynh_app_setting_set $app is_public $is_public
|
||||||
|
ynh_app_setting_set $app language $language
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD MODIFICATIONS
|
||||||
|
#=================================================
|
||||||
|
# FIND AND OPEN A PORT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Find a free port
|
||||||
|
port=$(ynh_find_port 8095)
|
||||||
|
# Open this port
|
||||||
|
sudo yunohost firewall allow --no-upnp TCP $port 2>&1
|
||||||
|
ynh_app_setting_set $app port $port
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# INSTALL NODEJS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_install_nodejs 4.8.3
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# INSTALL DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE A MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
# If your app uses a MySQL database, you can use these lines to bootstrap
|
||||||
|
# a database, an associated user and save the password in app settings
|
||||||
|
|
||||||
|
db_name=$(ynh_sanitize_dbid $app)
|
||||||
|
ynh_app_setting_set $app db_name $db_name
|
||||||
|
ynh_mysql_setup_db $db_name $db_name
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# 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
|
||||||
|
ynh_setup_source "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a system user
|
||||||
|
ynh_system_user_create $app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# PHP-FPM CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated php-fpm config
|
||||||
|
ynh_fpm_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC SETUP
|
||||||
|
#=================================================
|
||||||
|
# ...
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SYSTEMD
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a dedicated systemd config
|
||||||
|
ynh_systemd_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP APPLICATION WITH CURL
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Set right permissions for curl install
|
||||||
sudo chown -R $app: $final_path
|
sudo chown -R $app: $final_path
|
||||||
|
|
||||||
echo "Setting up init script..."
|
# Set the app as temporarily public for curl call
|
||||||
logfile=/var/log/$name/$app.log
|
ynh_app_setting_set $app unprotected_uris "/"
|
||||||
sed -i "s@YUNOPORT@$port@g" ../conf/$name
|
# Reload SSOwat config
|
||||||
sed -i "s@YUNOLOG@$app@g" ../conf/$name
|
|
||||||
sed -i "s@YUNOPATH@$path@g" ../conf/$name
|
|
||||||
sed -i "s@YUNOAPP@$app@g" ../conf/$name
|
|
||||||
if [ "$expire" -eq 0 ]; then
|
|
||||||
expire=""
|
|
||||||
else
|
|
||||||
expire="--expire $(($expire * 86400))"
|
|
||||||
fi
|
|
||||||
sed -i "s@YUNOEXPIRE@$expire@g" ../conf/$name
|
|
||||||
sudo cp ../conf/$name /etc/init.d/$app
|
|
||||||
sudo chmod +x /etc/init.d/$app
|
|
||||||
sudo update-rc.d $app defaults
|
|
||||||
if [ ! -d "/var/log/$name/" ]; then
|
|
||||||
sudo mkdir /var/log/$name/
|
|
||||||
fi
|
|
||||||
sudo touch $logfile
|
|
||||||
sudo chown $app $logfile
|
|
||||||
sudo service $app stop
|
|
||||||
sudo service $app start
|
|
||||||
sudo yunohost service add $app -l $logfile
|
|
||||||
|
|
||||||
echo "Setting up logrotate configuration..."
|
|
||||||
sed -i "s@YNH_LOGFILE@$logfile@g" ../conf/logrotate
|
|
||||||
sudo cp ../conf/logrotate /etc/logrotate.d/$app
|
|
||||||
|
|
||||||
echo "Nginx configuration ..."
|
|
||||||
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf*
|
|
||||||
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf*
|
|
||||||
sed -i "s@YUNOPORT@$port@g" ../conf/nginx.conf*
|
|
||||||
if [ "$path" = "" ];
|
|
||||||
then
|
|
||||||
sudo cp ../conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
else
|
|
||||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Reloading Nginx..."
|
|
||||||
sudo service nginx reload
|
|
||||||
if [ "$is_public" = "Yes" ];
|
|
||||||
then
|
|
||||||
sudo yunohost app setting ethercalc skipped_uris -v "/"
|
|
||||||
fi
|
|
||||||
sudo yunohost app ssowatconf
|
sudo yunohost app ssowatconf
|
||||||
|
|
||||||
|
# Reload Nginx
|
||||||
|
sudo systemctl reload nginx
|
||||||
|
|
||||||
|
# Installation with curl
|
||||||
|
ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STORE THE CHECKSUM OF THE CONFIG FILE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Calculate and store the config file checksum into the app settings
|
||||||
|
ynh_store_file_checksum "$final_path/CONFIG_FILE"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# SECURE FILES AND DIRECTORIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Set permissions to app files
|
||||||
|
sudo chown -R root: $final_path
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Use logrotate to manage application logfile(s)
|
||||||
|
ynh_use_logrotate
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
sudo yunohost service add $app --log "/var/log/ethercalc.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
if [ $is_public -eq 0 ]
|
||||||
|
then # Remove the public access
|
||||||
|
ynh_app_setting_delete $app skipped_uris
|
||||||
|
fi
|
||||||
|
# Make app public if necessary
|
||||||
|
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
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
sudo systemctl reload nginx
|
||||||
|
|
Loading…
Add table
Reference in a new issue