From b5df934831ad02a4d56e2207fd944d97f422ebc0 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Mon, 1 Apr 2024 14:16:02 +0700 Subject: [PATCH] Self-update now will patch server to update latest softwares --- files/installers/20240401.1.sh | 106 +++++++++++++++++++++++++++++++++ files/installers/install.sh | 4 +- files/scripts/capima.sh | 25 +++++++- files/scripts/capima.version | 2 +- 4 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 files/installers/20240401.1.sh diff --git a/files/installers/20240401.1.sh b/files/installers/20240401.1.sh new file mode 100644 index 0000000..7fbf280 --- /dev/null +++ b/files/installers/20240401.1.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +# +# +# Capima patcher script for Ubuntu servers +# VERSION: 20240401.1 +# +# DO NOT RUN THIS SCRIPT MANUALLY UNLESS YOU KNOW WHAT YOU ARE DOING !!! +# + +OSNAME=`lsb_release -s -i` +OSVERSION=`lsb_release -s -r` +OSCODENAME=`lsb_release -s -c` +SUPPORTEDVERSION="16.04 18.04 20.04 22.04" +INSTALLPACKAGE="" +readonly SELF=$(basename "$0") + +function ReplaceWholeLine { + sed -i "s/$1.*/$2/" $3 +} + +function ReplaceTrueWholeLine { + sed -i "s/.*$1.*/$2/" $3 +} + +function CheckingRemoteAccessible { + echo -ne "\n\n\nChecking if $CAPIMAURL is accessible...\n" + + # send command to check wait 2 seconds inside jobs before trying + timeout 15 bash -c "curl -4 -I --silent $CAPIMAURL | grep 'HTTP/2 200' &>/dev/null" + status="$?" + if [[ "$status" -ne 0 ]]; then + clear +echo -ne "\n +################################################## +# Unable to connect to Capima server from this # +# Please take a coffee or take a nap and rerun # +# the installation script again! # +################################################## +\n\n\n +" + exit 1 + fi +} + +function PatchingServer { + echo -ne "Patching the server..." + + if [[ "$OSCODENAME" == 'jammy' ]]; then + apt-get remove nodejs -y; + apt-get purge nodejs; + apt-get install -y ca-certificates curl gnupg + mkdir -p /etc/apt/keyrings + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg + NODE_MAJOR=18 + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list + INSTALLPACKAGE+="nodejs php83rc php83rc-essentials" + fi + + if [[ ! -f "/opt/Capima/patched/$SELF" ]]; then + apt-get install $INSTALLPACKAGE -y; + touch "/opt/Capima/patched/$SELF"; + else + echo -ne "Server already patched. Exiting...\n" + exit 0 + fi +} + +# Checker +if [[ $EUID -ne 0 ]]; then + message="Capima patcher must be run as root!" + echo $message 1>&2 + exit 1 +fi + +if [[ "$OSNAME" != "Ubuntu" ]]; then + message="This patcher only support $OSNAME" + echo $message + exit 1 +fi + +if [[ $(uname -m) != "x86_64" ]]; then + message="This patcher only support x86_64 architecture" + echo $message + exit 1 +fi + +grep -q $OSVERSION <<< $SUPPORTEDVERSION +if [[ $? -ne 0 ]]; then + message="This patcher does not support $OSNAME $OSVERSION" + echo $message + exit 1 +fi + +CAPIMAURL="https://capima.nntoan.com" + +locale-gen en_US en_US.UTF-8 + +export LANGUAGE=en_US.utf8 +export LC_ALL=en_US.utf8 +export DEBIAN_FRONTEND=noninteractive + +# Checking if server is up +CheckingRemoteAccessible + +# Patch the server +PatchingServer \ No newline at end of file diff --git a/files/installers/install.sh b/files/installers/install.sh index ffd42f3..beb1791 100644 --- a/files/installers/install.sh +++ b/files/installers/install.sh @@ -119,13 +119,13 @@ function BootstrapInstaller { PIPEXEC="pip" - INSTALLPACKAGE+="libmysqlclient20 python-pip php70rc php70rc-essentials php71rc php71rc-essentials php72rc php72rc-essentials php73rc php73rc-essentials php74rc php74rc-essentials php80rc php80rc-essentials php81rc php81rc-essentials php82rc php82rc-essentials" + INSTALLPACKAGE+="libmysqlclient20 python-pip php70rc php70rc-essentials php71rc php71rc-essentials php72rc php72rc-essentials php73rc php73rc-essentials php74rc php74rc-essentials php80rc php80rc-essentials php81rc php81rc-essentials php82rc php82rc-essentials php83rc php83rc-essentials" elif [[ "$OSCODENAME" == 'focal' ]]; then add-apt-repository 'deb [arch=amd64] https://mirror.rackspace.com/mariadb/repo/10.4/ubuntu focal main' PIPEXEC="pip3" - INSTALLPACKAGE+="libmysqlclient21 python3-pip php72rc php72rc-essentials php73rc php73rc-essentials php74rc php74rc-essentials php80rc php80rc-essentials php81rc php81rc-essentials php82rc php82rc-essentials dirmngr gnupg libmagic-dev" + INSTALLPACKAGE+="libmysqlclient21 python3-pip php72rc php72rc-essentials php73rc php73rc-essentials php74rc php74rc-essentials php80rc php80rc-essentials php81rc php81rc-essentials php82rc php82rc-essentials php83rc php83rc-essentials dirmngr gnupg libmagic-dev" elif [[ "$OSCODENAME" == 'jammy' ]]; then add-apt-repository 'deb [arch=amd64] https://mirror.rackspace.com/mariadb/repo/10.6/ubuntu jammy main' diff --git a/files/scripts/capima.sh b/files/scripts/capima.sh index 9892bed..9a66fc8 100644 --- a/files/scripts/capima.sh +++ b/files/scripts/capima.sh @@ -3,7 +3,7 @@ # FILE: /usr/sbin/capima # DESCRIPTION: Capima Box Manager - Everything you need to use Capima Box! # AUTHOR: Toan Nguyen (htts://github.com/nntoan) -# VERSION: 1.4.0 +# VERSION: 1.4.1 # ------------------------------------------------------------------------------ # Use colors, but only if connected to a terminal, and that terminal @@ -107,7 +107,8 @@ declare -A PHPFPM_CONFDIRS=( ["php82"]="/etc/php82rc/fpm.d" ["php83"]="/etc/php83rc/fpm.d" ) -readonly VERSION="1.4.0" +readonly VERSION="1.4.1" +readonly PATCH_VERSION="20240401.1" readonly SELF=$(basename "$0") readonly UPDATE_BASE="${CAPIMAURL}/files/scripts" readonly PHP_EXTRA_CONFDIR="/etc/php-extra" @@ -1221,21 +1222,29 @@ function TailLogs { nginx) if [[ ${#nginxLogs} -gt 0 ]]; then tail -f ${nginxLogs} -n200 + else + exit; fi ;; apache) if [[ ${#httpdLogs} -gt 0 ]]; then tail -f ${httpdLogs} -n200 + else + exit; fi ;; fpm) if [[ ${#fpmLogs} -gt 0 ]]; then tail -f ${fpmLogs} -n200 + else + exit; fi ;; all|*) if [[ ${#allLogs} -gt 0 ]]; then tail -f ${allLogs} -n200 + else + exit; fi ;; esac @@ -1302,6 +1311,10 @@ function UpdateSelfAndInvoke { # Overwrite old file with new mv $0.tmp $0 + + # Patching + PatchAndInstall + echo -ne "...${NORMAL} ${GREEN}DONE${NORMAL} 🎉🎉🎉" echo "" @@ -1309,6 +1322,14 @@ function UpdateSelfAndInvoke { fi } +function PatchAndInstall { + # Patching + echo -ne "${GREEN}Patching Capima...${NORMAL}" + wget "$CAPIMAURL/files/installers/$PATCH_VERSION.sh" --quiet -O - | bash - + echo -ne "...${NORMAL} ${GREEN}DONE${NORMAL}" + echo "" +} + function Heading { echo "${BLUE} diff --git a/files/scripts/capima.version b/files/scripts/capima.version index e21e727..13175fd 100644 --- a/files/scripts/capima.version +++ b/files/scripts/capima.version @@ -1 +1 @@ -1.4.0 \ No newline at end of file +1.4.1 \ No newline at end of file