mirror of
https://github.com/YunoHost-Apps/framagames_ynh.git
synced 2024-09-03 18:36:28 +02:00
Adjustments to scripts
This commit is contained in:
parent
9ee1ba6d57
commit
6f51b2feb6
3 changed files with 11 additions and 139 deletions
|
@ -40,18 +40,6 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path=$YNH_APP_ARG_PATH
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
runninguser=$YNH_APP_ARG_RUNNINGUSER
|
||||
calibre=$YNH_APP_ARG_CALIBRE
|
||||
|
||||
# No basic auth if app is private
|
||||
if [ "$is_public" = "Yes" ];
|
||||
then
|
||||
basicauthcreate=$YNH_APP_ARG_BASICAUTHCREATE
|
||||
basicauthname=$YNH_APP_ARG_BASICAUTHNAME
|
||||
basicauthpass=$YNH_APP_ARG_BASICAUTHPASS
|
||||
else
|
||||
basicauthcreate="No"
|
||||
fi
|
||||
|
||||
# We check variables are not empty
|
||||
CHECK_VAR () { # Vérifie que la variable n'est pas vide.
|
||||
|
@ -93,18 +81,6 @@ CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déj
|
|||
|
||||
CHECK_FINALPATH
|
||||
|
||||
# We check that calibre path is correct
|
||||
CHECK_CALIBRE () { # Vérifie la présence du / en début de path. Et son absence à la fin.
|
||||
if [ "${calibre:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
|
||||
calibre="/$calibre" # Ajoute un / en début de path
|
||||
fi
|
||||
if [ "${calibre:${#calibre}-1}" == "/" ] && [ ${#calibre} -gt 1 ]; then # Si le dernier caractère est un / $
|
||||
calibre="${calibre:0:${#calibre}-1}" # Supprime le dernier caractère
|
||||
fi
|
||||
}
|
||||
|
||||
CHECK_CALIBRE;
|
||||
|
||||
final_path=/var/www/$app
|
||||
|
||||
# Define variables and Save app settings
|
||||
|
@ -112,9 +88,6 @@ ynh_app_setting_set "$app" domain "$domain"
|
|||
#ynh_app_setting_set "$app" path "$path"
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
ynh_app_setting_set "$app" final_path "$final_path"
|
||||
ynh_app_setting_set "$app" runninguser "$runninguser"
|
||||
ynh_app_setting_set "$app" calibre "$calibre"
|
||||
ynh_app_setting_set "$app" basicauthcreate "$basicauthcreate"
|
||||
|
||||
finalnginxconf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
ynh_app_setting_set "$app" finalnginxconf "$finalnginxconf"
|
||||
|
@ -122,54 +95,18 @@ ynh_app_setting_set "$app" finalnginxconf "$finalnginxconf"
|
|||
finalphpconf="/etc/php5/fpm/pool.d/${app}.conf"
|
||||
ynh_app_setting_set "$app" finalphpconf "$finalphpconf"
|
||||
|
||||
# We install dependencies
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install php5-gd php5-sqlite php5-json php5-intl -y
|
||||
|
||||
# Creation of folder
|
||||
sudo mkdir -p $final_path
|
||||
|
||||
# We download the sources and check the md5sum
|
||||
cops_file=`sudo cat ../sources/source_file`;
|
||||
sudo wget -nv -i ../sources/source_url -O $cops_file
|
||||
sudo md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
|
||||
sudo unzip ${cops_file} -d $final_path
|
||||
|
||||
# Site adjustments
|
||||
sed -i "s@CALIBRETOCHANGE@$calibre@g" ../conf/config_local.php
|
||||
timezone=`sudo cat /etc/timezone`;
|
||||
sed -i "s@TIMEZONETOCHANGE@$timezone@g" ../conf/config_local.php
|
||||
|
||||
sudo cp ../conf/config_local.php $final_path
|
||||
sudo cp ../conf/robots.txt $final_path
|
||||
#cops_file=`sudo cat ../sources/source_file`;
|
||||
#sudo wget -nv -i ../sources/source_url -O $cops_file
|
||||
#sudo md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
|
||||
#sudo unzip ${cops_file} -d $final_path
|
||||
|
||||
# Set permissions
|
||||
sudo chmod 775 -R $final_path
|
||||
sudo chown -hR $runninguser:$runninguser $final_path
|
||||
|
||||
# Add basic auth if requested
|
||||
if [ "$basicauthcreate" = "Yes" ];
|
||||
then
|
||||
ynh_app_setting_set "$app" basicauthname "$basicauthname"
|
||||
ynh_app_setting_set "$app" basicauthpass "$basicauthpass"
|
||||
|
||||
# Generation of the htpasswd file according https://www.nginx.com/resources/wiki/community/faq/
|
||||
SALT="$(openssl rand -base64 3)"
|
||||
(SHA1=$(printf "$basicauthpass$SALT" |
|
||||
openssl dgst -binary -sha1 | xxd -ps |
|
||||
sed 's#$#'"`echo -n $SALT | xxd -ps`"'#' |
|
||||
xxd -r -ps |
|
||||
base64);printf "$basicauthname:{SSHA}$SHA1\n" >> ../sources/htpasswd)
|
||||
sudo cp ../sources/htpasswd $final_path
|
||||
sudo chmod 440 $final_path/htpasswd
|
||||
sudo chown www-data:www-data $final_path/htpasswd
|
||||
|
||||
# Modif nginx
|
||||
sed -i "s|^.*\bauth_basic\b.*$| auth_basic \"Private Library\";|" ../conf/nginx.conf;
|
||||
sed -i "s|^.*\bauth_basic_user_file\b.*$| auth_basic_user_file $final_path/htpasswd;|" ../conf/nginx.conf;
|
||||
else
|
||||
echo "No basic auth";
|
||||
fi
|
||||
sudo chown -hR www-data:www-data $final_path
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf.d directory
|
||||
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
||||
|
|
|
@ -26,12 +26,6 @@ domain=$(ynh_app_setting_get $app domain)
|
|||
is_public=$(ynh_app_setting_get $app is_public)
|
||||
finalnginxconf=$(ynh_app_setting_get $app finalnginxconf)
|
||||
finalphpconf=$(ynh_app_setting_get $app finalphpconf)
|
||||
runninguser=$(ynh_app_setting_get $app runninguser)
|
||||
basicauthcreate=$(ynh_app_setting_get $app basicauthcreate)
|
||||
|
||||
# We install dependencies
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install php5-gd php5-sqlite php5-json php5-intl -y
|
||||
|
||||
# Restore sources & data
|
||||
sudo mkdir -p $final_path
|
||||
|
@ -39,15 +33,7 @@ sudo cp -a ./sources/* $final_path/
|
|||
|
||||
# Restore permissions to app files
|
||||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
||||
sudo chown -R $runninguser:$runninguser $final_path
|
||||
|
||||
if [ "$basicauthcreate" = "Yes" ];
|
||||
then
|
||||
sudo chmod 440 $final_path/htpasswd
|
||||
sudo chown www-data:www-data $final_path/htpasswd
|
||||
else
|
||||
echo "Nothing to do"
|
||||
fi
|
||||
sudo chown -R www-data:www-data $final_path
|
||||
|
||||
# Restore NGINX configuration
|
||||
sudo cp -a ./nginx.conf $finalnginxconf
|
||||
|
|
|
@ -26,71 +26,20 @@ domain=$(ynh_app_setting_get $app domain)
|
|||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
finalnginxconf=$(ynh_app_setting_get $app finalnginxconf)
|
||||
finalphpconf=$(ynh_app_setting_get $app finalphpconf)
|
||||
runninguser=$(ynh_app_setting_get $app runninguser)
|
||||
calibre=$(ynh_app_setting_get $app calibre)
|
||||
basicauthcreate=$(ynh_app_setting_get $app basicauthcreate)
|
||||
|
||||
# We check that calibre path is correct
|
||||
CHECK_CALIBRE () { # Vérifie la présence du / en début de path. Et son absence à la fin.
|
||||
if [ "${calibre:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
|
||||
calibre="/$calibre" # Ajoute un / en début de path
|
||||
fi
|
||||
if [ "${calibre:${#calibre}-1}" == "/" ] && [ ${#calibre} -gt 1 ]; then # Si le dernier caractère est un / $
|
||||
calibre="${calibre:0:${#calibre}-1}" # Supprime le dernier caractère
|
||||
fi
|
||||
}
|
||||
|
||||
CHECK_CALIBRE
|
||||
|
||||
# We install dependencies
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install php5-gd php5-sqlite php5-json php5-intl -y
|
||||
|
||||
# Removal of old folder and restart from fresh
|
||||
sudo rm -rf $final_path
|
||||
sudo mkdir -p $final_path
|
||||
|
||||
# We download the sources and check the md5sum
|
||||
cops_file=`sudo cat ../sources/source_file`;
|
||||
sudo wget -nv -i ../sources/source_url -O $cops_file
|
||||
sudo md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
|
||||
sudo unzip ${cops_file} -d $final_path
|
||||
|
||||
# Site adjustments
|
||||
sed -i "s@CALIBRETOCHANGE@$calibrepath@g" ../conf/config_local.php
|
||||
timezone=`sudo cat /etc/timezone`;
|
||||
sed -i "s@TIMEZONETOCHANGE@$timezone@g" ../conf/config_local.php
|
||||
|
||||
sudo cp ../conf/config_local.php $final_path
|
||||
sudo cp ../conf/robots.txt $final_path
|
||||
#cops_file=`sudo cat ../sources/source_file`;
|
||||
#sudo wget -nv -i ../sources/source_url -O $cops_file
|
||||
#sudo md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
|
||||
#sudo unzip ${cops_file} -d $final_path
|
||||
|
||||
# Set permissions
|
||||
sudo chmod 775 -R $final_path
|
||||
sudo chown -hR $runninguser:$runninguser $final_path
|
||||
|
||||
# Add basic auth if requested
|
||||
if [ "$basicauthcreate" = "Yes" ];
|
||||
then
|
||||
basicauthname=$(ynh_app_setting_get $app basicauthname)
|
||||
basicauthpass=$(ynh_app_setting_get $app basicauthpass)
|
||||
|
||||
# Generation of the htpasswd file according https://www.nginx.com/resources/wiki/community/faq/
|
||||
SALT="$(openssl rand -base64 3)"
|
||||
(SHA1=$(printf "$basicauthpass$SALT" |
|
||||
openssl dgst -binary -sha1 | xxd -ps |
|
||||
sed 's#$#'"`echo -n $SALT | xxd -ps`"'#' |
|
||||
xxd -r -ps |
|
||||
base64);printf "$basicauthname:{SSHA}$SHA1\n" >> ../sources/htpasswd)
|
||||
sudo cp ../sources/htpasswd $final_path
|
||||
sudo chmod 440 $final_path/htpasswd
|
||||
sudo chown www-data:www-data $final_path/htpasswd
|
||||
|
||||
# Modif nginx
|
||||
sed -i "s|^.*\bauth_basic\b.*$| auth_basic \"Private Library\";|" ../conf/nginx.conf;
|
||||
sed -i "s|^.*\bauth_basic_user_file\b.*$| auth_basic_user_file $final_path/htpasswd;|" ../conf/nginx.conf;
|
||||
else
|
||||
echo "No basic auth";
|
||||
fi
|
||||
sudo chown -hR www-data:www-data $final_path
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf.d directory
|
||||
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
||||
|
|
Loading…
Reference in a new issue