mirror of
https://github.com/YunoHost-Apps/pyinventory_ynh.git
synced 2024-09-03 20:16:09 +02:00
Use ynh_exec_as instead of sudo
This commit is contained in:
parent
0cfa0bd871
commit
83f4ee4a1d
3 changed files with 28 additions and 11 deletions
|
@ -72,3 +72,18 @@ ynh_redis_remove_db() {
|
|||
local db=$1
|
||||
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
|
||||
}
|
|
@ -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 "$final_path"
|
||||
|
||||
sudo mkdir -p "$log_path"
|
||||
sudo touch "${log_file}"
|
||||
mkdir -p "$log_path"
|
||||
touch "${log_file}"
|
||||
|
||||
#=================================================
|
||||
# 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
|
||||
|
||||
virtualenv --python=python3 "${final_path}/venv"
|
||||
sudo chown -R "$app" "$final_path"
|
||||
chown -R "$app" "$final_path"
|
||||
|
||||
#run source in a 'sub shell'
|
||||
(
|
||||
set +o nounset
|
||||
source "${final_path}/venv/bin/activate"
|
||||
set -o nounset
|
||||
sudo -u $app $final_path/venv/bin/pip install --upgrade pip
|
||||
sudo -u $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 pip
|
||||
ynh_exec_as $app $final_path/venv/bin/pip install --upgrade setuptools wheel psycopg2-binary
|
||||
ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pyinventory=="$pyinventory_version"
|
||||
)
|
||||
|
||||
#=================================================
|
||||
|
@ -238,6 +238,8 @@ ynh_script_progression --message="Reloading nginx web server..."
|
|||
|
||||
ynh_systemd_action --service_name="nginx" --action="reload"
|
||||
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Installation of $app completed" --last
|
||||
|
|
|
@ -95,9 +95,9 @@ sudo chown -R "$app" "$final_path"
|
|||
set +o nounset
|
||||
source "${final_path}/venv/bin/activate"
|
||||
set -o nounset
|
||||
sudo -u $app $final_path/venv/bin/pip install --upgrade pip
|
||||
sudo -u $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 pip
|
||||
ynh_exec_as $app $final_path/venv/bin/pip install --upgrade setuptools wheel psycopg2-binary
|
||||
ynh_exec_as $app $final_path/venv/bin/pip install --upgrade pyinventory=="$pyinventory_version"
|
||||
)
|
||||
|
||||
#=================================================
|
||||
|
|
Loading…
Reference in a new issue