From 0e921d3258a0f210cc86f643a1599aa7151dcd14 Mon Sep 17 00:00:00 2001 From: sh <37271604+shumvgolove@users.noreply.github.com> Date: Fri, 4 Oct 2024 08:57:07 +0000 Subject: [PATCH] scripts: preparations for new deployments (#1357) * scripts/install: allow specifying version * scripts/update: allow specifying version * scripts/services: allow 443 for smp, allow infinite startup --- README.md | 11 +++++++-- install.sh | 38 ++++++++++++++++++----------- scripts/main/simplex-servers-update | 20 ++++++++++++--- scripts/main/smp-server.service | 2 ++ scripts/main/xftp-server.service | 1 + 5 files changed, 52 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b43fe6920..b5cbca928 100644 --- a/README.md +++ b/README.md @@ -149,8 +149,15 @@ On Linux, you can deploy smp and xftp server using Docker. This will download im You can install and setup servers automatically using our script: ```sh -curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/simplex-chat/simplexmq/stable/install.sh -o simplex-server-install.sh \ -&& if echo 'c90886104cd640b2ed64921dba80e90691db36788e8d6dcc13d8f33f92f0ea54 simplex-server-install.sh' | sha256sum -c; then chmod +x ./simplex-server-install.sh && ./simplex-server-install.sh; rm ./simplex-server-install.sh; else echo "SHA-256 checksum is incorrect!" && rm ./simplex-server-install.sh; fi +curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/simplex-chat/simplexmq/stable/install.sh -o simplex-server-install.sh &&\ +if echo '53fcdb4ceab324316e2c4cda7e84dbbb344f32550a65975a7895425e5a1be757 simplex-server-install.sh' | sha256sum -c; then + chmod +x ./simplex-server-install.sh + ./simplex-server-install.sh + rm ./simplex-server-install.sh +else + echo "SHA-256 checksum is incorrect!" + rm ./simplex-server-install.sh +fi ``` ### Build from source diff --git a/install.sh b/install.sh index 461215f71..4974c8a3c 100755 --- a/install.sh +++ b/install.sh @@ -2,9 +2,6 @@ set -eu # Links to scripts/configs -bin="https://github.com/simplex-chat/simplexmq/releases/latest/download" -remote_version="$(curl --proto '=https' --tlsv1.2 -sSf -L https://api.github.com/repos/simplex-chat/simplexmq/releases/latest | grep -i "tag_name" | awk -F \" '{print $4}')" - scripts="https://raw.githubusercontent.com/simplex-chat/simplexmq/stable/scripts/main" scripts_systemd_smp="$scripts/smp-server.service" scripts_systemd_xftp="$scripts/xftp-server.service" @@ -57,7 +54,7 @@ ${GRN}1.${NC} Install latest binaries from GitHub releases: ${GRN}2.${NC} Create server directories: - smp: ${YLW}${path_conf_smp}${NC} - xftp: ${YLW}${path_conf_xftp}${NC} -${GRN}3.${NC} Setup user for each server: +${GRN}3.${NC} Setup user for server: - xmp: ${YLW}${user_smp}${NC} - xftp: ${YLW}${user_xftp}${NC} ${GRN}4.${NC} Create systemd services: @@ -67,9 +64,8 @@ ${GRN}5.${NC} Install stopscript (systemd), update and uninstallation script: - all: ${YLW}${path_bin_update}${NC}, ${YLW}${path_bin_uninstall}${NC}, ${YLW}${path_bin_stopscript}${NC} Press: - - ${GRN}ENTER${NC} to continue installing both xftp and smp servers - - ${GRN}1${NC} to install only smp server - - ${GRN}2${NC} to install only xftp server + - ${GRN}1${NC} to install smp server + - ${GRN}2${NC} to install xftp server - ${RED}Ctrl+C${NC} to cancel installation Selection: " @@ -83,6 +79,21 @@ Please checkout our server guides: To uninstall with full clean-up, simply run: ${YLW}sudo /usr/local/bin/simplex-servers-uninstall${NC} " +set_version() { + ver="${VER:-latest}" + + case "$ver" in + latest) + bin="https://github.com/simplex-chat/simplexmq/releases/latest/download" + remote_version="$(curl --proto '=https' --tlsv1.2 -sSf -L https://api.github.com/repos/simplex-chat/simplexmq/releases/latest | grep -i "tag_name" | awk -F \" '{print $4}')" + ;; + *) + bin="https://github.com/simplex-chat/simplexmq/releases/download/${ver}" + remote_version="${ver}" + ;; + esac +} + os_test() { . /etc/os-release @@ -155,6 +166,7 @@ checks() { exit 1 fi + set_version os_test mkdir -p $path_conf_info @@ -166,13 +178,11 @@ main() { printf "%b\n%b" "${BLU}$logo${NC}" "$welcome" read ans - if [ "$ans" = '1' ]; then - setup='smp' - elif [ "$ans" = '2' ]; then - setup='xftp' - else - setup='smp xftp' - fi + case "$ans" in + 1) setup='smp' ;; + 2) setup='xftp' ;; + *) printf 'Installation aborted.\n' && exit 0 ;; + esac printf "Installing binaries..." diff --git a/scripts/main/simplex-servers-update b/scripts/main/simplex-servers-update index 7e85ff777..dad3c25b9 100755 --- a/scripts/main/simplex-servers-update +++ b/scripts/main/simplex-servers-update @@ -2,8 +2,6 @@ set -eu # Links to scripts/configs -bin="https://github.com/simplex-chat/simplexmq/releases/latest/download" - scripts="https://raw.githubusercontent.com/simplex-chat/simplexmq/stable/scripts/main" scripts_systemd_smp="$scripts/smp-server.service" scripts_systemd_xftp="$scripts/xftp-server.service" @@ -76,6 +74,21 @@ installed_test() { set -u } +set_version() { + ver="${VER:-latest}" + + case "$ver" in + latest) + bin="https://github.com/simplex-chat/simplexmq/releases/latest/download" + remote_version="$(curl --proto '=https' --tlsv1.2 -sSf -L https://api.github.com/repos/simplex-chat/simplexmq/releases/latest | grep -i "tag_name" | awk -F \" '{print $4}')" + ;; + *) + bin="https://github.com/simplex-chat/simplexmq/releases/download/${ver}" + remote_version="${ver}" + ;; + esac +} + update_scripts() { curl --proto '=https' --tlsv1.2 -sSf -L "$scripts_update" -o "$path_tmp_bin_update" && chmod +x "$path_tmp_bin_update" curl --proto '=https' --tlsv1.2 -sSf -L "$scripts_uninstall" -o "$path_tmp_bin_uninstall" && chmod +x "$path_tmp_bin_uninstall" @@ -137,8 +150,6 @@ update_bins() { eval "bin=\$bin_${1}" eval "path_bin=\$path_bin_${1}" - remote_version="$(curl --proto '=https' --tlsv1.2 -sSf -L https://api.github.com/repos/simplex-chat/simplexmq/releases/latest | grep -i "tag_name" | awk -F \" '{print $4}')" - set_ver() { local_version='unset' sed -i -- "s/local_version_${1}=.*/local_version_${1}='${remote_version}'/" "$path_conf_info/release" @@ -192,6 +203,7 @@ checks() { exit 1 fi + set_version os_test installed_test diff --git a/scripts/main/smp-server.service b/scripts/main/smp-server.service index 3a845f1c6..6d365041d 100644 --- a/scripts/main/smp-server.service +++ b/scripts/main/smp-server.service @@ -9,7 +9,9 @@ ExecStart=/usr/local/bin/smp-server start +RTS -N -RTS ExecStopPost=/usr/local/bin/simplex-servers-stopscript smp-server LimitNOFILE=65535 KillSignal=SIGINT +TimeoutStartSec=infinity TimeoutStopSec=infinity +AmbientCapabilities=CAP_NET_BIND_SERVICE [Install] WantedBy=multi-user.target diff --git a/scripts/main/xftp-server.service b/scripts/main/xftp-server.service index 51c8b1cd9..fcde29bf8 100644 --- a/scripts/main/xftp-server.service +++ b/scripts/main/xftp-server.service @@ -9,6 +9,7 @@ ExecStart=/usr/local/bin/xftp-server start +RTS -N -RTS ExecStopPost=/usr/local/bin/simplex-servers-stopscript xftp-server LimitNOFILE=65535 KillSignal=SIGINT +TimeoutStartSec=infinity TimeoutStopSec=infinity AmbientCapabilities=CAP_NET_BIND_SERVICE