1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/cjdns_ynh.git synced 2024-09-03 18:16:29 +02:00
cjdns_ynh/scripts/install
2024-05-17 13:33:19 +03:00

97 lines
3.9 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chmod +x "$install_dir/cjdroute"
#=================================================
# CONFIGURING CJDNS
#=================================================
ynh_script_progression --message="Configuring $app..." --weight=1
$install_dir/cjdroute --genconf | $install_dir/cjdroute --cleanconf > $install_dir/cjdroute.conf
jq '.security[0].setuser = 0' $install_dir/cjdroute.conf > $install_dir/cjdroute.conf.tmp && mv $install_dir/cjdroute.conf.tmp $install_dir/cjdroute.conf
jq '.security[0].seccomp = 0' $install_dir/cjdroute.conf > $install_dir/cjdroute.conf.tmp && mv $install_dir/cjdroute.conf.tmp $install_dir/cjdroute.conf
jq '.noBackground = 1' $install_dir/cjdroute.conf > $install_dir/cjdroute.conf.tmp && mv $install_dir/cjdroute.conf.tmp $install_dir/cjdroute.conf
#=================================================
# UPGRADE PEERS
#=================================================
ynh_script_progression --message="Getting $app peers..." --weight=1
# Fetch the JSON data
json=$(curl -s -A "ynh" https://vpn.anode.co/api/0.4/vpn/cjdns/peeringlines/)
echo "Got peering lines"
length=$(echo $json | jq '. | length')
ynh_script_progression --message="Adding $length $app peers..." --weight=1
for (( i=0; i<$length; i++ ))
do
# Parse the JSON data
ip=$(echo $json | jq -r --argjson i $i '.[$i].ip')
port=$(echo $json | jq -r --argjson i $i '.[$i].port')
login=$(echo $json | jq -r --argjson i $i '.[$i].login')
password=$(echo $json | jq -r --argjson i $i '.[$i].password')
publicKey=$(echo $json | jq -r --argjson i $i '.[$i].publicKey')
# Prepare the peer to be inserted
peer=$(jq -n \
--arg ip_port "$ip:$port" \
--arg login "$login" \
--arg password "$password" \
--arg publicKey "$publicKey" \
'{($ip_port): {"login": $login, "password": $password, "publicKey": $publicKey}}')
# Insert the peer into the cjdroute.conf file
jq --argjson peer "$peer" '(.interfaces.UDPInterface[] | select(.beaconPort == 64512) .connectTo) |= . + $peer' $install_dir/cjdroute.conf > $install_dir/cjdroute.conf.tmp
mv $install_dir/cjdroute.conf.tmp $install_dir/cjdroute.conf
done
cjdns_ipv6=$(jq -r '.ipv6' < $install_dir/cjdroute.conf)
ynh_app_setting_set --app=$app --key=cjdns_ipv6 --value=$cjdns_ipv6
#=================================================
# APP INITIAL CONFIGURATION
#=================================================
ynh_script_progression --message="Adding $app's configuration files..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
yunohost service add $app --description="Encrypted IPv6 network" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last