mirror of
https://github.com/YunoHost-Apps/zeronet_ynh.git
synced 2024-09-03 17:46:12 +02:00
Squashed commit of the following:
commit f64d3c0eca9ee13888524a07b8d178140b52620e Author: whypsi <whypsi@riseup.net> Date: Sat Mar 4 13:35:24 2017 +0100 Several improvements ZeroNet application is now owned by user Cleans up code
This commit is contained in:
parent
85990f80f4
commit
d87e7807c0
6 changed files with 34 additions and 85 deletions
BIN
ZeroNet.tar.gz
BIN
ZeroNet.tar.gz
Binary file not shown.
|
@ -1,11 +1,11 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=ZeroNet for USER
|
Description=ZeroNet for __USER__
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=USER
|
User=__USER__
|
||||||
ExecStart=/usr/bin/python2 ./zeronet.py --ui_port UI_PORT --data_dir DATA_DIR --log_dir LOG_DIR
|
ExecStart=/usr/bin/python2 ./zeronet.py --ui_port __UI_PORT__ --data_dir __DATA_DIR__ --log_dir __LOG_DIR__
|
||||||
WorkingDirectory=WORKING_DIRECTORY
|
WorkingDirectory=__WORKING_DIRECTORY__
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
KillMode=process
|
KillMode=process
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
|
|
|
@ -38,23 +38,13 @@ extract_archive() {
|
||||||
|
|
||||||
sudo mkdir --parents ${deploy_path}
|
sudo mkdir --parents ${deploy_path}
|
||||||
sudo tar --extract --file=${src_file} --directory=${deploy_path} --overwrite --strip-components 1
|
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() {
|
obtain_and_deploy_source() {
|
||||||
local app_config=$1
|
local app_config=$1
|
||||||
local deploy_path=$2
|
local deploy_path=$2
|
||||||
local symlink_to_deploy_path=$3
|
local symlink_to_deploy_path=$3
|
||||||
|
local user=$4
|
||||||
local src_url=$(app_config_get $app_config "SOURCE_URL")
|
local src_url=$(app_config_get $app_config "SOURCE_URL")
|
||||||
local src_checksum=$(app_config_get $app_config "SOURCE_SUM")
|
local src_checksum=$(app_config_get $app_config "SOURCE_SUM")
|
||||||
local src_file="/tmp/source.tar.gz"
|
local src_file="/tmp/source.tar.gz"
|
||||||
|
@ -64,4 +54,7 @@ obtain_and_deploy_source() {
|
||||||
extract_archive $src_file $deploy_path
|
extract_archive $src_file $deploy_path
|
||||||
|
|
||||||
sudo ln --symbolic --force $deploy_path $symlink_to_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
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,10 +51,9 @@ update_systemd_configuration() {
|
||||||
local service_name=$3
|
local service_name=$3
|
||||||
local service_file=$4
|
local service_file=$4
|
||||||
local user=$5
|
local user=$5
|
||||||
local group_id=$6
|
local port=$6
|
||||||
local port=$7
|
local symlink_to_deploy_path=$7
|
||||||
local symlink_to_deploy_path=$8
|
local zeronet_dir=$8
|
||||||
local zeronet_dir=$9
|
|
||||||
|
|
||||||
# create zeronet user data location
|
# create zeronet user data location
|
||||||
local data_dir=$zeronet_dir/data
|
local data_dir=$zeronet_dir/data
|
||||||
|
@ -62,17 +61,17 @@ update_systemd_configuration() {
|
||||||
|
|
||||||
sudo mkdir -p $data_dir
|
sudo mkdir -p $data_dir
|
||||||
sudo mkdir -p $log_dir
|
sudo mkdir -p $log_dir
|
||||||
sudo chown -R $user:$group_id $zeronet_dir
|
sudo chown -R $user: $zeronet_dir
|
||||||
|
|
||||||
# configure systemd service
|
# configure systemd service
|
||||||
sudo cp $service_template $service_file
|
sudo cp $service_template $service_file
|
||||||
|
|
||||||
sudo sed --in-place "s@USER@$user@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@__UI_PORT__@$port@g" $service_file
|
||||||
sudo sed --in-place "s@APP_NAME@$app@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@__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@__DATA_DIR__@$data_dir@g" $service_file
|
||||||
sudo sed --in-place "s@LOG_DIR@$log_dir@g" $service_file
|
sudo sed --in-place "s@__LOG_DIR__@$log_dir@g" $service_file
|
||||||
|
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
sudo systemctl enable $service_name
|
sudo systemctl enable $service_name
|
||||||
|
@ -103,7 +102,6 @@ main() {
|
||||||
local domain=$YNH_APP_ARG_DOMAIN
|
local domain=$YNH_APP_ARG_DOMAIN
|
||||||
local user=$YNH_APP_ARG_ADMIN
|
local user=$YNH_APP_ARG_ADMIN
|
||||||
|
|
||||||
local group_id=`id -g $user`
|
|
||||||
local port=$( ynh_find_port 43110 ) # the port zeronet listens on
|
local port=$( ynh_find_port 43110 ) # the port zeronet listens on
|
||||||
|
|
||||||
local path="/"
|
local path="/"
|
||||||
|
@ -131,23 +129,23 @@ main() {
|
||||||
ynh_app_setting_set $app path $path
|
ynh_app_setting_set $app path $path
|
||||||
ynh_app_setting_set $app url $url
|
ynh_app_setting_set $app url $url
|
||||||
ynh_app_setting_set $app admin $user
|
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 deploy_path $deploy_path
|
||||||
ynh_app_setting_set $app symlink_to_deploy_path $symlink_to_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 port $port
|
||||||
ynh_app_setting_set $app installed_version $source_version
|
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 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 user_zeronet_dir $user_zeronet_dir
|
||||||
ynh_app_setting_set $app systemd_service_name $systemd_service_name
|
ynh_app_setting_set $app systemd_service_name $systemd_service_name
|
||||||
ynh_app_setting_set $app systemd_service_file $systemd_service_file
|
ynh_app_setting_set $app systemd_service_file $systemd_service_file
|
||||||
|
|
||||||
install_dependencies
|
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_nginx_configuration $app $nginx_config_template $nginx_config_file $path $port
|
||||||
update_systemd_configuration $app $systemd_service_template $systemd_service_name $systemd_service_file \
|
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
|
main
|
||||||
|
|
|
@ -11,7 +11,6 @@ main() {
|
||||||
local systemd_service_name=$( ynh_app_setting_get $app systemd_service_name )
|
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 systemd_service_file=$( ynh_app_setting_get $app systemd_service_file )
|
||||||
local user=$( ynh_app_setting_get $app user )
|
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 user_zeronet_dir=$( ynh_app_setting_get $app user_zeronet_dir )
|
||||||
|
|
||||||
local url=$(ynh_app_setting_get $app url)
|
local url=$(ynh_app_setting_get $app url)
|
||||||
|
@ -19,12 +18,13 @@ main() {
|
||||||
sudo yunohost app checkurl $url -a $app
|
sudo yunohost app checkurl $url -a $app
|
||||||
|
|
||||||
sudo cp -a "./sources" $deploy_path
|
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 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 rm -rf $user_zeronet_dir
|
||||||
sudo cp -aR "./conf/.zeronet" $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 cp -a "./conf/nginx.conf" $nginx_config_file
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
|
@ -6,47 +6,9 @@ set -eu
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
source functions.sh
|
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<len; i++))
|
|
||||||
do
|
|
||||||
[ "${installed[i]:-0}" -lt "${available[i]:-0}" ] && return 0
|
|
||||||
[ "${installed[i]:-0}" -gt "${available[i]:-0}" ] && return 1
|
|
||||||
done
|
|
||||||
|
|
||||||
# both versions are equal
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
local app=${YNH_APP_INSTANCE_NAME}
|
local app=${YNH_APP_INSTANCE_NAME}
|
||||||
|
local user=$( ynh_app_setting_get $app user )
|
||||||
local deploy_path=$( ynh_app_setting_get $app deploy_path )
|
local deploy_path=$( ynh_app_setting_get $app deploy_path )
|
||||||
local symlink_to_deploy_path=$( ynh_app_setting_get $app symlink_to_deploy_path )
|
local symlink_to_deploy_path=$( ynh_app_setting_get $app symlink_to_deploy_path )
|
||||||
local installed_version=$( ynh_app_setting_get $app installed_version )
|
local installed_version=$( ynh_app_setting_get $app installed_version )
|
||||||
|
@ -54,23 +16,19 @@ main() {
|
||||||
local app_config=../conf/app.src
|
local app_config=../conf/app.src
|
||||||
local source_version=$(app_config_get $app_config "SOURCE_VERSION")
|
local source_version=$(app_config_get $app_config "SOURCE_VERSION")
|
||||||
|
|
||||||
# if is_new_version_available $installed_version $source_version; then
|
local old_deploy_path=$deploy_path
|
||||||
local old_deploy_path=$deploy_path
|
local new_deploy_path=$( make_deploy_path $app $source_version )
|
||||||
local new_deploy_path=$( make_deploy_path $app $source_version )
|
|
||||||
|
|
||||||
obtain_and_deploy_source $app_config $new_deploy_path $symlink_to_deploy_path
|
obtain_and_deploy_source $app_config $new_deploy_path $symlink_to_deploy_path $user
|
||||||
#mock_obtain_and_deploy_source $new_deploy_path $symlink_to_deploy_path
|
|
||||||
|
|
||||||
sudo systemctl restart $systemd_service_name
|
sudo systemctl restart $systemd_service_name
|
||||||
|
|
||||||
ynh_app_setting_set $app installed_version $source_version
|
ynh_app_setting_set $app installed_version $source_version
|
||||||
ynh_app_setting_set $app deploy_path $new_deploy_path
|
ynh_app_setting_set $app deploy_path $new_deploy_path
|
||||||
|
|
||||||
|
if [ $new_deploy_path != $old_deploy_path ]; then
|
||||||
sudo rm -rf $old_deploy_path
|
sudo rm -rf $old_deploy_path
|
||||||
#else
|
fi
|
||||||
# echo "There is no new version of ZeroNet, nothing to upgrade!"
|
|
||||||
# ynh_die
|
|
||||||
#fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
main
|
||||||
|
|
Loading…
Add table
Reference in a new issue