1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/weblate_ynh.git synced 2024-10-01 13:35:04 +02:00

Code cleanup

This commit is contained in:
Jean-Baptiste Holcroft 2017-10-04 15:22:54 +02:00
parent ba26794dd0
commit 639f95aa63
7 changed files with 28 additions and 37 deletions

View file

@ -10,7 +10,7 @@ ynh_psql_test_if_first_run() {
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 \
sed -i '/local\s*all\s*all\s*peer/i
local all all password' /etc/postgresql/9.4/main/pg_hba.conf
systemctl enable postgresql
systemctl reload postgresql
@ -51,7 +51,7 @@ ynh_psql_execute_as_root () {
ynh_psql_execute_file_as_root() {
file="$1"
db="$2"
su -c "psql $db" postgres < $file
su -c "psql $db" postgres < "$file"
}
# Create a database, an user and its password. Then store the password in the app's config

View file

@ -27,10 +27,9 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME
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)
db_pwd=$(ynh_app_setting_get $app pgsqlpwd)
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)
#=================================================
# STANDARD BACKUP STEPS

View file

@ -107,7 +107,6 @@ ynh_add_nginx_config
#=================================================
# Hub needs a home directory with a config file
smtp_pwd=$(ynh_string_random)
ynh_system_user_create "$app" "$final_path"
# Allow bash for our user, so he can use Hub
chsh --shell /bin/bash "$app"
@ -139,7 +138,7 @@ case "$arch" in
;;
esac
[[ $(sha256sum "$file_bin" | cut -d' ' -f1) = $sha256sum ]] || ynh_die "Hub's sha256sum failed (arch: ${arch})"
[[ $(sha256sum "$file_bin" | cut -d' ' -f1) = "$sha256sum" ]] || ynh_die "Hub's sha256sum failed (arch: ${arch})"
tar --extract --file "$file_bin" "$version/bin/hub"
mkdir "$final_path/bin/"
@ -207,7 +206,6 @@ ynh_replace_string "__DOMAIN__" "$domain" "$final_path/venv/lib/python2.7
ynh_replace_string "__KEY__" "$key" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
ynh_replace_string "__PATHURL__" "$path_url" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
ynh_replace_string "__SMTPPWD__" "$smtp_pwd" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
ynh_replace_string "__MEMCPORT__" "$memc_port" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
ynh_replace_string "__GITHUBUSER__" "$github_account" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
@ -233,7 +231,7 @@ ynh_replace_string "__GITHUBUSER__" "$github_account" "$final_path/venv/lib/pyth
#=================================================
# SETUP CRON
#=================================================
cp ../conf/cron_weblate "/etc/cron.d/$app"
cp ../conf/cron "/etc/cron.d/$app"
ynh_replace_string "__FINALPATH__" "$final_path/" "/etc/cron.d/$app"
#=================================================

View file

@ -5,7 +5,7 @@
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
set -eu
set -u
source _common.sh
source /usr/share/yunohost/helpers
@ -15,9 +15,7 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
db_name=$(ynh_app_setting_get "$app" db_name)
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
@ -87,4 +85,4 @@ ynh_secure_remove "/etc/systemd/system/$app.service"
#=================================================
# Delete a system user
ynh_system_user_delete $app
ynh_system_user_delete "$app"

View file

@ -27,12 +27,11 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
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)
domain=$(ynh_app_setting_get "$app" domain)
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)
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
smtp_pwd=$(ynh_app_setting_get $app smtppwd)
#=================================================
# CHECK IF THE APP CAN BE RESTORED

View file

@ -15,30 +15,27 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
smtp_pwd=$(ynh_app_setting_get $app smtppwd)
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)
domain=$(ynh_app_setting_get "$app" domain)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value
ynh_app_setting_set "$app" is_public 1 # Fix is_public as a boolean value
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
ynh_app_setting_set "$app" is_public 0
is_public=0
fi
if [ -z $db_name ]; then # If db_name doesn't exist, create it
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
if [ -z "$db_name" ]; then # If db_name doesn't exist, create it
db_name=$(ynh_sanitize_dbid "$app")
ynh_app_setting_set "$app" db_name "$db_name"
fi
#=================================================
@ -46,7 +43,7 @@ fi
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
path_url=$(ynh_normalize_url_path "$path_url")
#=================================================
# STANDARD UPGRADE STEPS
@ -92,7 +89,7 @@ chsh --shell /bin/bash "$app"
set +eu
source ${final_path}/venv/bin/activate
export DJANGO_SETTINGS_MODULE="weblate.settings"
cd ${final_path}
cd "${final_path}"
weblate migrate --noinput
)
@ -118,13 +115,13 @@ ynh_use_logrotate
if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete $app skipped_uris
ynh_app_setting_delete "$app" skipped_uris
fi
# 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 unprotected_uris "/"
ynh_app_setting_set "$app" unprotected_uris "/"
fi
#=================================================