2022-06-15 20:04:58 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-12-15 05:37:47 +00:00
|
|
|
|
2024-04-25 22:03:22 +00:00
|
|
|
SCRIPT_VERSION="153"
|
2022-03-18 18:09:58 +00:00
|
|
|
SCRIPT_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/update.sh'
|
|
|
|
LATEST_SETTINGS_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/api/tacticalrmm/tacticalrmm/settings.py'
|
2020-08-12 09:00:40 +00:00
|
|
|
YELLOW='\033[1;33m'
|
|
|
|
GREEN='\033[0;32m'
|
2020-09-20 21:29:21 +00:00
|
|
|
RED='\033[0;31m'
|
2020-08-12 09:00:40 +00:00
|
|
|
NC='\033[0m'
|
2021-03-23 07:39:06 +00:00
|
|
|
THIS_SCRIPT=$(readlink -f "$0")
|
2020-08-12 09:00:40 +00:00
|
|
|
|
2022-05-24 22:03:24 +00:00
|
|
|
SCRIPTS_DIR='/opt/trmm-community-scripts'
|
2024-02-29 02:09:33 +00:00
|
|
|
PYTHON_VER='3.11.8'
|
2022-05-24 22:03:24 +00:00
|
|
|
SETTINGS_FILE='/rmm/api/tacticalrmm/tacticalrmm/settings.py'
|
2024-02-29 01:56:19 +00:00
|
|
|
local_settings='/rmm/api/tacticalrmm/tacticalrmm/local_settings.py'
|
2022-01-24 05:07:08 +00:00
|
|
|
|
2020-08-12 09:00:40 +00:00
|
|
|
TMP_FILE=$(mktemp -p "" "rmmupdate_XXXXXXXXXX")
|
2023-03-21 05:57:24 +00:00
|
|
|
curl -s -L "${SCRIPT_URL}" >${TMP_FILE}
|
2020-08-12 09:00:40 +00:00
|
|
|
NEW_VER=$(grep "^SCRIPT_VERSION" "$TMP_FILE" | awk -F'[="]' '{print $3}')
|
|
|
|
|
2020-09-25 05:02:27 +00:00
|
|
|
if [ "${SCRIPT_VERSION}" -ne "${NEW_VER}" ]; then
|
2023-03-21 05:57:24 +00:00
|
|
|
printf >&2 "${YELLOW}Old update script detected, downloading and replacing with the latest version...${NC}\n"
|
|
|
|
wget -q "${SCRIPT_URL}" -O update.sh
|
|
|
|
exec ${THIS_SCRIPT}
|
2020-08-12 09:00:40 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f $TMP_FILE
|
|
|
|
|
2024-04-25 22:03:22 +00:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
2021-02-24 11:24:47 +00:00
|
|
|
force=false
|
|
|
|
if [[ $* == *--force* ]]; then
|
2023-03-21 05:57:24 +00:00
|
|
|
force=true
|
2021-02-24 11:24:47 +00:00
|
|
|
fi
|
|
|
|
|
2020-08-19 20:15:17 +00:00
|
|
|
if [ $EUID -eq 0 ]; then
|
|
|
|
echo -ne "\033[0;31mDo NOT run this script as root. Exiting.\e[0m\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-26 05:51:23 +00:00
|
|
|
sudo apt update
|
|
|
|
|
2020-09-20 21:29:21 +00:00
|
|
|
strip="User="
|
|
|
|
ORIGUSER=$(grep ${strip} /etc/systemd/system/rmm.service | sed -e "s/^${strip}//")
|
|
|
|
|
|
|
|
if [ "$ORIGUSER" != "$USER" ]; then
|
|
|
|
printf >&2 "${RED}ERROR: You must run this update script from the same user account used during install: ${GREEN}${ORIGUSER}${NC}\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-11-01 09:18:22 +00:00
|
|
|
TMP_SETTINGS=$(mktemp -p "" "rmmsettings_XXXXXXXXXX")
|
2023-03-21 05:57:24 +00:00
|
|
|
curl -s -L "${LATEST_SETTINGS_URL}" >${TMP_SETTINGS}
|
2020-11-01 09:18:22 +00:00
|
|
|
|
|
|
|
LATEST_TRMM_VER=$(grep "^TRMM_VERSION" "$TMP_SETTINGS" | awk -F'[= "]' '{print $5}')
|
|
|
|
CURRENT_TRMM_VER=$(grep "^TRMM_VERSION" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}')
|
|
|
|
|
2021-02-24 11:24:47 +00:00
|
|
|
if [[ "${CURRENT_TRMM_VER}" == "${LATEST_TRMM_VER}" ]] && ! [[ "$force" = true ]]; then
|
|
|
|
printf >&2 "${GREEN}Already on latest version. Current version: ${CURRENT_TRMM_VER} Latest version: ${LATEST_TRMM_VER}${NC}\n"
|
|
|
|
rm -f $TMP_SETTINGS
|
|
|
|
exit 0
|
2020-11-01 09:18:22 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
LATEST_MESH_VER=$(grep "^MESH_VER" "$TMP_SETTINGS" | awk -F'[= "]' '{print $5}')
|
|
|
|
LATEST_PIP_VER=$(grep "^PIP_VER" "$TMP_SETTINGS" | awk -F'[= "]' '{print $5}')
|
2021-08-29 08:13:04 +00:00
|
|
|
NATS_SERVER_VER=$(grep "^NATS_SERVER_VER" "$TMP_SETTINGS" | awk -F'[= "]' '{print $5}')
|
2020-11-01 09:18:22 +00:00
|
|
|
|
|
|
|
CURRENT_PIP_VER=$(grep "^PIP_VER" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}')
|
|
|
|
|
2021-04-04 01:13:27 +00:00
|
|
|
cls() {
|
|
|
|
printf "\033c"
|
|
|
|
}
|
|
|
|
|
2023-10-01 15:59:14 +00:00
|
|
|
if [ ! -d /etc/apt/keyrings ]; then
|
|
|
|
sudo mkdir -p /etc/apt/keyrings
|
|
|
|
fi
|
|
|
|
|
2021-12-09 00:06:33 +00:00
|
|
|
CHECK_NATS_LIMITNOFILE=$(grep LimitNOFILE /etc/systemd/system/nats.service)
|
|
|
|
if ! [[ $CHECK_NATS_LIMITNOFILE ]]; then
|
|
|
|
|
2023-03-21 05:57:24 +00:00
|
|
|
sudo rm -f /etc/systemd/system/nats.service
|
2021-12-09 00:06:33 +00:00
|
|
|
|
2023-03-21 05:57:24 +00:00
|
|
|
natsservice="$(
|
|
|
|
cat <<EOF
|
2021-12-09 00:06:33 +00:00
|
|
|
[Unit]
|
|
|
|
Description=NATS Server
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
PrivateTmp=true
|
|
|
|
Type=simple
|
|
|
|
ExecStart=/usr/local/bin/nats-server -c /rmm/api/tacticalrmm/nats-rmm.conf
|
|
|
|
ExecReload=/usr/bin/kill -s HUP \$MAINPID
|
|
|
|
ExecStop=/usr/bin/kill -s SIGINT \$MAINPID
|
|
|
|
User=${USER}
|
|
|
|
Group=www-data
|
|
|
|
Restart=always
|
|
|
|
RestartSec=5s
|
|
|
|
LimitNOFILE=1000000
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
2023-03-21 05:57:24 +00:00
|
|
|
)"
|
|
|
|
echo "${natsservice}" | sudo tee /etc/systemd/system/nats.service >/dev/null
|
|
|
|
sudo systemctl daemon-reload
|
2021-12-09 00:06:33 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-18 20:13:06 +00:00
|
|
|
printf >&2 "${GREEN}Stopping celery and celerybeat services (this might take a while)...${NC}\n"
|
2023-03-21 05:57:24 +00:00
|
|
|
for i in celerybeat celery; do
|
|
|
|
sudo systemctl stop ${i}
|
2023-01-18 20:13:06 +00:00
|
|
|
done
|
|
|
|
|
2023-03-21 05:57:24 +00:00
|
|
|
for i in nginx nats-api nats rmm daphne; do
|
|
|
|
printf >&2 "${GREEN}Stopping ${i} service...${NC}\n"
|
|
|
|
sudo systemctl stop ${i}
|
2020-11-01 09:18:22 +00:00
|
|
|
done
|
|
|
|
|
2024-06-11 00:31:53 +00:00
|
|
|
if ! grep -q V3 /etc/systemd/system/celerybeat.service; then
|
|
|
|
sudo rm -f /etc/systemd/system/celerybeat.service
|
|
|
|
|
|
|
|
celerybeatservice="$(
|
|
|
|
cat <<EOF
|
|
|
|
[Unit]
|
|
|
|
Description=Celery Beat Service V3
|
|
|
|
After=network.target redis-server.service postgresql.service
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
User=${USER}
|
|
|
|
Group=${USER}
|
|
|
|
EnvironmentFile=/etc/conf.d/celery.conf
|
|
|
|
WorkingDirectory=/rmm/api/tacticalrmm
|
|
|
|
ExecStart=/bin/sh -c '\${CELERY_BIN} -A \${CELERY_APP} beat --pidfile=\${CELERYBEAT_PID_FILE} --logfile=\${CELERYBEAT_LOG_FILE} --loglevel=\${CELERYD_LOG_LEVEL}'
|
|
|
|
ExecStartPre=rm -f /rmm/api/tacticalrmm/beat.pid
|
|
|
|
Restart=always
|
|
|
|
RestartSec=10s
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${celerybeatservice}" | sudo tee /etc/systemd/system/celerybeat.service >/dev/null
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
fi
|
|
|
|
|
2023-10-29 21:38:33 +00:00
|
|
|
# migrate daphne to uvicorn
|
|
|
|
if ! grep -q uvicorn /etc/systemd/system/daphne.service; then
|
2023-03-21 05:57:24 +00:00
|
|
|
sudo rm -f /etc/systemd/system/daphne.service
|
2022-10-07 17:15:37 +00:00
|
|
|
|
2023-10-29 21:38:33 +00:00
|
|
|
uviservice="$(
|
2023-03-21 05:57:24 +00:00
|
|
|
cat <<EOF
|
2022-10-07 17:15:37 +00:00
|
|
|
[Unit]
|
2023-10-29 21:38:33 +00:00
|
|
|
Description=uvicorn daemon v1
|
2022-10-07 17:15:37 +00:00
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
User=${USER}
|
|
|
|
Group=www-data
|
|
|
|
WorkingDirectory=/rmm/api/tacticalrmm
|
|
|
|
Environment="PATH=/rmm/api/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
2023-10-29 21:38:33 +00:00
|
|
|
ExecStart=/rmm/api/env/bin/uvicorn --uds /rmm/daphne.sock --forwarded-allow-ips='*' tacticalrmm.asgi:application
|
2022-10-07 17:15:37 +00:00
|
|
|
ExecStartPre=rm -f /rmm/daphne.sock
|
|
|
|
ExecStartPre=rm -f /rmm/daphne.sock.lock
|
|
|
|
Restart=always
|
|
|
|
RestartSec=3s
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
2023-03-21 05:57:24 +00:00
|
|
|
)"
|
2023-10-29 21:38:33 +00:00
|
|
|
echo "${uviservice}" | sudo tee /etc/systemd/system/daphne.service >/dev/null
|
2023-03-21 05:57:24 +00:00
|
|
|
sudo systemctl daemon-reload
|
2022-10-07 17:15:37 +00:00
|
|
|
fi
|
|
|
|
|
2023-10-28 01:41:50 +00:00
|
|
|
osname=$(lsb_release -si)
|
|
|
|
osname=${osname^}
|
|
|
|
osname=$(echo "$osname" | tr '[A-Z]' '[a-z]')
|
|
|
|
|
|
|
|
# for weasyprint
|
|
|
|
if [[ "$osname" == "debian" ]]; then
|
|
|
|
count=$(dpkg -l | grep -E "libpango-1.0-0|libpangoft2-1.0-0" | wc -l)
|
|
|
|
if ! [ "$count" -eq 2 ]; then
|
|
|
|
sudo apt install -y libpango-1.0-0 libpangoft2-1.0-0
|
|
|
|
fi
|
|
|
|
elif [[ "$osname" == "ubuntu" ]]; then
|
|
|
|
count=$(dpkg -l | grep -E "libpango-1.0-0|libharfbuzz0b|libpangoft2-1.0-0" | wc -l)
|
|
|
|
if ! [ "$count" -eq 3 ]; then
|
|
|
|
sudo apt install -y libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-07-26 08:09:49 +00:00
|
|
|
if [ ! -f /etc/apt/sources.list.d/nginx.list ]; then
|
2023-03-21 05:57:24 +00:00
|
|
|
codename=$(lsb_release -sc)
|
|
|
|
nginxrepo="$(
|
|
|
|
cat <<EOF
|
2023-10-01 15:59:14 +00:00
|
|
|
deb [signed-by=/etc/apt/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/$osname $codename nginx
|
2022-07-26 08:09:49 +00:00
|
|
|
EOF
|
2023-03-21 05:57:24 +00:00
|
|
|
)"
|
|
|
|
echo "${nginxrepo}" | sudo tee /etc/apt/sources.list.d/nginx.list >/dev/null
|
2024-06-24 05:51:36 +00:00
|
|
|
wget -qO - https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /etc/apt/keyrings/nginx-archive-keyring.gpg
|
2023-03-21 05:57:24 +00:00
|
|
|
sudo apt update
|
|
|
|
sudo apt install -y nginx
|
2022-07-26 08:09:49 +00:00
|
|
|
fi
|
|
|
|
|
2022-07-09 08:09:24 +00:00
|
|
|
nginxdefaultconf='/etc/nginx/nginx.conf'
|
2022-07-26 08:09:49 +00:00
|
|
|
CHECK_NGINX_WORKER_CONN=$(grep "worker_connections 4096" $nginxdefaultconf)
|
2021-01-17 01:16:28 +00:00
|
|
|
if ! [[ $CHECK_NGINX_WORKER_CONN ]]; then
|
2022-07-26 08:09:49 +00:00
|
|
|
printf >&2 "${GREEN}Changing nginx worker connections to 4096${NC}\n"
|
|
|
|
sudo sed -i 's/worker_connections.*/worker_connections 4096;/g' $nginxdefaultconf
|
2021-01-17 01:16:28 +00:00
|
|
|
fi
|
|
|
|
|
2022-07-09 08:09:24 +00:00
|
|
|
CHECK_NGINX_NOLIMIT=$(grep "worker_rlimit_nofile 1000000" $nginxdefaultconf)
|
|
|
|
if ! [[ $CHECK_NGINX_NOLIMIT ]]; then
|
2023-03-21 05:57:24 +00:00
|
|
|
sudo sed -i '/worker_rlimit_nofile.*/d' $nginxdefaultconf
|
|
|
|
printf >&2 "${GREEN}Increasing nginx open file limit${NC}\n"
|
|
|
|
sudo sed -i '1s/^/worker_rlimit_nofile 1000000;\
|
2022-07-09 08:09:24 +00:00
|
|
|
/' $nginxdefaultconf
|
|
|
|
fi
|
|
|
|
|
2023-12-11 18:36:08 +00:00
|
|
|
sudo sed -i 's/# server_names_hash_bucket_size.*/server_names_hash_bucket_size 256;/g' $nginxdefaultconf
|
2021-12-21 19:04:00 +00:00
|
|
|
|
2023-03-21 05:57:24 +00:00
|
|
|
if ! sudo nginx -t >/dev/null 2>&1; then
|
2022-07-26 08:09:49 +00:00
|
|
|
sudo nginx -t
|
|
|
|
echo -ne "\n"
|
|
|
|
echo -ne "${RED}You have syntax errors in your nginx configs. See errors above. Please fix them and re-run this script.${NC}\n"
|
|
|
|
echo -ne "${RED}Aborting...${NC}\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-03-20 01:58:54 +00:00
|
|
|
HAS_PY311=$(python3.11 --version | grep ${PYTHON_VER})
|
|
|
|
if ! [[ $HAS_PY311 ]]; then
|
2022-03-10 03:07:37 +00:00
|
|
|
printf >&2 "${GREEN}Updating to ${PYTHON_VER}${NC}\n"
|
2021-02-21 07:37:19 +00:00
|
|
|
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev
|
|
|
|
numprocs=$(nproc)
|
|
|
|
cd ~
|
2022-03-10 03:07:37 +00:00
|
|
|
wget https://www.python.org/ftp/python/${PYTHON_VER}/Python-${PYTHON_VER}.tgz
|
|
|
|
tar -xf Python-${PYTHON_VER}.tgz
|
|
|
|
cd Python-${PYTHON_VER}
|
2021-02-21 07:37:19 +00:00
|
|
|
./configure --enable-optimizations
|
|
|
|
make -j $numprocs
|
|
|
|
sudo make altinstall
|
|
|
|
cd ~
|
2022-03-10 03:07:37 +00:00
|
|
|
sudo rm -rf Python-${PYTHON_VER} Python-${PYTHON_VER}.tgz
|
2021-02-21 07:37:19 +00:00
|
|
|
fi
|
|
|
|
|
2023-07-04 08:53:06 +00:00
|
|
|
arch=$(uname -m)
|
|
|
|
nats_server='/usr/local/bin/nats-server'
|
|
|
|
|
2021-08-29 08:13:04 +00:00
|
|
|
HAS_LATEST_NATS=$(/usr/local/bin/nats-server -version | grep "${NATS_SERVER_VER}")
|
|
|
|
if ! [[ $HAS_LATEST_NATS ]]; then
|
|
|
|
printf >&2 "${GREEN}Updating nats to v${NATS_SERVER_VER}${NC}\n"
|
2021-03-16 17:03:02 +00:00
|
|
|
nats_tmp=$(mktemp -d -t nats-XXXXXXXXXX)
|
2023-07-04 08:53:06 +00:00
|
|
|
if [ "$arch" = "x86_64" ]; then
|
|
|
|
natsarch='amd64'
|
|
|
|
else
|
|
|
|
natsarch='arm64'
|
|
|
|
fi
|
|
|
|
wget https://github.com/nats-io/nats-server/releases/download/v${NATS_SERVER_VER}/nats-server-v${NATS_SERVER_VER}-linux-${natsarch}.tar.gz -P ${nats_tmp}
|
|
|
|
tar -xzf ${nats_tmp}/nats-server-v${NATS_SERVER_VER}-linux-${natsarch}.tar.gz -C ${nats_tmp}
|
|
|
|
sudo rm -f $nats_server
|
|
|
|
sudo mv ${nats_tmp}/nats-server-v${NATS_SERVER_VER}-linux-${natsarch}/nats-server /usr/local/bin/
|
|
|
|
sudo chmod +x $nats_server
|
|
|
|
sudo chown ${USER}:${USER} $nats_server
|
2021-03-16 17:03:02 +00:00
|
|
|
rm -rf ${nats_tmp}
|
|
|
|
fi
|
|
|
|
|
2022-03-10 03:07:37 +00:00
|
|
|
if [ -d ~/.npm ]; then
|
|
|
|
sudo rm -rf ~/.npm
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d ~/.cache ]; then
|
|
|
|
sudo rm -rf ~/.cache
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d ~/.config ]; then
|
|
|
|
sudo chown -R $USER:$GROUP ~/.config
|
|
|
|
fi
|
|
|
|
|
2023-12-30 01:20:40 +00:00
|
|
|
if ! which npm >/dev/null; then
|
|
|
|
sudo apt install -y npm
|
|
|
|
fi
|
|
|
|
|
2024-02-24 23:19:03 +00:00
|
|
|
# older distros still might not have npm after above command, due to recent changes to node apt packages which replaces nodesource with official node
|
|
|
|
# if we still don't have npm, force a switch to nodesource
|
|
|
|
if ! which npm >/dev/null; then
|
|
|
|
sudo systemctl stop meshcentral
|
|
|
|
sudo chown ${USER}:${USER} -R /meshcentral
|
|
|
|
sudo apt remove -y nodejs
|
|
|
|
sudo rm -rf /usr/lib/node_modules
|
|
|
|
|
2024-03-13 01:06:07 +00:00
|
|
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs
|
2024-02-24 23:19:03 +00:00
|
|
|
sudo npm install -g npm
|
|
|
|
|
|
|
|
cd /meshcentral
|
|
|
|
rm -rf node_modules/ package-lock.json
|
|
|
|
npm install
|
|
|
|
sudo systemctl start meshcentral
|
|
|
|
fi
|
|
|
|
|
2021-03-16 23:09:38 +00:00
|
|
|
sudo npm install -g npm
|
|
|
|
|
2024-02-24 23:19:03 +00:00
|
|
|
CURRENT_MESH_VER=$(cd /meshcentral/node_modules/meshcentral && node -p -e "require('./package.json').version")
|
|
|
|
if [[ "${CURRENT_MESH_VER}" != "${LATEST_MESH_VER}" ]] || [[ "$force" = true ]]; then
|
|
|
|
printf >&2 "${GREEN}Updating meshcentral from ${CURRENT_MESH_VER} to ${LATEST_MESH_VER}${NC}\n"
|
|
|
|
sudo systemctl stop meshcentral
|
|
|
|
sudo chown ${USER}:${USER} -R /meshcentral
|
|
|
|
cd /meshcentral
|
|
|
|
rm -rf node_modules/ package.json package-lock.json
|
|
|
|
mesh_pkg="$(
|
|
|
|
cat <<EOF
|
|
|
|
{
|
|
|
|
"dependencies": {
|
|
|
|
"archiver": "5.3.1",
|
|
|
|
"meshcentral": "${LATEST_MESH_VER}",
|
|
|
|
"otplib": "10.2.3",
|
|
|
|
"pg": "8.7.1",
|
|
|
|
"pgtools": "0.3.2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${mesh_pkg}" >/meshcentral/package.json
|
|
|
|
npm install
|
|
|
|
sudo systemctl start meshcentral
|
|
|
|
fi
|
|
|
|
|
2022-01-21 23:11:27 +00:00
|
|
|
# update from main repo
|
2020-11-01 09:18:22 +00:00
|
|
|
cd /rmm
|
2020-11-25 01:18:26 +00:00
|
|
|
git config user.email "admin@example.com"
|
|
|
|
git config user.name "Bob"
|
2020-11-01 09:18:22 +00:00
|
|
|
git fetch
|
|
|
|
git checkout master
|
|
|
|
git reset --hard FETCH_HEAD
|
|
|
|
git clean -df
|
|
|
|
git pull
|
|
|
|
|
2022-01-21 23:11:27 +00:00
|
|
|
# update from community-scripts repo
|
2022-01-24 05:07:08 +00:00
|
|
|
if [[ ! -d ${SCRIPTS_DIR} ]]; then
|
|
|
|
sudo mkdir -p ${SCRIPTS_DIR}
|
|
|
|
sudo chown ${USER}:${USER} ${SCRIPTS_DIR}
|
|
|
|
git clone https://github.com/amidaware/community-scripts.git ${SCRIPTS_DIR}/
|
|
|
|
cd ${SCRIPTS_DIR}
|
2022-01-21 23:11:27 +00:00
|
|
|
git config user.email "admin@example.com"
|
|
|
|
git config user.name "Bob"
|
|
|
|
else
|
2022-01-24 05:07:08 +00:00
|
|
|
cd ${SCRIPTS_DIR}
|
2022-01-21 23:11:27 +00:00
|
|
|
git config user.email "admin@example.com"
|
|
|
|
git config user.name "Bob"
|
|
|
|
git fetch
|
2022-01-22 04:27:14 +00:00
|
|
|
git checkout main
|
2022-01-21 23:11:27 +00:00
|
|
|
git reset --hard FETCH_HEAD
|
|
|
|
git clean -df
|
|
|
|
git pull
|
|
|
|
fi
|
|
|
|
|
2021-05-05 07:58:30 +00:00
|
|
|
SETUPTOOLS_VER=$(grep "^SETUPTOOLS_VER" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}')
|
|
|
|
WHEEL_VER=$(grep "^WHEEL_VER" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}')
|
|
|
|
|
2020-08-25 00:38:23 +00:00
|
|
|
sudo chown ${USER}:${USER} -R /rmm
|
2022-01-24 05:07:08 +00:00
|
|
|
sudo chown ${USER}:${USER} -R ${SCRIPTS_DIR}
|
2020-08-25 00:38:23 +00:00
|
|
|
sudo chown ${USER}:${USER} /var/log/celery
|
2020-09-08 02:57:05 +00:00
|
|
|
sudo chown ${USER}:${USER} -R /etc/conf.d/
|
2020-11-26 03:42:27 +00:00
|
|
|
sudo chown ${USER}:${USER} -R /etc/letsencrypt
|
2023-07-05 02:02:58 +00:00
|
|
|
|
|
|
|
if [ -d /rmmbackups ]; then
|
|
|
|
sudo chown ${USER}:${USER} -R /rmmbackups
|
|
|
|
fi
|
2023-05-11 18:59:39 +00:00
|
|
|
|
2022-04-09 17:09:54 +00:00
|
|
|
CHECK_CELERY_CONFIG=$(grep "autoscale=20,2" /etc/conf.d/celery.conf)
|
|
|
|
if ! [[ $CHECK_CELERY_CONFIG ]]; then
|
|
|
|
sed -i 's/CELERYD_OPTS=.*/CELERYD_OPTS="--time-limit=86400 --autoscale=20,2"/g' /etc/conf.d/celery.conf
|
|
|
|
fi
|
|
|
|
|
2024-02-29 01:56:19 +00:00
|
|
|
CHECK_ADMIN_ENABLED=$(grep ADMIN_ENABLED $local_settings)
|
2021-02-27 23:19:35 +00:00
|
|
|
if ! [[ $CHECK_ADMIN_ENABLED ]]; then
|
2023-03-21 05:57:24 +00:00
|
|
|
adminenabled="$(
|
|
|
|
cat <<EOF
|
2021-02-27 23:19:35 +00:00
|
|
|
ADMIN_ENABLED = False
|
|
|
|
EOF
|
2023-03-21 05:57:24 +00:00
|
|
|
)"
|
2024-02-29 01:56:19 +00:00
|
|
|
echo "${adminenabled}" | tee --append $local_settings >/dev/null
|
2021-02-27 23:19:35 +00:00
|
|
|
fi
|
|
|
|
|
2023-07-04 08:53:06 +00:00
|
|
|
if [ "$arch" = "x86_64" ]; then
|
|
|
|
natsapi='nats-api'
|
|
|
|
else
|
|
|
|
natsapi='nats-api-arm64'
|
|
|
|
fi
|
|
|
|
|
|
|
|
nats_api='/usr/local/bin/nats-api'
|
|
|
|
sudo cp /rmm/natsapi/bin/${natsapi} $nats_api
|
|
|
|
sudo chown ${USER}:${USER} $nats_api
|
|
|
|
sudo chmod +x $nats_api
|
2021-01-17 01:16:28 +00:00
|
|
|
|
2021-02-24 11:24:47 +00:00
|
|
|
if [[ "${CURRENT_PIP_VER}" != "${LATEST_PIP_VER}" ]] || [[ "$force" = true ]]; then
|
2020-11-01 09:18:22 +00:00
|
|
|
rm -rf /rmm/api/env
|
|
|
|
cd /rmm/api
|
2023-03-20 01:58:54 +00:00
|
|
|
python3.11 -m venv env
|
2020-11-01 09:18:22 +00:00
|
|
|
source /rmm/api/env/bin/activate
|
|
|
|
cd /rmm/api/tacticalrmm
|
|
|
|
pip install --no-cache-dir --upgrade pip
|
2021-05-05 01:41:39 +00:00
|
|
|
pip install --no-cache-dir setuptools==${SETUPTOOLS_VER} wheel==${WHEEL_VER}
|
2020-11-01 09:18:22 +00:00
|
|
|
pip install --no-cache-dir -r requirements.txt
|
|
|
|
else
|
|
|
|
source /rmm/api/env/bin/activate
|
|
|
|
cd /rmm/api/tacticalrmm
|
2020-11-26 03:42:27 +00:00
|
|
|
pip install -r requirements.txt
|
2020-11-01 09:18:22 +00:00
|
|
|
fi
|
|
|
|
|
2023-04-30 17:18:03 +00:00
|
|
|
if [ ! -d /opt/tactical/reporting/assets ]; then
|
2023-10-04 16:51:24 +00:00
|
|
|
sudo mkdir -p /opt/tactical/reporting/assets
|
2023-04-30 17:18:03 +00:00
|
|
|
fi
|
|
|
|
|
2023-07-09 03:08:16 +00:00
|
|
|
if [ ! -d /opt/tactical/reporting/schemas ]; then
|
|
|
|
sudo mkdir /opt/tactical/reporting/schemas
|
2023-05-01 14:32:21 +00:00
|
|
|
fi
|
|
|
|
|
2024-02-29 01:56:19 +00:00
|
|
|
sed -i '/^REDIS_HOST/d' $local_settings
|
|
|
|
|
2023-07-09 03:05:42 +00:00
|
|
|
sudo chown -R ${USER}:${USER} /opt/tactical
|
2023-05-01 14:32:21 +00:00
|
|
|
|
2020-08-13 01:53:24 +00:00
|
|
|
python manage.py pre_update_tasks
|
2022-03-20 09:00:33 +00:00
|
|
|
celery -A tacticalrmm purge -f
|
2024-02-24 23:19:03 +00:00
|
|
|
printf >&2 "${GREEN}Running database migrations (this might take a long time)...${NC}\n"
|
2019-12-15 05:37:47 +00:00
|
|
|
python manage.py migrate
|
2023-07-09 00:22:49 +00:00
|
|
|
python manage.py generate_json_schemas
|
2020-02-02 09:30:50 +00:00
|
|
|
python manage.py delete_tokens
|
2020-08-10 20:29:42 +00:00
|
|
|
python manage.py collectstatic --no-input
|
2020-11-26 03:42:27 +00:00
|
|
|
python manage.py reload_nats
|
2021-01-19 23:43:37 +00:00
|
|
|
python manage.py load_chocos
|
2021-06-30 06:45:50 +00:00
|
|
|
python manage.py create_installer_user
|
2021-11-13 21:30:01 +00:00
|
|
|
python manage.py create_natsapi_conf
|
2023-10-28 20:07:50 +00:00
|
|
|
python manage.py create_uwsgi_conf
|
2022-12-30 01:24:57 +00:00
|
|
|
python manage.py clear_redis_celery_locks
|
2020-08-13 01:53:24 +00:00
|
|
|
python manage.py post_update_tasks
|
2023-10-31 18:32:01 +00:00
|
|
|
echo "Running management commands...please wait..."
|
2022-05-24 22:03:24 +00:00
|
|
|
API=$(python manage.py get_config api)
|
|
|
|
WEB_VERSION=$(python manage.py get_config webversion)
|
2023-08-11 05:14:43 +00:00
|
|
|
FRONTEND=$(python manage.py get_config webdomain)
|
|
|
|
MESHDOMAIN=$(python manage.py get_config meshdomain)
|
2023-10-24 05:18:47 +00:00
|
|
|
WEBTAR_URL=$(python manage.py get_webtar_url)
|
2023-10-26 01:08:52 +00:00
|
|
|
CERT_PUB_KEY=$(python manage.py get_config certfile)
|
|
|
|
CERT_PRIV_KEY=$(python manage.py get_config keyfile)
|
2019-12-15 05:37:47 +00:00
|
|
|
deactivate
|
|
|
|
|
2023-08-11 05:14:43 +00:00
|
|
|
if grep -q manage_etc_hosts /etc/hosts; then
|
2023-08-11 22:07:59 +00:00
|
|
|
sudo sed -i '/manage_etc_hosts: true/d' /etc/cloud/cloud.cfg >/dev/null
|
|
|
|
if ! grep -q "manage_etc_hosts: false" /etc/cloud/cloud.cfg; then
|
|
|
|
echo -e "\nmanage_etc_hosts: false" | sudo tee --append /etc/cloud/cloud.cfg >/dev/null
|
2023-08-11 05:14:43 +00:00
|
|
|
sudo systemctl restart cloud-init >/dev/null
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-10-26 01:08:52 +00:00
|
|
|
rmmconf='/etc/nginx/sites-available/rmm.conf'
|
2023-10-28 20:07:50 +00:00
|
|
|
if ! grep -q "location /assets/" $rmmconf; then
|
2023-10-26 01:08:52 +00:00
|
|
|
printf >&2 "${YELLOW}WARNING!!!!\n\n"
|
|
|
|
printf >&2 "${rmmconf} will now be replaced due to changes needed for this update.\n\n"
|
|
|
|
printf >&2 "A backup of the existing config will be created in your home directory at ~/rmm.conf.nginx.bak\n\n"
|
|
|
|
printf >&2 "If you have made any custom or unsupported changes to this file please add them back in after this update.\n\n"
|
|
|
|
read -n 1 -s -r -p "Press any key to confirm you have read the above and continue..."
|
|
|
|
printf >&2 "\n${NC}\n"
|
|
|
|
cp $rmmconf ~/rmm.conf.nginx.bak
|
|
|
|
nginxrmm="$(
|
|
|
|
cat <<EOF
|
|
|
|
server_tokens off;
|
|
|
|
|
2023-10-28 20:07:50 +00:00
|
|
|
upstream tacticalrmm {
|
|
|
|
server unix:////rmm/api/tacticalrmm/tacticalrmm.sock;
|
2023-10-26 01:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
map \$http_user_agent \$ignore_ua {
|
|
|
|
"~python-requests.*" 0;
|
|
|
|
"~go-resty.*" 0;
|
|
|
|
default 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 80;
|
|
|
|
listen [::]:80;
|
|
|
|
server_name ${API};
|
|
|
|
return 301 https://\$server_name\$request_uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 443 ssl reuseport;
|
|
|
|
listen [::]:443 ssl;
|
|
|
|
server_name ${API};
|
|
|
|
client_max_body_size 300M;
|
|
|
|
access_log /rmm/api/tacticalrmm/tacticalrmm/private/log/access.log combined if=\$ignore_ua;
|
|
|
|
error_log /rmm/api/tacticalrmm/tacticalrmm/private/log/error.log;
|
|
|
|
ssl_certificate ${CERT_PUB_KEY};
|
|
|
|
ssl_certificate_key ${CERT_PRIV_KEY};
|
|
|
|
|
|
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
ssl_prefer_server_ciphers on;
|
|
|
|
ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
|
|
|
|
ssl_ecdh_curve secp384r1;
|
|
|
|
ssl_stapling on;
|
|
|
|
ssl_stapling_verify on;
|
|
|
|
add_header X-Content-Type-Options nosniff;
|
|
|
|
|
|
|
|
location /static/ {
|
|
|
|
root /rmm/api/tacticalrmm;
|
|
|
|
add_header "Access-Control-Allow-Origin" "https://${FRONTEND}";
|
|
|
|
}
|
|
|
|
|
|
|
|
location /private/ {
|
|
|
|
internal;
|
|
|
|
add_header "Access-Control-Allow-Origin" "https://${FRONTEND}";
|
|
|
|
alias /rmm/api/tacticalrmm/tacticalrmm/private/;
|
|
|
|
}
|
|
|
|
|
|
|
|
location /assets/ {
|
|
|
|
internal;
|
|
|
|
add_header "Access-Control-Allow-Origin" "https://${FRONTEND}";
|
|
|
|
alias /opt/tactical/reporting/assets/;
|
|
|
|
}
|
|
|
|
|
|
|
|
location ~ ^/ws/ {
|
|
|
|
proxy_pass http://unix:/rmm/daphne.sock;
|
|
|
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_set_header Upgrade \$http_upgrade;
|
|
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
|
|
|
|
proxy_redirect off;
|
|
|
|
proxy_set_header Host \$host;
|
|
|
|
proxy_set_header X-Real-IP \$remote_addr;
|
|
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
|
|
proxy_set_header X-Forwarded-Host \$server_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
location ~ ^/natsws {
|
|
|
|
proxy_pass http://127.0.0.1:9235;
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
|
|
|
proxy_set_header Host \$host;
|
|
|
|
proxy_set_header Upgrade \$http_upgrade;
|
|
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
proxy_set_header X-Forwarded-Host \$host:\$server_port;
|
|
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
|
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
|
|
|
}
|
|
|
|
|
|
|
|
location / {
|
2023-10-28 20:07:50 +00:00
|
|
|
uwsgi_pass tacticalrmm;
|
|
|
|
include /etc/nginx/uwsgi_params;
|
|
|
|
uwsgi_read_timeout 300s;
|
|
|
|
uwsgi_ignore_client_abort on;
|
2023-10-26 01:08:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${nginxrmm}" | sudo tee /etc/nginx/sites-available/rmm.conf >/dev/null
|
|
|
|
fi
|
|
|
|
|
2023-08-11 05:14:43 +00:00
|
|
|
CHECK_HOSTS=$(grep 127.0.1.1 /etc/hosts | grep "$API" | grep "$FRONTEND" | grep "$MESHDOMAIN")
|
|
|
|
HAS_11=$(grep 127.0.1.1 /etc/hosts)
|
|
|
|
|
|
|
|
if ! [[ $CHECK_HOSTS ]]; then
|
|
|
|
if [[ $HAS_11 ]]; then
|
|
|
|
sudo sed -i "/127.0.1.1/s/$/ ${API} ${FRONTEND} ${MESHDOMAIN}/" /etc/hosts
|
|
|
|
else
|
|
|
|
echo "127.0.1.1 ${API} ${FRONTEND} ${MESHDOMAIN}" | sudo tee --append /etc/hosts >/dev/null
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-05-24 22:03:24 +00:00
|
|
|
if [ -d /rmm/web ]; then
|
|
|
|
rm -rf /rmm/web
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d /var/www/rmm ]; then
|
|
|
|
sudo mkdir -p /var/www/rmm
|
2020-11-01 09:18:22 +00:00
|
|
|
fi
|
|
|
|
|
2022-05-24 22:03:24 +00:00
|
|
|
webtar="trmm-web-v${WEB_VERSION}.tar.gz"
|
2023-10-24 05:18:47 +00:00
|
|
|
wget -q ${WEBTAR_URL} -O /tmp/${webtar}
|
2019-12-15 05:37:47 +00:00
|
|
|
sudo rm -rf /var/www/rmm/dist
|
2022-05-24 22:03:24 +00:00
|
|
|
sudo tar -xzf /tmp/${webtar} -C /var/www/rmm
|
2023-03-21 05:57:24 +00:00
|
|
|
echo "window._env_ = {PROD_URL: \"https://${API}\"}" | sudo tee /var/www/rmm/dist/env-config.js >/dev/null
|
2019-12-15 05:37:47 +00:00
|
|
|
sudo chown www-data:www-data -R /var/www/rmm/dist
|
2022-05-24 22:03:24 +00:00
|
|
|
rm -f /tmp/${webtar}
|
2019-12-15 05:37:47 +00:00
|
|
|
|
2023-03-21 05:57:24 +00:00
|
|
|
for i in nats nats-api rmm daphne celery celerybeat nginx; do
|
|
|
|
printf >&2 "${GREEN}Starting ${i} service${NC}\n"
|
|
|
|
sudo systemctl start ${i}
|
2019-12-16 22:45:18 +00:00
|
|
|
done
|
2020-06-14 19:52:20 +00:00
|
|
|
|
2020-11-01 09:18:22 +00:00
|
|
|
rm -f $TMP_SETTINGS
|
2023-03-21 05:57:24 +00:00
|
|
|
printf >&2 "${GREEN}Update finished!${NC}\n"
|