diff --git a/scripts/_common.sh b/scripts/_common.sh index 3e6b5e1..c48820f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -43,6 +43,22 @@ fix_permissions() { } +install_apt_dependencies() { + sudo apt-get install -y -qq python-dev python-virtualenv supervisor libmysqlclient-dev +} + +create_unix_user() { + sudo mkdir -p /opt/yunohost + sudo useradd ihatemoney -d /opt/yunohost/ihatemoney/ --create-home || ynh_die "User creation failed" +} + +create_system_dirs() { + sudo install -o ihatemoney -g ihatemoney -m 755 -d \ + /var/log/ihatemoney \ + /etc/ihatemoney + sudo mkdir -p /opt/yunohost +} + ### Backported helpers (from testing) diff --git a/scripts/install b/scripts/install index e7177a6..8cf1987 100755 --- a/scripts/install +++ b/scripts/install @@ -56,12 +56,9 @@ trap exit_properly ERR ynh_app_setting_set $app domain $domain ynh_app_setting_set $app is_public "$is_public" -# Install debian packages dependencies -sudo apt-get install -y -qq python-dev python-virtualenv supervisor libmysqlclient-dev +install_apt_dependencies -# Create the dedicated user -sudo mkdir -p /opt/yunohost -sudo useradd ihatemoney -d /opt/yunohost/ihatemoney/ --create-home +create_unix_user # Install source fetch_and_extract /opt/yunohost/ihatemoney/src/ ihatemoney @@ -74,9 +71,7 @@ sudo /opt/yunohost/ihatemoney/venv/bin/pip install gunicorn>=19.3.0 MySQL-python # Fix permissions fix_permissions /opt/yunohost/ihatemoney/src -# Create various dirs -sudo install -o ihatemoney -g ihatemoney -m 755 \ - -d /var/log/ihatemoney /etc/ihatemoney +create_system_dirs # Configure gunicorn sudo install -o ihatemoney -g ihatemoney -m 644 \ diff --git a/scripts/restore b/scripts/restore index 770aad3..9a358eb 100644 --- a/scripts/restore +++ b/scripts/restore @@ -46,12 +46,9 @@ test -f $gunicorn_conf_path && ynh_die \ "The Gunicorn configuration already exists at '${gunicorn_conf_path}'. You should safely delete it before restoring this app." -# Install debian packages dependencies -sudo apt-get install -y -qq python-dev python-virtualenv supervisor libmysqlclient-dev +install_apt_dependencies -# Create the dedicated user -sudo mkdir -p /opt/yunohost/ -sudo useradd ihatemoney -d /opt/yunohost/ihatemoney/ --create-home +create_unix_user # Restore the app files sudo cp -a ./install_dir/. "$INSTALL_DIR" @@ -61,9 +58,7 @@ fix_permissions ${INSTALL_DIR}/src ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql -# Create various dirs -sudo install -o ihatemoney -g ihatemoney -m 755 \ - -d /var/log/ihatemoney /etc/ihatemoney +create_system_dirs # Restore settings sudo cp -a "conf/nginx.conf" "$nginx_conf_path"