mirror of
https://github.com/YunoHost-Apps/lstu_ynh.git
synced 2024-09-03 19:36:12 +02:00
Merge branch 'master' into testing
This commit is contained in:
commit
11e06c5c63
15 changed files with 710 additions and 490 deletions
76
README.md
76
README.md
|
@ -1,10 +1,70 @@
|
||||||
|
# Lstu app for YunoHost
|
||||||
|
|
||||||

|
[](https://dash.yunohost.org/appci/app/lstu)
|
||||||
|
[](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
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 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 - [](https://ci-apps.yunohost.org/ci/apps/lstu/)
|
||||||
|
* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/lstu/)
|
||||||
|
* Jessie x86-64b - [](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
|
## Todo
|
||||||
|
|
||||||
- [ ] Integrate with LDAP
|
- [ ] 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 the database (sqlite or PostgreSQL)
|
||||||
- [ ] Allow to choose to use Minion
|
- [ ] Allow to choose to use Minion
|
||||||
- [ ] Add CI stuff
|
- [ ] Add CI stuff
|
||||||
|
- [ ] Theme choice (default or milligram)
|
||||||
# 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
|
|
||||||
|
|
5
conf/app.src
Normal file
5
conf/app.src
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
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
|
|
@ -67,9 +67,9 @@
|
||||||
#fixed_domain => 'example.org',
|
#fixed_domain => 'example.org',
|
||||||
|
|
||||||
# choose what database you want to use
|
# choose what database you want to use
|
||||||
# valid choices are sqlite and postgresql (all lowercase)
|
# valid choices are sqlite, postgresql and mysql (all lowercase)
|
||||||
# optional, default is sqlite
|
# optional, default is sqlite
|
||||||
#dbtype => 'sqlite',
|
dbtype => 'postgresql',
|
||||||
|
|
||||||
# SQLite ONLY - only used if dbtype is set to sqlite
|
# SQLite ONLY - only used if dbtype is set to sqlite
|
||||||
# define a path to the SQLite database
|
# define a path to the SQLite database
|
||||||
|
@ -81,11 +81,29 @@
|
||||||
# PostgreSQL ONLY - only used if dbtype is set to postgresql
|
# PostgreSQL ONLY - only used if dbtype is set to postgresql
|
||||||
# these are the credentials to access the PostgreSQL database
|
# these are the credentials to access the PostgreSQL database
|
||||||
# mandatory if you choosed postgresql as dbtype
|
# mandatory if you choosed postgresql as dbtype
|
||||||
#pgdb => {
|
pgdb => {
|
||||||
|
database => '__DB_NAME__',
|
||||||
|
host => 'localhost',
|
||||||
|
# optional, default is 5432
|
||||||
|
#port => 5432,
|
||||||
|
user => '__DB_USER__',
|
||||||
|
pwd => '__DB_PWD__',
|
||||||
|
# optional, default is 1
|
||||||
|
#max_connections => 1,
|
||||||
|
},
|
||||||
|
|
||||||
|
# MySQL ONLY - only used if dbtype is set to mysql
|
||||||
|
# these are the credentials to access the MySQL database
|
||||||
|
# mandatory if you choosed mysql as dbtype
|
||||||
|
#mysqldb => {
|
||||||
# database => 'lstu',
|
# database => 'lstu',
|
||||||
# host => 'localhost',
|
# host => 'localhost',
|
||||||
# #user => 'DBUSER',
|
# # optional, default is 3306
|
||||||
# #pwd => 'DBPASSWORD'
|
# #port => 3306,
|
||||||
|
# user => 'DBUSER',
|
||||||
|
# pwd => 'DBPASSWORD',
|
||||||
|
# # optional, default is 5 (set to 0 to disable persistent connections)
|
||||||
|
# #max_connections => 5,
|
||||||
#},
|
#},
|
||||||
|
|
||||||
# Rate-limiting for the API
|
# Rate-limiting for the API
|
||||||
|
@ -104,6 +122,14 @@
|
||||||
# optional, default is an empty array
|
# optional, default is an empty array
|
||||||
#ban_whitelist => [],
|
#ban_whitelist => [],
|
||||||
|
|
||||||
|
# Ban blacklist
|
||||||
|
# You can blacklist IP addresses to always ban those IP addresses
|
||||||
|
# Be careful, the IP addresses are compared as string, not as IP addresses
|
||||||
|
# a network range will not work
|
||||||
|
# Example of valid input: ban_blacklist => ['198.51.100.42', '2001:0DB8::42'],¬
|
||||||
|
# optional, default is an empty array
|
||||||
|
#ban_blacklist => [],
|
||||||
|
|
||||||
# define an URL to the Piwik instance and the ID of a website to track
|
# define an URL to the Piwik instance and the ID of a website to track
|
||||||
# set if you want to track views in Piwik
|
# set if you want to track views in Piwik
|
||||||
# optional, Piwik tracking is disabled by default
|
# optional, Piwik tracking is disabled by default
|
||||||
|
@ -115,21 +141,50 @@
|
||||||
# use Minion instead of directly increase counters
|
# use Minion instead of directly increase counters
|
||||||
# need to launch a minion worker service if enabled
|
# need to launch a minion worker service if enabled
|
||||||
# optional, Minion is disabled by default
|
# optional, Minion is disabled by default
|
||||||
|
# It will use the same DB type as Lstu: sqlite if you choose sqlite for `dbtype`,
|
||||||
|
# postgresql for postgresql, etc.
|
||||||
#minion => {
|
#minion => {
|
||||||
# enabled => 0,
|
# enabled => 0,
|
||||||
# db_path => 'minion.db' # you can define it relative to lstu directory or set an absolute path
|
# # SQLite ONLY - only used if if you choose sqlite as DB type,
|
||||||
|
# # define the path to the minion database
|
||||||
|
# # you can define it relative to lstu directory or set an absolute path
|
||||||
|
# # remember that it has to be in a directory writable by Lutim user
|
||||||
|
# # optional, default is minion.db
|
||||||
|
# db_path => 'minion.db',
|
||||||
|
# # PostgreSQL ONLY - only used if you choose postgresql as DB type
|
||||||
|
# # these are the credentials to access the Minion's PostgreSQL database
|
||||||
|
# # mandatory if you choosed postgresql as DB type, no default
|
||||||
|
# pgdb => {
|
||||||
|
# database => 'lstu_minion',
|
||||||
|
# host => 'localhost',
|
||||||
|
# # optional, default is 5432
|
||||||
|
# #port => 5432,
|
||||||
|
# user => 'DBUSER',
|
||||||
|
# pwd => 'DBPASSWORD'
|
||||||
|
# },
|
||||||
|
# # MySQL ONLY - only used if you choose mysql as DB type
|
||||||
|
# # these are the credentials to access the Minion's MySQL database
|
||||||
|
# # mandatory if you choosed mysql as DB type, no default
|
||||||
|
# mysqldb => {
|
||||||
|
# database => 'lstu_minion',
|
||||||
|
# host => 'localhost',
|
||||||
|
# # optional, default is 3306
|
||||||
|
# #port => 3306,
|
||||||
|
# user => 'DBUSER',
|
||||||
|
# pwd => 'DBPASSWORD',
|
||||||
|
# },
|
||||||
#},
|
#},
|
||||||
|
|
||||||
# set `ldap` if you want that only authenticated users can shorten URLs
|
# set `ldap` if you want that only authenticated users can shorten URLs
|
||||||
# please note that everybody can still use shortend URLs
|
# please note that everybody can still use shortend URLs
|
||||||
# optional, no default
|
# optional, no default
|
||||||
#ldap => {
|
#ldap => {
|
||||||
# uri => 'ldaps://ldap.example.org',
|
# uri => 'ldaps://ldap.example.org', # server URI
|
||||||
# user_tree => 'ou=users,dc=example,dc=org',
|
# user_tree => 'ou=users,dc=example,dc=org', # search base DN
|
||||||
# bind_dn => ',ou=users,dc=example,dc=org',
|
# bind_dn => 'uid=ldap_user,ou=users,dc=example,dc=org', # search bind DN
|
||||||
# bind_user => 'uid=ldap_user',
|
# bind_pwd => 'secr3t', # search bind password
|
||||||
# bind_pwd => 'secr3t',
|
# user_attr => 'uid', # user attribute (uid, mail, sAMAccountName, etc.)
|
||||||
# user_filter => '!(uid=ldap_user)'
|
# user_filter => '(!(uid=ldap_user))', # user filter (to exclude some users, etc.)
|
||||||
#},
|
#},
|
||||||
|
|
||||||
# set `htpasswd` if you want to use an htpasswd file instead of ldap
|
# set `htpasswd` if you want to use an htpasswd file instead of ldap
|
||||||
|
@ -142,4 +197,72 @@
|
||||||
# the user needs to reauthenticate
|
# the user needs to reauthenticate
|
||||||
# optional, default is 3600
|
# optional, default is 3600
|
||||||
#session_duration => 3600,
|
#session_duration => 3600,
|
||||||
|
|
||||||
|
# how many redirections are allowed for the shortened URL before considering it as a spam?
|
||||||
|
# optional, default is 2. Set to -1 to allow infinite redirections (not recommended)
|
||||||
|
#max_redir => 2,
|
||||||
|
|
||||||
|
# spam blacklist regex. All URLs (or redirection) whose host part matches this regex are considered as spam
|
||||||
|
# optional, no default
|
||||||
|
#spam_blacklist_regex => 'foo|bar',
|
||||||
|
|
||||||
|
# spam path blacklist regex. All URLs (or redirection) whose path part matches this regex are considered as spam
|
||||||
|
# optional, no default
|
||||||
|
#spam_path_blacklist_regex => 'foo|bar',
|
||||||
|
|
||||||
|
# spam whitelist regex. All URLs (or redirection) whose host part matches this regex will never be considered as spam
|
||||||
|
# optional, no default
|
||||||
|
#spam_whitelist_regex => 'foo|bar',
|
||||||
|
|
||||||
|
# set to 1 to skip SpamHaus check (not recommended)
|
||||||
|
# optional, default is 0
|
||||||
|
#skip_spamhaus => 0,
|
||||||
|
|
||||||
|
# put your Google API key to enable Google safebrowsing check
|
||||||
|
# This will allow Lstu to download the Google safebrowsing database and use a local copy to check the URLs.
|
||||||
|
# Google does not get the URLs that are checked.
|
||||||
|
# Instructions to get a key: https://developers.google.com/safe-browsing/v4/get-started
|
||||||
|
# TL;DR: https://console.developers.google.com/projectselector/apis/library
|
||||||
|
# optional, no default
|
||||||
|
#safebrowsing_api_key => '',
|
||||||
|
|
||||||
|
# array of memcached servers to cache URL in order to accelerate responses to often-viewed URL.
|
||||||
|
# If set to [], the cache is disabled
|
||||||
|
# optional, default is []
|
||||||
|
#memcached_servers => [],
|
||||||
|
|
||||||
|
# Content-Security-Policy header that will be sent by Lstu
|
||||||
|
# Set to '' to disable CSP header
|
||||||
|
# https://content-security-policy.com/ provides a good documentation about CSP.
|
||||||
|
# https://report-uri.com/home/generate provides a tool to generate a CSP header.
|
||||||
|
# optional, default is "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; form-action 'self'; base-uri 'self'"
|
||||||
|
# the default value is good for `default` and `milligram` themes
|
||||||
|
#csp => "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; form-action 'self'; base-uri 'self'",
|
||||||
|
|
||||||
|
# X-Frame-Options header that will be sent by Lstu
|
||||||
|
# Valid values are: 'DENY', 'SAMEORIGIN', 'ALLOW-FROM https://example.com/'
|
||||||
|
# Set to '' to disable X-Frame-Options header
|
||||||
|
# See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
|
||||||
|
# Please note that this will add a "frame-ancestors" directive to the CSP header (see above) accordingly
|
||||||
|
# to the chosen setting (See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors)
|
||||||
|
# optional, default is 'DENY'
|
||||||
|
#x_frame_options => 'DENY',
|
||||||
|
|
||||||
|
# X-Content-Type-Options that will be sent by Lstu
|
||||||
|
# See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
|
||||||
|
# Set to '' to disable X-Content-Type-Options header
|
||||||
|
# optional, default is 'nosniff'
|
||||||
|
#x_content_type_options => 'nosniff',
|
||||||
|
|
||||||
|
# X-XSS-Protection that will be sent by Lstu
|
||||||
|
# See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection
|
||||||
|
# Set to '' to disable X-XSS-Protection header
|
||||||
|
# optional, default is '1; mode=block'
|
||||||
|
#x_xss_protection => '1; mode=block',
|
||||||
|
|
||||||
|
# Log creator's IP address
|
||||||
|
# Set to 1 if you want to register the IP addresses of URL creators
|
||||||
|
# optional, default is 0
|
||||||
|
#log_creator_ip => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,10 @@ After=network.target
|
||||||
Type=simple
|
Type=simple
|
||||||
User=www-data
|
User=www-data
|
||||||
RemainAfterExit=yes
|
RemainAfterExit=yes
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
WorkingDirectory=__FINALPATH__
|
WorkingDirectory=__FINALPATH__
|
||||||
PIDFile=__FINALPATH__script/hypnotoad.pid
|
PIDFile=__FINALPATH__/script/hypnotoad.pid
|
||||||
ExecStart=/usr/local/bin/carton exec hypnotoad script/lstu
|
ExecStart=/usr/local/bin/carton exec hypnotoad script/lstu
|
||||||
ExecStop=/usr/local/bin/carton exec hypnotoad -s script/lstu
|
ExecStop=/usr/local/bin/carton exec hypnotoad -s script/lstu
|
||||||
ExecReload=/usr/local/bin/carton exec hypnotoad script/lstu
|
ExecReload=/usr/local/bin/carton exec hypnotoad script/lstu
|
|
@ -2,6 +2,7 @@
|
||||||
"name": "Lstu",
|
"name": "Lstu",
|
||||||
"id": "lstu",
|
"id": "lstu",
|
||||||
"packaging_format": 1,
|
"packaging_format": 1,
|
||||||
|
"version": "0.21-4~ynh1",
|
||||||
"requirements": {
|
"requirements": {
|
||||||
"yunohost": ">= 2.4"
|
"yunohost": ">= 2.4"
|
||||||
},
|
},
|
||||||
|
@ -12,8 +13,8 @@
|
||||||
"url": "https://lstu.fr",
|
"url": "https://lstu.fr",
|
||||||
"license": "WTFPL",
|
"license": "WTFPL",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
"name": "frj365",
|
"name": "frju365",
|
||||||
"email": "win10@tutanota.com"
|
"email": "abld@abld.info"
|
||||||
},
|
},
|
||||||
"multi_instance": false,
|
"multi_instance": false,
|
||||||
"services": [
|
"services": [
|
||||||
|
|
|
@ -1,230 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# vim:set noexpandtab:
|
|
||||||
|
|
||||||
ynh_version="2.5"
|
|
||||||
|
|
||||||
YNH_VERSION () { # Returns the version number of the Yunohost moulinette
|
|
||||||
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_VAR () { # Verifies that the variable is not empty.
|
CHECK_VAR () { # Verifies that the variable is not empty.
|
||||||
# $1 = Variable to be checked
|
# $1 = Variable to be checked
|
||||||
# $2 = Display text on error
|
# $2 = Display text on error
|
||||||
test -n "$1" || (echo "$2" >&2 && false)
|
test -n "$1" || (echo "$2" >&2 && false)
|
||||||
}
|
}
|
||||||
|
|
||||||
EXIT_PROPERLY () { # Causes the script to stop in the event of an error. And clean the residue.
|
|
||||||
trap '' ERR
|
|
||||||
echo -e "\e[91m \e[1m" # Shell in light red bold
|
|
||||||
echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!" >&2
|
|
||||||
|
|
||||||
if type -t CLEAN_SETUP > /dev/null; then # Checks the existence of the function before executing it.
|
|
||||||
CLEAN_SETUP # Call the specific cleanup function of the install script.
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Compensates the ssowat bug that does not remove the app's input in case of installation error.
|
|
||||||
sudo sed -i "\@\"$domain$path/\":@d" /etc/ssowat/conf.json
|
|
||||||
|
|
||||||
if [ "$ynh_version" = "2.2" ]; then
|
|
||||||
/bin/bash $script_dir/remove
|
|
||||||
fi
|
|
||||||
|
|
||||||
ynh_die
|
|
||||||
}
|
|
||||||
|
|
||||||
TRAP_ON () { # Activate signal capture
|
|
||||||
trap EXIT_PROPERLY ERR # Capturing exit signals on error
|
|
||||||
}
|
|
||||||
|
|
||||||
TRAP_OFF () { # Ignoring signal capture until TRAP_ON
|
|
||||||
trap '' ERR # Ignoring exit signals
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_USER () { # Check the validity of the user admin
|
|
||||||
# $1 = User admin variable
|
|
||||||
ynh_user_exists "$1" || (echo "Wrong admin" >&2 && false)
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_PATH () { # Checks / at the beginning of the path. And his absence at the end.
|
|
||||||
if [ "${path:0:1}" != "/" ]; then # If the first character is not /
|
|
||||||
path="/$path" # Add / at the beginning of path
|
|
||||||
fi
|
|
||||||
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # If the last character is a / and it is not the only character.
|
|
||||||
path="${path:0:${#path}-1}" # Delete last character
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_DOMAINPATH () { # Checks the availability of the path and domain.
|
|
||||||
sudo yunohost app checkurl $domain$path -a $app
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_FINALPATH () { # Checks that the destination folder is not already in use.
|
|
||||||
final_path=/var/www/$app
|
|
||||||
if [ -e "$final_path" ]
|
|
||||||
then
|
|
||||||
echo "This path already contains a folder" >&2
|
|
||||||
false
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
SETUP_SOURCE () { # Download source, decompress and copu into $final_path
|
|
||||||
src=$(cat ../sources/source_md5 | awk -F' ' {'print $2'})
|
|
||||||
sudo wget -nv -i ../sources/source_url -O $src
|
|
||||||
# Checks the checksum of the downloaded source.
|
|
||||||
# md5sum -c ../sources/source_md5 --status || ynh_die "Corrupt source"
|
|
||||||
# Decompress source
|
|
||||||
if [ "$(echo ${src##*.})" == "tgz" ]; then
|
|
||||||
tar -x -f $src
|
|
||||||
elif [ "$(echo ${src##*.})" == "zip" ]; then
|
|
||||||
unzip -q $src
|
|
||||||
else
|
|
||||||
false # Unsupported archive format.
|
|
||||||
fi
|
|
||||||
# Copy file source
|
|
||||||
sudo cp -a $(cat ../sources/source_dir)/. "$final_path"
|
|
||||||
# Copy additional file and modified
|
|
||||||
if test -e "../sources/ajouts"; then
|
|
||||||
sudo cp -a ../sources/ajouts/. "$final_path"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
ADD_SYS_USER () { # Créer un utilisateur système dédié à l'app
|
|
||||||
if ! ynh_system_user_exists "$app" # Test l'existence de l'utilisateur
|
|
||||||
then
|
|
||||||
sudo useradd -d /var/www/$app --system --user-group $app --shell /usr/sbin/nologin || (echo "Unable to create $app system account" >&2 && false)
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
STORE_MD5_CONFIG () { # Saves the checksum of the config file
|
|
||||||
# $1 = Name of the conf file for storage in settings.yml
|
|
||||||
# $2 = Full name and path of the conf file.
|
|
||||||
ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1)
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_MD5_CONFIG () { # Created a backup of the config file if it was changed.
|
|
||||||
# $1 = Name of the conf file for storage in settings.yml
|
|
||||||
# $2 = Full name and path of the conf file.onf.
|
|
||||||
if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then
|
|
||||||
sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup.
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
FIND_PORT () { # Search free port
|
|
||||||
YNH_VERSION
|
|
||||||
if [ $ynh_version == "2.5" ]; then
|
|
||||||
# $1 = Port number to start the search.
|
|
||||||
port=$1
|
|
||||||
while ! sudo yunohost app checkport $port ; do
|
|
||||||
port=$((port+1))
|
|
||||||
done
|
|
||||||
CHECK_VAR "$port" "port empty"
|
|
||||||
else
|
|
||||||
# $1 = Port number to start the search.
|
|
||||||
port=$1
|
|
||||||
if [ "$(sudo yunohost tools port-available $port)" = "True" ]; then
|
|
||||||
port=$((port+1))
|
|
||||||
fi
|
|
||||||
CHECK_VAR "$port" "port empty"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
### REMOVE SCRIPT
|
|
||||||
|
|
||||||
REMOVE_NGINX_CONF () { # Delete nginx configuration
|
|
||||||
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
|
|
||||||
echo "Delete nginx config"
|
|
||||||
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
||||||
sudo service nginx reload
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOVE_LOGROTATE_CONF () { # Delete logrotate configuration
|
|
||||||
if [ -e "/etc/logrotate.d/$app" ]; then
|
|
||||||
echo "Delete logrotate config"
|
|
||||||
sudo rm "/etc/logrotate.d/$app"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
SECURE_REMOVE () { # Deleting a folder with variable verification
|
|
||||||
chaine="$1" # The argument must be given between simple quotes '', to avoid interpreting the variables.
|
|
||||||
no_var=0
|
|
||||||
while (echo "$chaine" | grep -q '\$') # Loop as long as there are $ in the string
|
|
||||||
do
|
|
||||||
no_var=1
|
|
||||||
global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole the first variable found.
|
|
||||||
only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole completely the variable by adding the $ at the beginning and keeping only the name of the variable. Mostly gets rid of / and a possible path behind.
|
|
||||||
real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` Allows to interpret a variable contained in a variable.
|
|
||||||
if test -z "$real_var" || [ "$real_var" = "/" ]; then
|
|
||||||
echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # Replaces variable with its value in the string.
|
|
||||||
done
|
|
||||||
if [ "$no_var" -eq 1 ]
|
|
||||||
then
|
|
||||||
if [ -e "$chaine" ]; then
|
|
||||||
echo "Delete directory $chaine"
|
|
||||||
sudo rm -r "$chaine"
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
echo "No detected variable." >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOVE_SYS_USER () { # Delete user
|
|
||||||
if ynh_system_user_exists "$app" # Test user exist
|
|
||||||
then
|
|
||||||
sudo userdel $app
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# BACKUP
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Manage a fail of the script
|
|
||||||
#
|
|
||||||
# Print a warning to inform that the script was failed
|
|
||||||
# Execute the ynh_clean_setup function if used in the app script
|
|
||||||
#
|
|
||||||
# usage of ynh_clean_setup function
|
|
||||||
# This function provide a way to clean some residual of installation that not managed by remove script.
|
|
||||||
# To use it, simply add in your script:
|
|
||||||
# ynh_clean_setup () {
|
|
||||||
# instructions...
|
|
||||||
# }
|
|
||||||
# This function is optionnal.
|
|
||||||
#
|
|
||||||
# Usage: ynh_exit_properly is used only by the helper ynh_check_error.
|
|
||||||
# You must not use it directly.
|
|
||||||
ynh_exit_properly () {
|
|
||||||
exit_code=$?
|
|
||||||
if [ "$exit_code" -eq 0 ]; then
|
|
||||||
ynh_die # Exit without error if the script ended correctly
|
|
||||||
fi
|
|
||||||
|
|
||||||
trap '' EXIT # Ignore new exit signals
|
|
||||||
set +eu # Do not exit anymore if a command fail or if a variable is empty
|
|
||||||
|
|
||||||
echo -e "!!\n $app's script has encountered an error. Its execution was cancelled.\n!!" >&2
|
|
||||||
|
|
||||||
if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script.
|
|
||||||
ynh_clean_setup # Call the function to do specific cleaning for the app.
|
|
||||||
fi
|
|
||||||
|
|
||||||
ynh_die # Exit with error status
|
|
||||||
}
|
|
||||||
|
|
||||||
# Exit if an error occurs during the execution of the script.
|
|
||||||
#
|
|
||||||
# Stop immediatly the execution if an error occured or if a empty variable is used.
|
|
||||||
# The execution of the script is derivate to ynh_exit_properly function before exit.
|
|
||||||
#
|
|
||||||
# Usage: ynh_abort_if_errors
|
|
||||||
ynh_abort_if_errors () {
|
|
||||||
set -eu # Exit if a command fail, and if a variable is used unset.
|
|
||||||
trap ynh_exit_properly EXIT # Capturing exit signals on shell script
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,27 +1,65 @@
|
||||||
#!/bin/bash
|
#!/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
|
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
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve app settings
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
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}"
|
# STANDARD BACKUP STEPS
|
||||||
ynh_backup "${final_path}" "sources" 1
|
#=================================================
|
||||||
|
# BACKUP THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Copy the nginx conf files
|
ynh_backup "$final_path"
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
|
||||||
|
|
||||||
# Copy the lstu conf file
|
#=================================================
|
||||||
ynh_backup "${final_path}/lstu.conf" "lstu.conf"
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
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"
|
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"
|
223
scripts/install
223
scripts/install
|
@ -13,125 +13,182 @@ source /usr/share/yunohost/helpers
|
||||||
# MANAGE SCRIPT FAILURE
|
# 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
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
# Retrieve arguments
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||||
|
#=================================================
|
||||||
|
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path=$YNH_APP_ARG_PATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
script_dir=$PWD
|
#=================================================
|
||||||
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Check variables are not empty
|
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
|
||||||
CHECK_VAR "$app" "app name not set"
|
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
|
||||||
CHECK_VAR "$script_dir" "script_dir not set"
|
final_path=/var/www/$app
|
||||||
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
|
|
||||||
CHECK_PATH # Check and fix path syntax
|
|
||||||
CHECK_DOMAINPATH # Check and fix domain disponibility
|
|
||||||
|
|
||||||
CHECK_FINALPATH # Check final path
|
|
||||||
|
|
||||||
# Check domain with regex
|
|
||||||
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
||||||
|
|
||||||
|
# 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
|
||||||
CHECK_VAR "$domain_regex" "domain_regex empty"
|
CHECK_VAR "$domain_regex" "domain_regex empty"
|
||||||
|
|
||||||
FIND_PORT 8096 # Check port availability
|
#=================================================
|
||||||
|
# FIND AND OPEN A PORT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Find a free port
|
||||||
|
port=$(ynh_find_port 8095)
|
||||||
|
# Open this port
|
||||||
|
yunohost firewall allow --no-upnp TCP $port 2>&1
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STORE SETTINGS FROM MANIFEST
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Save app settings
|
|
||||||
ynh_app_setting_set $app domain $domain
|
ynh_app_setting_set $app domain $domain
|
||||||
ynh_app_setting_set $app is_public $is_public
|
ynh_app_setting_set $app is_public $is_public
|
||||||
ynh_app_setting_set $app port $port
|
ynh_app_setting_set $app port $port
|
||||||
|
ynh_app_setting_set $app path $path_url
|
||||||
|
|
||||||
# Install dependencies
|
#=================================================
|
||||||
ynh_package_update
|
# INSTALL DEPENDENCIES
|
||||||
ynh_package_install build-essential libssl-dev libpq-dev
|
#=================================================
|
||||||
|
|
||||||
# Copy files to the right place
|
|
||||||
sudo mkdir "${final_path}"
|
|
||||||
ynh_app_setting_set $app final_path $final_path
|
|
||||||
|
|
||||||
# Get source
|
|
||||||
SETUP_SOURCE
|
|
||||||
|
|
||||||
# Copy it to Nginx conf directory
|
|
||||||
sudo cp ../conf/nginx.conf /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
|
|
||||||
|
|
||||||
## Copy and fix variable into lstu config
|
|
||||||
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"
|
|
||||||
|
|
||||||
secret=$(ynh_string_random 24)
|
|
||||||
CHECK_VAR "$secret" "secret empty"
|
|
||||||
sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lstu.conf"
|
|
||||||
STORE_MD5_CONFIG "lstu.conf" "${final_path}/lstu.conf"
|
|
||||||
|
|
||||||
# Install systemd script
|
|
||||||
sudo cp ../conf/lstu.service /etc/systemd/system/lstu.service
|
|
||||||
sudo chown root: /etc/systemd/system/lstu.service
|
|
||||||
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/lstu.service
|
|
||||||
|
|
||||||
# Install logrotate
|
|
||||||
sudo cp ../conf/logrotate /etc/logrotate.d/$app
|
|
||||||
sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/logrotate.d/$app
|
|
||||||
|
|
||||||
|
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql
|
||||||
# Install Carton
|
# Install Carton
|
||||||
echo yes | sudo cpan Carton
|
echo yes | sudo cpan Carton
|
||||||
|
|
||||||
# Install lstu's dependencies via carton
|
#=================================================
|
||||||
sudo mkdir -p /var/log/$app/
|
# CREATE A POSTGRESQL DATABASE
|
||||||
cd $final_path
|
#=================================================
|
||||||
sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
|
|
||||||
|
|
||||||
# Change variables in nginx configuration
|
# Create postgresql database
|
||||||
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
ynh_psql_test_if_first_run
|
||||||
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
db_name=$(ynh_sanitize_dbid "$app")
|
||||||
|
db_user=$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
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
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
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
||||||
|
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Create a system user
|
||||||
|
ynh_system_user_create $app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
## Copy and fix variable into lstu config
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
secret=$(ynh_string_random 24)
|
||||||
|
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
|
||||||
|
ynh_store_file_checksum "${final_path}/lstu.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Make app public or private
|
# Make app public or private
|
||||||
ynh_app_setting_set $app skipped_uris "/"
|
ynh_app_setting_set $app skipped_uris "/"
|
||||||
if [ $is_public -eq 0 ];
|
if [ $is_public -eq 0 ];
|
||||||
then # If the app is private, only the shortened URLs are publics
|
then # If the app is private, only the shortened URLs are publics
|
||||||
if [ "$path" == "/" ]; then
|
if [ "$path_url" == "/" ]; then
|
||||||
path=""
|
path_url=""
|
||||||
fi
|
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_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
|
||||||
|
ynh_replace_string "#--PRIVATE--" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Making log symbolic link to /var/log
|
#=================================================
|
||||||
sudo touch /var/log/$app/production.log
|
|
||||||
sudo chown www-data: /var/log/$app/production.log
|
|
||||||
sudo ln -s /var/log/$app/production.log "$final_path/log/production.log"
|
|
||||||
|
|
||||||
# Configure owner
|
# Configure owner
|
||||||
sudo chown -R www-data: $final_path
|
#=================================================
|
||||||
|
|
||||||
|
sudo chown -R www-data $final_path
|
||||||
|
|
||||||
|
#=================================================
|
||||||
# Start lstu
|
# Start lstu
|
||||||
sudo systemctl daemon-reload
|
#=================================================
|
||||||
sudo systemctl start lstu.service
|
|
||||||
sudo systemctl enable lstu.service
|
|
||||||
|
|
||||||
# Set right permissions on new files created at first start
|
systemctl enable $app.service
|
||||||
sudo chown -R www-data: "$final_path"
|
systemctl start $app
|
||||||
|
|
||||||
# Add lstu as a service
|
#=================================================
|
||||||
sudo yunohost service add lstu -l $final_path/log/production.log
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
if [ $is_public -eq 0 ];
|
|
||||||
then
|
|
||||||
# Delete public access
|
|
||||||
ynh_app_setting_delete $app unprotected_uris
|
|
||||||
# Regenerate SSOwat's configuration
|
|
||||||
sudo yunohost app ssowatconf
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Reload Nginx
|
# Reload Nginx
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
147
scripts/psql.sh
Normal file
147
scripts/psql.sh
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
#=================================================
|
||||||
|
# POSTGRES HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Open a connection as a user
|
||||||
|
#
|
||||||
|
# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;"
|
||||||
|
# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_connect_as user pwd [db]
|
||||||
|
# | arg: user - the user name to connect as
|
||||||
|
# | arg: pwd - the user password
|
||||||
|
# | arg: db - the database to connect to
|
||||||
|
ynh_psql_connect_as() {
|
||||||
|
user="$1"
|
||||||
|
pwd="$2"
|
||||||
|
db="$3"
|
||||||
|
su --command="PGUSER=\"${user}\" PGPASSWORD=\"${pwd}\" psql \"${db}\"" postgres
|
||||||
|
}
|
||||||
|
|
||||||
|
# # Execute a command as root user
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_execute_as_root sql [db]
|
||||||
|
# | arg: sql - the SQL command to execute
|
||||||
|
# | arg: db - the database to connect to
|
||||||
|
ynh_psql_execute_as_root () {
|
||||||
|
sql="$1"
|
||||||
|
su --command="psql" postgres <<< "$sql"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Execute a command from a file as root user
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_execute_file_as_root file [db]
|
||||||
|
# | arg: file - the file containing SQL commands
|
||||||
|
# | arg: db - the database to connect to
|
||||||
|
ynh_psql_execute_file_as_root() {
|
||||||
|
file="$1"
|
||||||
|
db="$2"
|
||||||
|
su -c "psql $db" postgres < "$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a database, an user and its password. Then store the password in the app's config
|
||||||
|
#
|
||||||
|
# After executing this helper, the password of the created database will be available in $db_pwd
|
||||||
|
# It will also be stored as "psqlpwd" into the app settings.
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_setup_db user name [pwd]
|
||||||
|
# | arg: user - Owner of the database
|
||||||
|
# | arg: name - Name of the database
|
||||||
|
# | arg: pwd - Password of the database. If not given, a password will be generated
|
||||||
|
ynh_psql_setup_db () {
|
||||||
|
db_user="$1"
|
||||||
|
app="$1"
|
||||||
|
db_name="$2"
|
||||||
|
new_db_pwd=$(ynh_string_random) # Generate a random password
|
||||||
|
# If $3 is not given, use new_db_pwd instead for db_pwd.
|
||||||
|
db_pwd="${3:-$new_db_pwd}"
|
||||||
|
ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database
|
||||||
|
ynh_app_setting_set "$app" psqlpwd "$db_pwd" # Store the password in the app's config
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a database and grant optionnaly privilegies to a user
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_create_db db [user [pwd]]
|
||||||
|
# | arg: db - the database name to create
|
||||||
|
# | arg: user - the user to grant privilegies
|
||||||
|
# | arg: pwd - the user password
|
||||||
|
ynh_psql_create_db() {
|
||||||
|
db="$1"
|
||||||
|
user="$2"
|
||||||
|
pwd="$3"
|
||||||
|
ynh_psql_create_user "$user" "$pwd"
|
||||||
|
su --command="createdb --owner=\"${user}\" \"${db}\"" postgres
|
||||||
|
}
|
||||||
|
|
||||||
|
# Drop a database
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_drop_db db user
|
||||||
|
# | arg: db - the database name to drop
|
||||||
|
# | arg: user - the user to drop
|
||||||
|
ynh_psql_remove_db() {
|
||||||
|
db="$1"
|
||||||
|
user="$2"
|
||||||
|
su --command="dropdb \"${db}\"" postgres
|
||||||
|
ynh_psql_drop_user "${user}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Dump a database
|
||||||
|
#
|
||||||
|
# example: ynh_psql_dump_db 'roundcube' > ./dump.sql
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_dump_db db
|
||||||
|
# | arg: db - the database name to dump
|
||||||
|
# | ret: the psqldump output
|
||||||
|
ynh_psql_dump_db() {
|
||||||
|
db="$1"
|
||||||
|
su --command="pg_dump \"${db}\"" postgres
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Create a user
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_create_user user pwd [host]
|
||||||
|
# | arg: user - the user name to create
|
||||||
|
ynh_psql_create_user() {
|
||||||
|
user="$1"
|
||||||
|
pwd="$2"
|
||||||
|
su --command="psql -c\"CREATE USER ${user} WITH PASSWORD '${pwd}'\"" postgres
|
||||||
|
}
|
||||||
|
|
||||||
|
# Drop a user
|
||||||
|
#
|
||||||
|
# usage: ynh_psql_drop_user user
|
||||||
|
# | arg: user - the user name to drop
|
||||||
|
ynh_psql_drop_user() {
|
||||||
|
user="$1"
|
||||||
|
su --command="dropuser \"${user}\"" postgres
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_psql_test_if_first_run() {
|
||||||
|
if [ -f /etc/yunohost/psql ];
|
||||||
|
then
|
||||||
|
echo "PostgreSQL is already installed, no need to create master password"
|
||||||
|
else
|
||||||
|
pgsql=$(ynh_string_random)
|
||||||
|
pg_hba=""
|
||||||
|
echo "$pgsql" >> /etc/yunohost/psql
|
||||||
|
|
||||||
|
if [ -e /etc/postgresql/9.4/ ]
|
||||||
|
then
|
||||||
|
pg_hba=/etc/postgresql/9.4/main/pg_hba.conf
|
||||||
|
elif [ -e /etc/postgresql/9.6/ ]
|
||||||
|
then
|
||||||
|
pg_hba=/etc/postgresql/9.6/main/pg_hba.conf
|
||||||
|
else
|
||||||
|
ynh_die "postgresql shoud be 9.4 or 9.6"
|
||||||
|
fi
|
||||||
|
|
||||||
|
systemctl start postgresql
|
||||||
|
su --command="psql -c\"ALTER user postgres WITH PASSWORD '${pgsql}'\"" postgres
|
||||||
|
# we can't use peer since YunoHost create users with nologin
|
||||||
|
sed -i '/local\s*all\s*all\s*peer/i \
|
||||||
|
local all all password' "$pg_hba"
|
||||||
|
systemctl enable postgresql
|
||||||
|
systemctl reload postgresql
|
||||||
|
fi
|
||||||
|
}
|
|
@ -17,6 +17,8 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
port=$(ynh_app_setting_get $app port)
|
port=$(ynh_app_setting_get $app port)
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
db_user=$db_name
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD REMOVE
|
# STANDARD REMOVE
|
||||||
|
@ -27,16 +29,6 @@ domain=$(ynh_app_setting_get $app domain)
|
||||||
# Remove the dedicated systemd config
|
# Remove the dedicated systemd config
|
||||||
ynh_remove_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
|
# REMOVE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -55,7 +47,7 @@ ynh_remove_nginx_config
|
||||||
# Delete Log
|
# Delete Log
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_secure_remove "/var/log/$app/"
|
ynh_secure_remove "/var/log/$app.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE LOGROTATE CONFIGURATION
|
# REMOVE LOGROTATE CONFIGURATION
|
||||||
|
@ -80,3 +72,9 @@ fi
|
||||||
|
|
||||||
# Remove metapackage and its dependencies
|
# Remove metapackage and its dependencies
|
||||||
ynh_remove_app_dependencies
|
ynh_remove_app_dependencies
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE THE PostgreSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_psql_remove_db $db_name $db_user
|
146
scripts/restore
146
scripts/restore
|
@ -1,97 +1,101 @@
|
||||||
#!/bin/bash
|
#!/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
|
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
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Get old parameter of the app
|
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
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)
|
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
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
echo yes | sudo cpan Carton
|
#=================================================
|
||||||
|
|
||||||
# Check domain/path availability
|
ynh_webpath_available $domain $path_url \
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "${app}" \
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
test ! -d $final_path \
|
||||||
|
|| ynh_die "There is already a directory: $final_path "
|
||||||
|
|
||||||
# Check $final_path
|
#=================================================
|
||||||
final_path="/var/www/${app}"
|
# STANDARD RESTORATION STEPS
|
||||||
if [ -d "${final_path}" ]; then
|
#=================================================
|
||||||
ynh_die "There is already a directory: ${final_path}"
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
fi
|
#=================================================
|
||||||
|
|
||||||
# Check configuration files nginx
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
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
|
|
||||||
|
|
||||||
# Check configuration files lstu
|
#=================================================
|
||||||
lstu_conf="${final_path}/${app}.conf"
|
# RESTORE THE APP MAIN DIR
|
||||||
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
|
|
||||||
|
|
||||||
lstu_systemd="/etc/systemd/system/${app}.service"
|
ynh_restore_file "$final_path"
|
||||||
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
|
|
||||||
|
|
||||||
lstu_logrotate="/etc/logrotate.d/${app}"
|
#=================================================
|
||||||
if [ -f "${lstu_logrotate}" ]; then
|
# RESTORE THE MYSQL DATABASE
|
||||||
ynh_die "The LSTU LOGROTATE configuration already exists at '${lstu_logrotate}'. You should safely delete it before restoring this app."
|
#=================================================
|
||||||
fi
|
|
||||||
|
|
||||||
lstu_log="/var/log/${app}/production.log"
|
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
||||||
if [ -f "${lstu_log}" ]; then
|
ynh_psql_setup_db $db_name $db_name $db_pwd
|
||||||
ynh_die "The LSTU LOG configuration already exists at '${lstu_log}'. You should safely delete it before restoring this app."
|
ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||||
fi
|
|
||||||
|
|
||||||
# Restore sources & data
|
#=================================================
|
||||||
sudo cp -a ./sources "${final_path}"
|
# SPECIFIC RESTORATION
|
||||||
|
#=================================================
|
||||||
|
# REINSTALL DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Set permissions
|
# Define and install dependencies
|
||||||
sudo chown -R www-data: "${final_path}"
|
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
|
ynh_restore_file "/etc/systemd/system/$app.service"
|
||||||
sudo cp -a ./lstu.conf "${lstu_conf}"
|
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}/"
|
# RESTORE THE LOGROTATE CONFIGURATION
|
||||||
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"
|
|
||||||
|
|
||||||
# Reload lstu service
|
ynh_restore_file "/etc/logrotate.d/$app"
|
||||||
sudo systemctl daemon-reload
|
|
||||||
sudo systemctl start lstu.service
|
|
||||||
sudo systemctl enable lstu.service
|
|
||||||
|
|
||||||
# Set ssowat config
|
#=================================================
|
||||||
if [ $is_public -eq 0 ];
|
# GENERIC FINALIZATION
|
||||||
then
|
#=================================================
|
||||||
ynh_app_setting_delete $app skipped_uris
|
# RELOAD NGINX
|
||||||
fi
|
#=================================================
|
||||||
|
|
||||||
# Reload services
|
systemctl reload nginx
|
||||||
sudo systemctl reload nginx
|
yunohost app ssowatconf
|
||||||
sudo yunohost app ssowatconf
|
|
||||||
|
|
129
scripts/upgrade
129
scripts/upgrade
|
@ -1,17 +1,25 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# vim:set noexpandtab:
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC STARTING
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source .fonctions
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
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
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -19,11 +27,14 @@ source /usr/share/yunohost/helpers
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
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)
|
is_public=$(ynh_app_setting_get $app is_public)
|
||||||
port=$(ynh_app_setting_get $app port)
|
port=$(ynh_app_setting_get $app port)
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
secret=$(ynh_app_setting_get $app secret)
|
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
|
# 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
|
final_path=/var/www/$app
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CHECK_PATH # Checks and corrects the syntax of the path.
|
#=================================================
|
||||||
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Get source
|
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql
|
||||||
SETUP_SOURCE
|
|
||||||
|
ynh_setup_source "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Copy Nginx configuration file
|
# Create a dedicated nginx config
|
||||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
ynh_add_nginx_config
|
||||||
# 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
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC UPGRADE
|
# SPECIFIC UPGRADE
|
||||||
|
@ -68,65 +74,78 @@ fi
|
||||||
# SETUP LSTU
|
# SETUP LSTU
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
## Copie et configuration du fichier de conf.
|
ynh_backup_if_checksum_is_different "$final_path/lstu.conf"
|
||||||
CHECK_MD5_CONFIG "lstu.conf" "$final_path/lstu.conf" # Créé un backup du fichier de config si il a été modifié.
|
cp ../conf/lstu.conf.template "${final_path}/lstu.conf"
|
||||||
sudo cp ../conf/lstu.conf.template "$final_path/lstu.conf"
|
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf"
|
||||||
sudo sed -i "s@__DOMAIN__@$domain@g" "$final_path/lstu.conf"
|
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf"
|
||||||
sudo sed -i "s@__PATH__@$path@g" "$final_path/lstu.conf"
|
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf"
|
||||||
sudo sed -i "s@__PORT__@$port@g" "$final_path/lstu.conf"
|
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf"
|
||||||
sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lstu.conf"
|
ynh_replace_string "__DB_USER__" "$db_user" "${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_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf"
|
||||||
|
|
||||||
#=================================================
|
secret=$(ynh_string_random 24)
|
||||||
# SETUP SYSTEMD
|
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
|
||||||
#=================================================
|
ynh_store_file_checksum "${final_path}/lstu.conf"
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SECURING FILES AND DIRECTORIES
|
# 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
|
# RESTART LSTU
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
sudo systemctl start lstu.service
|
systemctl reload $app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
# Make app public or private
|
||||||
ynh_app_setting_set $app skipped_uris "/"
|
ynh_app_setting_set $app skipped_uris "/"
|
||||||
if [ $is_public -eq 0 ];
|
if [ $is_public -eq 0 ];
|
||||||
then # If the app is private, only the shortened URLs are publics
|
then # If the app is private, only the shortened URLs are publics
|
||||||
if [ "$path" == "/" ]; then
|
if [ "$path_url" == "/" ]; then
|
||||||
path=""
|
path_url=""
|
||||||
fi
|
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
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RELOAD NGINX
|
# RELOAD NGINX
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
sudo systemctl reload nginx
|
systemctl reload nginx
|
||||||
sudo yunohost app ssowatconf
|
yunohost app ssowatconf
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
lstu-d4aec8a564f217b491cedd520191889a85569fd4-d4aec8a564f217b491cedd520191889a85569fd4
|
|
|
@ -1 +0,0 @@
|
||||||
306826bbae1d1f983296a5d880ed5709 lstu.zip
|
|
|
@ -1 +0,0 @@
|
||||||
https://framagit.org/luc/lstu/repository/archive.zip?ref=d4aec8a564f217b491cedd520191889a85569fd4
|
|
Loading…
Add table
Reference in a new issue