1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pyinventory_ynh.git synced 2024-09-03 20:16:09 +02:00

Merge pull request #3 from YunoHost-Apps/patch

Patch
This commit is contained in:
Jens Diemer 2020-12-09 18:16:40 +01:00 committed by GitHub
commit 0b43669038
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 50 deletions

33
check_process Normal file
View file

@ -0,0 +1,33 @@
# See here for more information
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
admin="john" (USER)
is_public=1 (PUBLIC|public=1|private=0)
password="pass"
port="666" (PORT)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
backup_restore=1
multi_instance=1
port_already_use=0
change_url=1
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=CommitHash
name=Name and date of the commit.
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666&

View file

@ -72,3 +72,18 @@ ynh_redis_remove_db() {
local db=$1 local db=$1
redis-cli -n "$db" flushall redis-cli -n "$db" flushall
} }
#=================================================
# Execute a command as another user
# usage: ynh_exec_as USER COMMAND [ARG ...]
ynh_exec_as() {
local USER=$1
shift 1
if [[ $USER = $(whoami) ]]; then
eval "$@"
else
sudo -u "$USER" "$@"
fi
}

View file

@ -22,13 +22,6 @@ final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
domain=$(ynh_app_setting_get --app="$app" --key=domain) domain=$(ynh_app_setting_get --app="$app" --key=domain)
db_name=$(ynh_app_setting_get --app="$app" --key=db_name) db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping systemd services..."
ynh_systemd_action --service_name="$app" --action="stop"
#================================================= #=================================================
# DECLARE DATA AND CONF FILES TO BACKUP # DECLARE DATA AND CONF FILES TO BACKUP
#================================================= #=================================================
@ -66,12 +59,6 @@ ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_systemd_action --service_name="$app" --action="start"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -31,8 +31,8 @@ ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url"
mkdir -p "$public_path/media" "$public_path/static" mkdir -p "$public_path/media" "$public_path/static"
mkdir -p "$final_path" mkdir -p "$final_path"
sudo mkdir -p "$log_path" mkdir -p "$log_path"
sudo touch "${log_file}" touch "${log_file}"
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
@ -103,16 +103,16 @@ ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell
ynh_script_progression --message="Install PyInventory using PIP..." --weight=80 ynh_script_progression --message="Install PyInventory using PIP..." --weight=80
virtualenv --python=python3 "${final_path}/venv" virtualenv --python=python3 "${final_path}/venv"
sudo chown -R "$app" "$final_path" chown -R "$app" "$final_path"
#run source in a 'sub shell' #run source in a 'sub shell'
( (
set +o nounset set +o nounset
source "${final_path}/venv/bin/activate" source "${final_path}/venv/bin/activate"
set -o nounset set -o nounset
sudo -u $app $final_path/venv/bin/pip install --upgrade pip ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pip
sudo -u $app $final_path/venv/bin/pip install --upgrade setuptools wheel psycopg2-binary ynh_exec_as $app $final_path/venv/bin/pip install --upgrade setuptools wheel psycopg2-binary
sudo -u $app $final_path/venv/bin/pip install --upgrade pyinventory=="$pyinventory_version" ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pyinventory=="$pyinventory_version"
) )
#================================================= #=================================================
@ -191,7 +191,7 @@ ynh_use_logrotate "$log_file"
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add "$app" --log "${log_file}" yunohost service add $app --description="Web based management to catalog things" --log="${log_file}"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -200,9 +200,9 @@ yunohost service add "$app" --log "${log_file}"
#================================================= #=================================================
# Set permissions to app files # Set permissions to app files
sudo chown -R "$app" "$log_path" chown -R "$app" "$log_path"
sudo chown -R "$app" "$public_path" chown -R "$app" "$public_path"
sudo chown -R "$app" "$final_path" chown -R "$app" "$final_path"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -217,11 +217,12 @@ ynh_add_systemd_config --service="$app" --template="pyinventory.service"
#================================================= #=================================================
ynh_script_progression --message="Configuring SSOwat..." ynh_script_progression --message="Configuring SSOwat..."
# Make app public if necessary # Make app public if necessary or protect it
if [ "$is_public" -eq 1 ] if [ $is_public -eq 1 ]
then then
# unprotected_uris allows SSO credentials to be passed anyway. # Everyone can access the app.
ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/" # The "main" permission is automatically created before the install script.
ynh_permission_update --permission "main" --add "visitors"
fi fi
#================================================= #=================================================
@ -238,6 +239,8 @@ ynh_script_progression --message="Reloading nginx web server..."
ynh_systemd_action --service_name="nginx" --action="reload" ynh_systemd_action --service_name="nginx" --action="reload"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression --message="Installation of $app completed" --last

View file

@ -102,7 +102,7 @@ systemctl enable $app.service --quiet
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add "$app" --log "/var/log/$app/pyinventory.log" yunohost service add $app --description="Web based management to catalog things" --log="${log_file}"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION

View file

@ -88,16 +88,16 @@ ynh_add_systemd_config --service="$app" --template="pyinventory.service"
ynh_script_progression --message="Install pyinventory using PIP..." --weight=15 ynh_script_progression --message="Install pyinventory using PIP..." --weight=15
virtualenv --python=python3 "${final_path}/venv" virtualenv --python=python3 "${final_path}/venv"
sudo chown -R "$app" "$final_path" chown -R "$app" "$final_path"
#run source in a 'sub shell' #run source in a 'sub shell'
( (
set +o nounset set +o nounset
source "${final_path}/venv/bin/activate" source "${final_path}/venv/bin/activate"
set -o nounset set -o nounset
sudo -u $app $final_path/venv/bin/pip install --upgrade pip ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pip
sudo -u $app $final_path/venv/bin/pip install --upgrade setuptools wheel psycopg2-binary ynh_exec_as $app $final_path/venv/bin/pip install --upgrade setuptools wheel psycopg2-binary
sudo -u $app $final_path/venv/bin/pip install --upgrade pyinventory=="$pyinventory_version" ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pyinventory=="$pyinventory_version"
) )
#================================================= #=================================================
@ -180,7 +180,7 @@ ynh_use_logrotate --non-append
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add "$app" --log "${log_file}" yunohost service add $app --description="Web based management to catalog things" --log="${log_file}"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -189,21 +189,9 @@ yunohost service add "$app" --log "${log_file}"
#================================================= #=================================================
# Set permissions to app files # Set permissions to app files
sudo chown -R "$app" "$log_path" chown -R "$app" "$log_path"
sudo chown -R "$app" "$public_path" chown -R "$app" "$public_path"
sudo chown -R "$app" "$final_path" chown -R "$app" "$final_path"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Upgrading SSOwat configuration..."
# Make app public if necessary
if [ "$is_public" -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/"
fi
#================================================= #=================================================
# Start pyinventory via systemd # Start pyinventory via systemd