Skip to content

Commit

Permalink
Self-update now will patch server to update latest softwares
Browse files Browse the repository at this point in the history
  • Loading branch information
nntoan committed Apr 1, 2024
1 parent 620b029 commit b5df934
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 5 deletions.
106 changes: 106 additions & 0 deletions files/installers/20240401.1.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions files/installers/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
25 changes: 23 additions & 2 deletions files/scripts/capima.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1302,13 +1311,25 @@ function UpdateSelfAndInvoke {

# Overwrite old file with new
mv $0.tmp $0

# Patching
PatchAndInstall

echo -ne "...${NORMAL} ${GREEN}DONE${NORMAL} 🎉🎉🎉"
echo ""

exit 0
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}
Expand Down
2 changes: 1 addition & 1 deletion files/scripts/capima.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.0
1.4.1

0 comments on commit b5df934

Please sign in to comment.