diff --git a/ZeroNet.tar.gz b/ZeroNet.tar.gz deleted file mode 100644 index 7ed0c2a..0000000 Binary files a/ZeroNet.tar.gz and /dev/null differ diff --git a/conf/systemd.service.template b/conf/systemd.service.template index 9233ca0..eebd817 100644 --- a/conf/systemd.service.template +++ b/conf/systemd.service.template @@ -1,11 +1,11 @@ [Unit] -Description=ZeroNet for USER +Description=ZeroNet for __USER__ After=network.target [Service] -User=USER -ExecStart=/usr/bin/python2 ./zeronet.py --ui_port UI_PORT --data_dir DATA_DIR --log_dir LOG_DIR -WorkingDirectory=WORKING_DIRECTORY +User=__USER__ +ExecStart=/usr/bin/python2 ./zeronet.py --ui_port __UI_PORT__ --data_dir __DATA_DIR__ --log_dir __LOG_DIR__ +WorkingDirectory=__WORKING_DIRECTORY__ ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure diff --git a/scripts/functions.sh b/scripts/functions.sh index 7ad983d..c810641 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -38,23 +38,13 @@ extract_archive() { sudo mkdir --parents ${deploy_path} sudo tar --extract --file=${src_file} --directory=${deploy_path} --overwrite --strip-components 1 - sudo chown --recursive root: $deploy_path -} - -mock_obtain_and_deploy_source() { - local deploy_path=$1 - local symlink_to_deploy_path=$2 - local source_file=../ZeroNet.tar.gz - - extract_archive $source_file $deploy_path - - sudo ln --symbolic --force $deploy_path $symlink_to_deploy_path } obtain_and_deploy_source() { local app_config=$1 local deploy_path=$2 local symlink_to_deploy_path=$3 + local user=$4 local src_url=$(app_config_get $app_config "SOURCE_URL") local src_checksum=$(app_config_get $app_config "SOURCE_SUM") local src_file="/tmp/source.tar.gz" @@ -64,4 +54,7 @@ obtain_and_deploy_source() { extract_archive $src_file $deploy_path sudo ln --symbolic --force $deploy_path $symlink_to_deploy_path + + sudo chown $user: -LR $symlink_to_deploy_path + sudo chown $user: -h $symlink_to_deploy_path } diff --git a/scripts/install b/scripts/install index 75459e3..a66ebcb 100755 --- a/scripts/install +++ b/scripts/install @@ -51,10 +51,9 @@ update_systemd_configuration() { local service_name=$3 local service_file=$4 local user=$5 - local group_id=$6 - local port=$7 - local symlink_to_deploy_path=$8 - local zeronet_dir=$9 + local port=$6 + local symlink_to_deploy_path=$7 + local zeronet_dir=$8 # create zeronet user data location local data_dir=$zeronet_dir/data @@ -62,17 +61,17 @@ update_systemd_configuration() { sudo mkdir -p $data_dir sudo mkdir -p $log_dir - sudo chown -R $user:$group_id $zeronet_dir + sudo chown -R $user: $zeronet_dir # configure systemd service sudo cp $service_template $service_file - sudo sed --in-place "s@USER@$user@g" $service_file - sudo sed --in-place "s@UI_PORT@$port@g" $service_file - sudo sed --in-place "s@APP_NAME@$app@g" $service_file - sudo sed --in-place "s@WORKING_DIRECTORY@$symlink_to_deploy_path@g" $service_file - sudo sed --in-place "s@DATA_DIR@$data_dir@g" $service_file - sudo sed --in-place "s@LOG_DIR@$log_dir@g" $service_file + sudo sed --in-place "s@__USER__@$user@g" $service_file + sudo sed --in-place "s@__UI_PORT__@$port@g" $service_file + sudo sed --in-place "s@__APP_NAME__@$app@g" $service_file + sudo sed --in-place "s@__WORKING_DIRECTORY__@$symlink_to_deploy_path@g" $service_file + sudo sed --in-place "s@__DATA_DIR__@$data_dir@g" $service_file + sudo sed --in-place "s@__LOG_DIR__@$log_dir@g" $service_file sudo systemctl daemon-reload sudo systemctl enable $service_name @@ -103,7 +102,6 @@ main() { local domain=$YNH_APP_ARG_DOMAIN local user=$YNH_APP_ARG_ADMIN - local group_id=`id -g $user` local port=$( ynh_find_port 43110 ) # the port zeronet listens on local path="/" @@ -131,23 +129,23 @@ main() { ynh_app_setting_set $app path $path ynh_app_setting_set $app url $url ynh_app_setting_set $app admin $user - ynh_app_setting_set $app group_id $group_id ynh_app_setting_set $app deploy_path $deploy_path ynh_app_setting_set $app symlink_to_deploy_path $symlink_to_deploy_path ynh_app_setting_set $app port $port ynh_app_setting_set $app installed_version $source_version ynh_app_setting_set $app nginx_config_file $nginx_config_file + ynh_app_setting_set $app user $user ynh_app_setting_set $app user_zeronet_dir $user_zeronet_dir ynh_app_setting_set $app systemd_service_name $systemd_service_name ynh_app_setting_set $app systemd_service_file $systemd_service_file install_dependencies - obtain_and_deploy_source $app_config $deploy_path $symlink_to_deploy_path - #mock_obtain_and_deploy_source $deploy_path $symlink_to_deploy_path + + obtain_and_deploy_source $app_config $deploy_path $symlink_to_deploy_path $user update_nginx_configuration $app $nginx_config_template $nginx_config_file $path $port update_systemd_configuration $app $systemd_service_template $systemd_service_name $systemd_service_file \ - $user $group_id $port $symlink_to_deploy_path $user_zeronet_dir + $user $port $symlink_to_deploy_path $user_zeronet_dir } main diff --git a/scripts/restore b/scripts/restore index 40f0fc1..7059952 100755 --- a/scripts/restore +++ b/scripts/restore @@ -11,7 +11,6 @@ main() { local systemd_service_name=$( ynh_app_setting_get $app systemd_service_name ) local systemd_service_file=$( ynh_app_setting_get $app systemd_service_file ) local user=$( ynh_app_setting_get $app user ) - local group_id=$( ynh_app_setting_get $app group_id ) local user_zeronet_dir=$( ynh_app_setting_get $app user_zeronet_dir ) local url=$(ynh_app_setting_get $app url) @@ -19,12 +18,13 @@ main() { sudo yunohost app checkurl $url -a $app sudo cp -a "./sources" $deploy_path - sudo chown www-data:www-data $deploy_path -R sudo ln --symbolic --force $deploy_path $symlink_to_deploy_path + sudo chown $user: -LR $symlink_to_deploy_path + sudo chown $user: -h $symlink_to_deploy_path sudo rm -rf $user_zeronet_dir sudo cp -aR "./conf/.zeronet" $user_zeronet_dir - sudo chown -R $user:$group_id $user_zeronet_dir + sudo chown -R $user: $user_zeronet_dir sudo cp -a "./conf/nginx.conf" $nginx_config_file sudo service nginx reload diff --git a/scripts/upgrade b/scripts/upgrade index 8437f1f..2e25c64 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -6,47 +6,9 @@ set -eu source /usr/share/yunohost/helpers source functions.sh -# -# finds maximum in a sequence of numbers, # e.g. -# max 1 2 3 => 3 -# -max() { - local m=$1 - local other=$@ - - for n in $other - do - if [ $n -gt $m ]; then - m=$n - fi - done - echo $m -} - -# -# returns true if first paramter is greater than second where -# parameter is in "digit-dot" format, e.g. -# -# is_new_version_available 1.2.1 1.2.0 => true -# is_new_version_available 1.2.1 1.2 => true -# -is_new_version_available() { - local installed=( $(echo "$1" | tr '.' ' ') ) - local available=( $(echo "$2" | tr '.' ' ') ) - local len="$(max "${#installed[*]}" "${#available[*]}")" - - for ((i=0; i