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

Merge pull request #18 from kay0u/fix-scripts

Fix scripts
This commit is contained in:
frju365 2019-02-03 01:37:54 +01:00 committed by GitHub
commit 33a0c5b572
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 292 additions and 179 deletions

View file

@ -1,10 +1,70 @@
# Lstu app for YunoHost
![WTFPL](http://www.wtfpl.net/wp-content/uploads/2012/12/wtfpl-badge-1.png)
[![Integration level](https://dash.yunohost.org/integration/lstu.svg)](https://dash.yunohost.org/appci/app/lstu)
[![Install lstu with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=lstu)
# lstu_ynh
> *This package allow you to install lstu quickly and simply on a YunoHost server.
If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.*
Seems to work, but need some testing.
## Overview
Lstu means Let's Shorten That Url.
**Shipped version:** 0.21-4
## Screenshots
![](https://framalibre.org/sites/default/files/Screenshot_20161213_120016_1.png)
## Demo
* [Official demo](https://lstu.fr)
## Configuration
How to configure this app: a plain file with SSH.
## Documentation
* Official documentation: https://framagit.org/fiat-tux/hat-softwares/lstu/wikis/home
## YunoHost specific features
#### Multi-users support
Are LDAP and HTTP auth supported? **Not yet**
Can the app be used by multiple users? **Yes**
#### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/lstu%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/lstu/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/lstu%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/lstu/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/lstu%20%28Community%29.svg)](https://ci-stretch.nohost.me/ci/apps/lstu/)
**More information on the documentation page:**
https://yunohost.org/packaging_apps
## Links
* Report a bug: https://github.com/YunoHost-Apps/lstu_ynh/issues
* App website: https://framagit.org/fiat-tux/hat-softwares/lstu
* YunoHost website: https://yunohost.org/
---
Developers info
----------------
**Only if you want to use a testing branch for coding, instead of merging directly into master.**
Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/lstu_ynh/tree/testing).
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/lstu_ynh/tree/testing --debug
or
sudo yunohost app upgrade lstu -u https://github.com/YunoHost-Apps/lstu_ynh/tree/testing --debug
```
## Todo
- [ ] Integrate with LDAP
@ -12,12 +72,4 @@ Seems to work, but need some testing.
- [ ] Allow to choose the database (sqlite or PostgreSQL)
- [ ] Allow to choose to use Minion
- [ ] Add CI stuff
# Contributing
To contribute see the package lutim_ynh as example.
Pour contribuer regardez le paquet lutim_ynh comme exemple.
lutim_ynh : https://github.com/YunoHost-Apps/lutim_ynh
Site officiel de lstu: https://framagit.org/luc/lstu
- [ ] Theme choice (default or milligram)

View file

@ -1,6 +1,5 @@
SOURCE_URL=https://framagit.org/fiat-tux/hat-softwares/lstu/-/archive/4388fad97387b5db4a12e7ce64d8c233d55b0a37/lstu-4388fad97387b5db4a12e7ce64d8c233d55b0a37.tar.gz
SOURCE_SUM=5bd073fb1129c1a16e3201b93fb340802c85772fb6f509bb3ee71b35793d2d33
SOURCE_URL=https://framagit.org/fiat-tux/hat-softwares/lstu/-/archive/0.21-4/lstu-0.21-4.tar.gz
SOURCE_SUM=28edf507a13e02917e55bd269c980739eaf9bcaf6924d51c432f1b3ed9cd4259
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

View file

@ -8,6 +8,8 @@ After=network.target
Type=forking
User=www-data
RemainAfterExit=yes
Restart=always
RestartSec=10
WorkingDirectory=__FINALPATH__
PIDFile=__FINALPATH__/script/hypnotoad.pid
ExecStart=/usr/local/bin/carton exec hypnotoad script/lstu

View file

@ -2,6 +2,7 @@
"name": "Lstu",
"id": "lstu",
"packaging_format": 1,
"version": "0.21-4~ynh1",
"requirements": {
"yunohost": ">= 2.4"
},

View file

@ -1,27 +1,65 @@
#!/bin/bash
# vim:set noexpandtab:
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source app helpers
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
# Get multi-instances specific variables
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
# Copy the app files
final_path="/var/www/${app}"
ynh_backup "${final_path}" "sources" 1
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
# Copy the nginx conf files
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
ynh_backup "$final_path"
# Copy the lstu conf file
ynh_backup "${final_path}/lstu.conf" "lstu.conf"
ynh_backup "/etc/systemd/system/lstu.service" "systemd_lstu.service"
ynh_backup "/etc/logrotate.d/${app}" "logrotate_lstu"
ynh_backup "/var/log/${app}/production.log" "production.log"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE POSTGRESQL DATABASE
#=================================================
ynh_psql_dump_db "$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service"

View file

@ -30,8 +30,6 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
script_dir=$PWD
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
@ -68,6 +66,7 @@ yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app port $port
ynh_app_setting_set $app path $path_url
#=================================================
# INSTALL DEPENDENCIES
@ -85,11 +84,10 @@ echo yes | sudo cpan Carton
ynh_psql_test_if_first_run
db_name=$(ynh_sanitize_dbid "$app")
db_user=$db_name
db_pwd=$(ynh_string_random)
ynh_app_setting_set $app db_pwd $db_pwd
ynh_app_setting_set "$app" db_name "$db_name"
# Initialize database and store postgres password for upgrade
ynh_psql_setup_db "$db_name" "$db_user"
ynh_app_setting_set "$app" db_name "$db_name"
db_pwd=$(ynh_app_setting_get $app psqlpwd) # Password created in ynh_psql_setup_db function
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -142,7 +140,9 @@ ynh_add_systemd_config
# Install lstu's dependencies via carton
#=================================================
carton install
pushd $final_path
carton install --deployment --without=sqlite --without=mysql
popd
#=================================================
# SETUP LOGROTATE
@ -165,8 +165,8 @@ yunohost service add $app --log "/var/log/$app.log"
ynh_app_setting_set $app skipped_uris "/"
if [ $is_public -eq 0 ];
then # If the app is private, only the shortened URLs are publics
if [ "$path" == "/" ]; then
path=""
if [ "$path_url" == "/" ]; then
path_url=""
fi
ynh_app_setting_set $app protected_regex "$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$"
else
@ -177,14 +177,14 @@ fi
# Configure owner
#=================================================
sudo chown -R $app:$app $final_path
sudo chown -R www-data $final_path
#=================================================
# Start lstu
#=================================================
systemctl enable lstu.service
systemctl start lstu.service
systemctl enable $app.service
systemctl start $app
#=================================================
# RELOAD NGINX

View file

@ -17,6 +17,8 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
db_user=$db_name
#=================================================
# STANDARD REMOVE
@ -27,16 +29,6 @@ domain=$(ynh_app_setting_get $app domain)
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
if yunohost service status | grep -q $app
then
echo "Remove $app service"
yunohost service remove $app
fi
#=================================================
# REMOVE APP MAIN DIR
#=================================================
@ -55,7 +47,7 @@ ynh_remove_nginx_config
# Delete Log
#=================================================
ynh_secure_remove "/var/log/$app/"
ynh_secure_remove "/var/log/$app.log"
#=================================================
# REMOVE LOGROTATE CONFIGURATION
@ -80,3 +72,9 @@ fi
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# REMOVE THE PostgreSQL DATABASE
#=================================================
ynh_psql_remove_db $db_name $db_user

View file

@ -1,97 +1,101 @@
#!/bin/bash
# vim:set noexpandtab:
# This restore script is adapted to Yunohost >=2.4
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source app helpers
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
# The parameter $app is the id of the app instance ex: ynhexample__2
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
# Get old parameter of the app
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
ynh_package_update
ynh_package_install build-essential libssl-dev libpq-dev
echo yes | sudo cpan Carton
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "${app}" \
|| ynh_die "Path not available: ${domain}${path}"
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
# Check $final_path
final_path="/var/www/${app}"
if [ -d "${final_path}" ]; then
ynh_die "There is already a directory: ${final_path}"
fi
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
# Check configuration files nginx
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
if [ -f "${nginx_conf}" ]; then
ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app."
fi
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
# Check configuration files lstu
lstu_conf="${final_path}/${app}.conf"
if [ -f "${lstu_conf}" ]; then
ynh_die "The LSTU CONF configuration already exists at '${lstu_conf}'. You should safely delete it before restoring this app."
fi
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
lstu_systemd="/etc/systemd/system/${app}.service"
if [ -f "${lstu_systemd}" ]; then
ynh_die "The LSTU SYSTEMD configuration already exists at '${lstu_systemd}'. You should safely delete it before restoring this app."
fi
ynh_restore_file "$final_path"
lstu_logrotate="/etc/logrotate.d/${app}"
if [ -f "${lstu_logrotate}" ]; then
ynh_die "The LSTU LOGROTATE configuration already exists at '${lstu_logrotate}'. You should safely delete it before restoring this app."
fi
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
lstu_log="/var/log/${app}/production.log"
if [ -f "${lstu_log}" ]; then
ynh_die "The LSTU LOG configuration already exists at '${lstu_log}'. You should safely delete it before restoring this app."
fi
db_pwd=$(ynh_app_setting_get $app psqlpwd)
ynh_psql_setup_db $db_name $db_name $db_pwd
ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
# Restore sources & data
sudo cp -a ./sources "${final_path}"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Set permissions
sudo chown -R www-data: "${final_path}"
# Define and install dependencies
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql
# Restore nginx configuration files
sudo cp -a ./nginx.conf "${nginx_conf}"
#=================================================
# RESTORE SYSTEMD
#=================================================
# Restore lstu configuration files
sudo cp -a ./lstu.conf "${lstu_conf}"
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
systemctl start $app
# Restore service
sudo cp -a ./systemd_lstu.service "${lstu_systemd}"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
sudo cp -a ./logrotate_lstu "${lstu_logrotate}"
yunohost service add $app --log "/var/log/$app.log"
# Create log production
sudo mkdir "/var/log/${app}/"
sudo cp -a ./production.log "${lstu_log}"
# Delete symbolic link and restore
sudo rm -fr "${final_path}/log/production.log"
sudo ln -s "/var/log/${app}/production.log" "${final_path}/log/production.log"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
# Reload lstu service
sudo systemctl daemon-reload
sudo systemctl start lstu.service
sudo systemctl enable lstu.service
ynh_restore_file "/etc/logrotate.d/$app"
# Set ssowat config
if [ $is_public -eq 0 ];
then
ynh_app_setting_delete $app skipped_uris
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
# Reload services
sudo systemctl reload nginx
sudo yunohost app ssowatconf
systemctl reload nginx
yunohost app ssowatconf

View file

@ -1,10 +1,7 @@
#!/bin/bash
# vim:set noexpandtab:
set -eu
#=================================================
# GENERIC STARTING
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -12,6 +9,17 @@ set -eu
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
@ -19,11 +27,14 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
path_url=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public)
port=$(ynh_app_setting_get $app port)
final_path=$(ynh_app_setting_get $app final_path)
secret=$(ynh_app_setting_get $app secret)
db_name=$(ynh_app_setting_get $app db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get $app psqlpwd)
#=================================================
# FIX OLD THINGS
@ -42,25 +53,20 @@ then # Si final_path n'est pas renseigné dans la config yunohost, cas d'ancien
final_path=/var/www/$app
fi
CHECK_PATH # Checks and corrects the syntax of the path.
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Get source
SETUP_SOURCE
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Copy Nginx configuration file
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Modify Nginx configuration file
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
if [ $is_public -eq 1 ];
then
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
fi
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
@ -68,65 +74,78 @@ fi
# SETUP LSTU
#=================================================
## Copie et configuration du fichier de conf.
CHECK_MD5_CONFIG "lstu.conf" "$final_path/lstu.conf" # Créé un backup du fichier de config si il a été modifié.
sudo cp ../conf/lstu.conf.template "$final_path/lstu.conf"
sudo sed -i "s@__DOMAIN__@$domain@g" "$final_path/lstu.conf"
sudo sed -i "s@__PATH__@$path@g" "$final_path/lstu.conf"
sudo sed -i "s@__PORT__@$port@g" "$final_path/lstu.conf"
sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lstu.conf"
STORE_MD5_CONFIG "lstu.conf" "$final_path/lstu.conf" # Réenregistre la somme de contrôle du fichier de config
ynh_backup_if_checksum_is_different "$final_path/lstu.conf"
cp ../conf/lstu.conf.template "${final_path}/lstu.conf"
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf"
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf"
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf"
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf"
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf"
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf"
#=================================================
# SETUP SYSTEMD
#=================================================
# Mise en place du script systemd
sudo systemctl stop $app
sudo cp ../conf/lstu.service /etc/systemd/system/$app.service
sudo chown root: /etc/systemd/system/$app.service
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/$app.service
##
sudo systemctl daemon-reload
## Démarrage auto du service
sudo systemctl enable $app
#=================================================
# UPDATE LSTU'S DEPENDENCIES WITH CARTON
#=================================================
pushd $final_path # cd avec une stack pour revenir en arrière
echo yes | sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
popd # Revient au dossier courant avant pushd
secret=$(ynh_string_random 24)
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
ynh_store_file_checksum "${final_path}/lstu.conf"
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
sudo chown -R www-data: $final_path
chown -R www-data $final_path
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# Install lstu's dependencies via carton
#=================================================
pushd $final_path
carton install --deployment --without=sqlite --without=mysql
popd
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app.log"
#=================================================
# RESTART LSTU
#=================================================
sudo systemctl start lstu.service
systemctl reload $app
#=================================================
# SETUP SSOWAT
#=================================================
# Make app public or private
ynh_app_setting_set $app skipped_uris "/"
if [ $is_public -eq 0 ];
then # If the app is private, only the shortened URLs are publics
if [ "$path" == "/" ]; then
path=""
if [ "$path_url" == "/" ]; then
path_url=""
fi
ynh_app_setting_set $app protected_regex "$domain_regex$path/login$","$domain_regex$path/logout$","$domain_regex$path/api$","$domain_regex$path/extensions$","$domain_regex$path/stats$","$domain_regex$path/d/.*$","$domain_regex$path/a$","$domain_regex$path/$"
ynh_app_setting_set $app protected_regex "$domain$path_url/login$","$domain$path_url/logout$","$domain$path_url/api$","$domain$path_url/extensions$","$domain$path_url/stats$","$domain$path_url/d/.*$","$domain$path_url/a$","$domain$path_url/$"
else
ynh_replace_string "#--PRIVATE--" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
fi
#=================================================
# RELOAD NGINX
#=================================================
sudo systemctl reload nginx
sudo yunohost app ssowatconf
systemctl reload nginx
yunohost app ssowatconf