2019-12-15 05:37:47 +00:00
#!/bin/bash
2021-02-22 10:05:46 +00:00
SCRIPT_VERSION = "111"
2020-11-26 03:42:27 +00:00
SCRIPT_URL = 'https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/update.sh'
2020-11-01 09:18:22 +00:00
LATEST_SETTINGS_URL = 'https://raw.githubusercontent.com/wh1te909/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'
TMP_FILE = $( mktemp -p "" "rmmupdate_XXXXXXXXXX" )
curl -s -L " ${ SCRIPT_URL } " > ${ TMP_FILE }
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
2020-11-20 08:09:58 +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
printf >& 2 " ${ YELLOW } Script updated! Please re-run ./update.sh ${ NC } \n "
2020-08-12 09:00:40 +00:00
rm -f $TMP_FILE
exit 1
fi
rm -f $TMP_FILE
2021-02-22 10:05:46 +00:00
sudo apt update
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
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
2021-01-17 01:16:28 +00:00
CHECK_030_MIGRATION = $( grep natsapi /etc/nginx/sites-available/rmm.conf)
if ! [ [ $CHECK_030_MIGRATION ] ] ; then
printf >& 2 " ${ RED } Manual configuration changes required before continuing. ${ NC } \n "
printf >& 2 " ${ RED } Please follow the steps here and then re-run this update script. ${ NC } \n "
printf >& 2 " ${ GREEN } https://github.com/wh1te909/tacticalrmm/blob/develop/docs/migration-0.3.0.md ${ NC } \n "
exit 1
fi
CHECK_CELERY_V2 = $( grep V2 /etc/systemd/system/celery.service)
if ! [ [ $CHECK_CELERY_V2 ] ] ; then
printf >& 2 " ${ GREEN } Updating celery.service ${ NC } \n "
sudo systemctl stop celery.service
sudo rm -f /etc/systemd/system/celery.service
celeryservice = " $( cat << EOF
[ Unit]
Description = Celery Service V2
After = network.target redis-server.service postgresql.service
[ Service]
Type = forking
User = ${ USER }
Group = ${ USER }
EnvironmentFile = /etc/conf.d/celery.conf
WorkingDirectory = /rmm/api/tacticalrmm
ExecStart = /bin/sh -c '\${CELERY_BIN} -A \$CELERY_APP multi start \$CELERYD_NODES --pidfile=\${CELERYD_PID_FILE} --logfile=\${CELERYD_LOG_FILE} --loglevel="\${CELERYD_LOG_LEVEL}" \$CELERYD_OPTS'
ExecStop = /bin/sh -c '\${CELERY_BIN} multi stopwait \$CELERYD_NODES --pidfile=\${CELERYD_PID_FILE} --loglevel="\${CELERYD_LOG_LEVEL}"'
ExecReload = /bin/sh -c '\${CELERY_BIN} -A \$CELERY_APP multi restart \$CELERYD_NODES --pidfile=\${CELERYD_PID_FILE} --logfile=\${CELERYD_LOG_FILE} --loglevel="\${CELERYD_LOG_LEVEL}" \$CELERYD_OPTS'
Restart = always
RestartSec = 10s
[ Install]
WantedBy = multi-user.target
EOF
) "
echo " ${ celeryservice } " | sudo tee /etc/systemd/system/celery.service > /dev/null
sudo systemctl daemon-reload
sudo systemctl enable celery.service
fi
CHECK_CELERYBEAT_V2 = $( grep V2 /etc/systemd/system/celerybeat.service)
if ! [ [ $CHECK_CELERYBEAT_V2 ] ] ; then
printf >& 2 " ${ GREEN } Updating celerybeat.service ${ NC } \n "
sudo systemctl stop celerybeat.service
sudo rm -f /etc/systemd/system/celerybeat.service
celerybeatservice = " $( cat << EOF
[ Unit]
Description = Celery Beat Service V2
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}'
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
sudo systemctl enable celerybeat.service
fi
2020-11-01 09:18:22 +00:00
TMP_SETTINGS = $( mktemp -p "" "rmmsettings_XXXXXXXXXX" )
curl -s -L " ${ LATEST_SETTINGS_URL } " > ${ TMP_SETTINGS }
SETTINGS_FILE = "/rmm/api/tacticalrmm/tacticalrmm/settings.py"
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-20 10:33:21 +00:00
if [ [ $* != *--force* ] ] ; then
if [ [ " ${ CURRENT_TRMM_VER } " = = " ${ LATEST_TRMM_VER } " ] ] ; 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
fi
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}' )
LATEST_NPM_VER = $( grep "^NPM_VER" " $TMP_SETTINGS " | awk -F'[= "]' '{print $5}' )
CURRENT_PIP_VER = $( grep "^PIP_VER" " $SETTINGS_FILE " | awk -F'[= "]' '{print $5}' )
CURRENT_NPM_VER = $( grep "^NPM_VER" " $SETTINGS_FILE " | awk -F'[= "]' '{print $5}' )
2020-11-26 03:42:27 +00:00
2021-01-17 01:16:28 +00:00
if [ ! -f /etc/systemd/system/natsapi.service ] ; then
natsapi = " $( cat << EOF
2020-11-26 03:42:27 +00:00
[ Unit]
2021-01-17 01:16:28 +00:00
Description = Tactical NATS API
After = network.target rmm.service nginx.service nats.service
2020-11-26 03:42:27 +00:00
[ Service]
Type = simple
2021-01-17 01:16:28 +00:00
ExecStart = /usr/local/bin/nats-api
2020-11-26 03:42:27 +00:00
User = ${ USER }
2021-01-17 01:16:28 +00:00
Group = ${ USER }
2020-11-26 03:42:27 +00:00
Restart = always
RestartSec = 5s
[ Install]
WantedBy = multi-user.target
EOF
) "
2021-01-17 01:16:28 +00:00
echo " ${ natsapi } " | sudo tee /etc/systemd/system/natsapi.service > /dev/null
2020-11-26 03:42:27 +00:00
sudo systemctl daemon-reload
2021-01-17 01:16:28 +00:00
sudo systemctl enable natsapi.service
2020-11-26 03:42:27 +00:00
fi
2021-01-20 22:11:54 +00:00
if [ -f /etc/systemd/system/celery-winupdate.service ] ; then
printf >& 2 " ${ GREEN } Removing celery-winupdate.service ${ NC } \n "
sudo systemctl stop celery-winupdate.service
sudo systemctl disable celery-winupdate.service
sudo rm -f /etc/systemd/system/celery-winupdate.service
sudo systemctl daemon-reload
fi
for i in nginx nats natsapi rmm celery celerybeat
2020-11-01 09:18:22 +00:00
do
2020-11-19 07:18:48 +00:00
printf >& 2 " ${ GREEN } Stopping ${ i } service... ${ NC } \n "
2020-11-01 09:18:22 +00:00
sudo systemctl stop ${ i }
done
2021-01-30 04:28:27 +00:00
# forgot to add this in install script. catch any installs that don't have it enabled and enable it
sudo systemctl enable natsapi.service
2021-01-17 01:16:28 +00:00
CHECK_NGINX_WORKER_CONN = $( grep "worker_connections 2048" /etc/nginx/nginx.conf)
if ! [ [ $CHECK_NGINX_WORKER_CONN ] ] ; then
printf >& 2 " ${ GREEN } Changing nginx worker connections to 2048 ${ NC } \n "
sudo sed -i 's/worker_connections.*/worker_connections 2048;/g' /etc/nginx/nginx.conf
fi
2021-02-17 23:26:56 +00:00
CHECK_HAS_GO116 = $( /usr/local/rmmgo/go/bin/go version | grep go1.16)
if ! [ [ $CHECK_HAS_GO116 ] ] ; then
printf >& 2 " ${ GREEN } Updating golang to version 1.16 ${ NC } \n "
sudo rm -rf /home/${ USER } /go/
sudo rm -rf /usr/local/rmmgo/
sudo mkdir -p /usr/local/rmmgo
go_tmp = $( mktemp -d -t rmmgo-XXXXXXXXXX)
wget https://golang.org/dl/go1.16.linux-amd64.tar.gz -P ${ go_tmp }
tar -xzf ${ go_tmp } /go1.16.linux-amd64.tar.gz -C ${ go_tmp }
sudo mv ${ go_tmp } /go /usr/local/rmmgo/
rm -rf ${ go_tmp }
sudo chown -R $USER :$GROUP /home/${ USER } /.cache
fi
2021-02-21 07:37:19 +00:00
HAS_PY39 = $( which python3.9)
if ! [ [ $HAS_PY39 ] ] ; then
printf >& 2 " ${ GREEN } Updating to Python 3.9 ${ NC } \n "
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 ~
wget https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz
tar -xf Python-3.9.2.tgz
cd Python-3.9.2
./configure --enable-optimizations
make -j $numprocs
sudo make altinstall
cd ~
sudo rm -rf Python-3.9.2 Python-3.9.2.tgz
fi
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
2020-09-08 02:57:05 +00:00
2020-08-25 00:38:23 +00:00
sudo chown ${ USER } :${ USER } -R /rmm
sudo chown ${ USER } :${ USER } /var/log/celery
2020-09-08 02:57:05 +00:00
sudo chown ${ USER } :${ USER } -R /etc/conf.d/
2020-08-25 00:38:23 +00:00
sudo chown -R $USER :$GROUP /home/${ USER } /.npm
sudo chown -R $USER :$GROUP /home/${ USER } /.config
2020-08-25 18:09:45 +00:00
sudo chown -R $USER :$GROUP /home/${ USER } /.cache
2020-11-26 03:42:27 +00:00
sudo chown ${ USER } :${ USER } -R /etc/letsencrypt
sudo chmod 775 -R /etc/letsencrypt
2020-08-25 00:38:23 +00:00
2021-02-06 00:39:22 +00:00
CHECK_BUFF_SIZE = $( grep buffer-size /rmm/api/tacticalrmm/app.ini)
if ! [ [ $CHECK_BUFF_SIZE ] ] ; then
setbuff = " $( cat << EOF
buffer-size = 65535
EOF
) "
echo " ${ setbuff } " | tee --append /rmm/api/tacticalrmm/app.ini > /dev/null
fi
2021-01-21 23:58:31 +00:00
CHECK_REMOVE_SALT = $( grep KEEP_SALT /rmm/api/tacticalrmm/tacticalrmm/local_settings.py)
if ! [ [ $CHECK_REMOVE_SALT ] ] ; then
printf >& 2 " ${ YELLOW } This update removes salt from the rmm ${ NC } \n "
printf >& 2 " ${ YELLOW } You may continue to use salt on existing agents, but there will not be any more integration with tacticalrmm, and new agents will not install the salt-minion ${ NC } \n "
until [ [ $rmsalt = ~ ( y| n) ] ] ; do
echo -ne " ${ YELLOW } Would you like to remove salt? (recommended) [y/n] ${ NC } : "
read rmsalt
done
if [ [ $rmsalt = = "y" ] ] ; then
keepsalt = " $( cat << EOF
KEEP_SALT = False
EOF
) "
else
keepsalt = " $( cat << EOF
KEEP_SALT = True
EOF
) "
fi
echo " ${ keepsalt } " | tee --append /rmm/api/tacticalrmm/tacticalrmm/local_settings.py > /dev/null
if [ [ $rmsalt = = "y" ] ] ; then
2021-02-17 23:26:56 +00:00
printf >& 2 " ${ GREEN } Removing salt-master and salt-api ${ NC } \n "
2021-01-21 23:58:31 +00:00
for i in salt-api salt-master; do sudo systemctl stop $i ; sudo systemctl disable $i ; done
2021-01-22 09:34:08 +00:00
sudo apt remove -y --purge salt-master salt-api salt-common
2021-01-21 23:58:31 +00:00
else
sudo systemctl stop salt-api
sudo systemctl disable salt-api
fi
fi
2020-10-06 01:32:54 +00:00
/usr/local/rmmgo/go/bin/go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
sudo cp /rmm/api/tacticalrmm/core/goinstaller/bin/goversioninfo /usr/local/bin/
sudo chown ${ USER } :${ USER } /usr/local/bin/goversioninfo
sudo chmod +x /usr/local/bin/goversioninfo
2020-11-01 09:18:22 +00:00
2021-01-17 01:16:28 +00:00
sudo cp /rmm/natsapi/bin/nats-api /usr/local/bin
sudo chown ${ USER } :${ USER } /usr/local/bin/nats-api
sudo chmod +x /usr/local/bin/nats-api
2020-11-01 09:18:22 +00:00
if [ [ " ${ CURRENT_PIP_VER } " != " ${ LATEST_PIP_VER } " ] ] ; then
rm -rf /rmm/api/env
cd /rmm/api
2021-02-21 07:37:19 +00:00
python3.9 -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-02-21 07:37:19 +00:00
pip install --no-cache-dir setuptools = = 53.0.0 wheel = = 0.36.2
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
2020-08-13 01:53:24 +00:00
python manage.py pre_update_tasks
2019-12-15 05:37:47 +00:00
python manage.py migrate
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
2020-08-13 01:53:24 +00:00
python manage.py post_update_tasks
2019-12-15 05:37:47 +00:00
deactivate
2020-06-28 05:18:31 +00:00
rm -rf /rmm/web/dist
2020-11-26 03:42:27 +00:00
rm -rf /rmm/web/.quasar
2020-06-28 05:18:31 +00:00
cd /rmm/web
2020-11-01 09:18:22 +00:00
if [ [ " ${ CURRENT_NPM_VER } " != " ${ LATEST_NPM_VER } " ] ] ; then
rm -rf /rmm/web/node_modules
fi
2020-12-18 21:59:23 +00:00
npm install
2019-12-15 05:37:47 +00:00
npm run build
sudo rm -rf /var/www/rmm/dist
2020-11-01 09:18:22 +00:00
sudo cp -pr /rmm/web/dist /var/www/rmm/
2019-12-15 05:37:47 +00:00
sudo chown www-data:www-data -R /var/www/rmm/dist
2021-01-20 22:11:54 +00:00
for i in rmm celery celerybeat nginx nats natsapi
2019-12-16 22:45:18 +00:00
do
2020-11-19 07:18:48 +00:00
printf >& 2 " ${ GREEN } Starting ${ i } service ${ NC } \n "
2019-12-16 22:45:18 +00:00
sudo systemctl start ${ i }
done
2020-06-14 19:52:20 +00:00
2021-02-18 08:53:02 +00:00
CURRENT_MESH_VER = $( cd /meshcentral/node_modules/meshcentral && node -p -e "require('./package.json').version" )
2020-11-01 09:18:22 +00:00
if [ [ " ${ CURRENT_MESH_VER } " != " ${ LATEST_MESH_VER } " ] ] ; 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/
npm install meshcentral@${ LATEST_MESH_VER }
sudo systemctl start meshcentral
sleep 10
fi
2020-08-12 09:00:40 +00:00
2020-11-01 09:18:22 +00:00
rm -f $TMP_SETTINGS
2020-08-12 09:00:40 +00:00
printf >& 2 " ${ GREEN } Update finished! ${ NC } \n "