github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/debian/postinst (about) 1 #!/bin/bash 2 3 . /usr/share/debconf/confmodule 4 5 OS_DIR_BIN="/usr/bin" 6 OS_DIR_CONFIG="/etc/mysterium-node" 7 OS_DIR_LOG="/var/log/mysterium-node" 8 OS_DIR_RUN="/var/run/mysterium-node" 9 OS_DIR_DATA="/var/lib/mysterium-node" 10 OS_DIR_INSTALLATION="/usr/lib/mysterium-node/installation" 11 OS_DIR_INITD="/etc/init.d/" 12 OS_DIR_SYSTEMD="/lib/systemd/system" 13 14 DAEMON_USER=mysterium-node 15 DAEMON_GROUP=mysterium-node 16 DAEMON_DEFAULT=/etc/default/mysterium-node 17 18 function install_initd { 19 printf "Installing initd script '$OS_DIR_INITD/mysterium-node'..\n" \ 20 && cp -f $OS_DIR_INSTALLATION/initd.sh $OS_DIR_INITD/mysterium-node \ 21 && chmod +x $OS_DIR_INITD/mysterium-node 22 } 23 24 function install_systemd { 25 printf "Installing systemd script '$OS_DIR_SYSTEMD/mysterium-node.service'..\n" \ 26 && cp -f $OS_DIR_INSTALLATION/mysterium-node.service $OS_DIR_SYSTEMD/mysterium-node.service \ 27 && cp -f $OS_DIR_INSTALLATION/mysterium-consumer.service $OS_DIR_SYSTEMD/mysterium-consumer.service \ 28 && systemctl enable systemd-networkd.service \ 29 && systemctl enable mysterium-node \ 30 && systemctl restart mysterium-node 31 } 32 33 function install_update_rcd { 34 printf "Installing rc.d config..\n" \ 35 && update-rc.d mysterium-node defaults 36 } 37 38 function install_chkconfig { 39 printf "Installing chkconfig..\n" \ 40 && chkconfig --add mysterium-node 41 } 42 43 function ensure_paths { 44 iptables_path=`which iptables` 45 46 # validate utility against valid system paths 47 basepath=${iptables_path%/*} 48 echo "iptables basepath detected: ${basepath}" 49 if ! [[ ${basepath} =~ (^/usr/sbin|^/sbin|^/bin|^/usr/bin) ]]; then 50 echo "invalid basepath for dependency - check if system PATH has not been altered" 51 exit 1 52 fi 53 54 iptables_required_path="/usr/sbin/iptables" 55 56 if ! [[ -x ${iptables_required_path} ]]; then 57 ln -s ${iptables_path} ${iptables_required_path} 58 fi 59 } 60 61 printf "Creating user '$DAEMON_USER:$DAEMON_GROUP'...\n" \ 62 && useradd --system -U $DAEMON_USER -G root -s /bin/false -m -d $OS_DIR_DATA \ 63 && usermod -a -G root $DAEMON_USER \ 64 && chown -R -L $DAEMON_USER:$DAEMON_GROUP $OS_DIR_DATA 65 66 printf "Creating directories...\n" \ 67 && mkdir -p $OS_DIR_LOG $OS_DIR_CONFIG $OS_DIR_RUN $OS_DIR_DATA \ 68 && chown $DAEMON_USER:$DAEMON_GROUP $OS_DIR_LOG $OS_DIR_CONFIG $OS_DIR_RUN $OS_DIR_DATA 69 70 printf "Setting required capabilities...\n" \ 71 && setcap cap_net_admin+ep $OS_DIR_BIN/myst 72 73 ensure_paths 74 75 # Add defaults file, if it doesn't exist 76 if [[ ! -f $DAEMON_DEFAULT ]]; then 77 cp $OS_DIR_INSTALLATION/default $DAEMON_DEFAULT 78 fi 79 80 # TODO remove temporary fix for starting all services instead of wireguard. 81 sed -i 's/^SERVICE_OPTS="wireguard"$/SERVICE_OPTS=""/g' $DAEMON_DEFAULT 82 83 printf "\nInstallation successfully finished.\n" \ 84 && printf "Usage: service mysterium-node restart\n" 85 86 # Distribution-specific logic 87 if [[ -f /etc/redhat-release ]]; then 88 # RHEL-variant logic 89 which systemctl &>/dev/null 90 if [[ $? -eq 0 ]]; then 91 install_systemd || echo "got an error, ignoring - probably systemd-spawn issue" 92 else 93 # Assuming sysv 94 install_initd 95 install_chkconfig 96 fi 97 elif [[ -f /etc/debian_version ]]; then 98 # Debian/Ubuntu logic 99 which systemctl &>/dev/null 100 if [[ $? -eq 0 ]]; then 101 install_systemd || echo "got an error, ignoring - probably systemd-spawn issue" 102 else 103 # Assuming sysv 104 install_initd 105 install_update_rcd 106 fi 107 elif [[ -f /etc/os-release ]]; then 108 source /etc/os-release 109 if [[ $ID = "amzn" ]]; then 110 # Amazon Linux logic 111 install_initd 112 install_chkconfig 113 fi 114 fi 115 116 #DEBHELPER#