Skip to content

Commit

Permalink
arm64/deb12/ubuntu22 support, remove mongo, postgres 15 and node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Jul 4, 2023
1 parent 7c3a5fc commit af694f1
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 146 deletions.
15 changes: 8 additions & 7 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

SCRIPT_VERSION="24"
SCRIPT_VERSION="25"

GREEN='\033[0;32m'
YELLOW='\033[1;33m'
Expand All @@ -18,11 +18,11 @@ if [[ $* == *--schedule* ]]; then
crontab -l 2>/dev/null
echo "0 0 * * * /rmm/backup.sh --auto"
) | crontab -
if [ ! -d /rmmbackups ]; then

if [ ! -d /rmmbackups ]; then
sudo mkdir /rmmbackups
fi

if [ ! -d /rmmbackups/daily ]; then
sudo mkdir /rmmbackups/daily
fi
Expand All @@ -35,7 +35,7 @@ if [[ $* == *--schedule* ]]; then
sudo mkdir /rmmbackups/monthly
fi
sudo chown ${USER}:${USER} -R /rmmbackups

printf >&2 "${GREEN}Backups setup to run at midnight and rotate.${NC}\n"
exit 0
fi
Expand Down Expand Up @@ -70,7 +70,7 @@ POSTGRES_PW=$(/rmm/api/env/bin/python /rmm/api/tacticalrmm/manage.py get_config

pg_dump --dbname=postgresql://"${POSTGRES_USER}":"${POSTGRES_PW}"@127.0.0.1:5432/tacticalrmm | gzip -9 >${tmp_dir}/postgres/db-${dt_now}.psql.gz

tar -czvf ${tmp_dir}/meshcentral/mesh.tar.gz --exclude=/meshcentral/node_modules /meshcentral
node /meshcentral/node_modules/meshcentral --dbexport # for import to postgres

if grep -q postgres "/meshcentral/meshcentral-data/config.json"; then
if ! which jq >/dev/null; then
Expand All @@ -83,6 +83,8 @@ else
mongodump --gzip --out=${tmp_dir}/meshcentral/mongo
fi

tar -czvf ${tmp_dir}/meshcentral/mesh.tar.gz --exclude=/meshcentral/node_modules /meshcentral

sudo tar -czvf ${tmp_dir}/certs/etc-letsencrypt.tar.gz -C /etc/letsencrypt .

for i in rmm frontend meshcentral; do
Expand All @@ -93,7 +95,6 @@ sudo tar -czvf ${tmp_dir}/confd/etc-confd.tar.gz -C /etc/conf.d .

sudo cp ${sysd}/rmm.service ${sysd}/celery.service ${sysd}/celerybeat.service ${sysd}/meshcentral.service ${sysd}/nats.service ${sysd}/daphne.service ${sysd}/nats-api.service ${tmp_dir}/systemd/

cat /rmm/api/tacticalrmm/tacticalrmm/private/log/django_debug.log | gzip -9 >${tmp_dir}/rmm/debug.log.gz
cp /rmm/api/tacticalrmm/tacticalrmm/local_settings.py ${tmp_dir}/rmm/

if [[ $* == *--auto* ]]; then
Expand Down
126 changes: 74 additions & 52 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

SCRIPT_VERSION="73"
SCRIPT_VERSION="74"
SCRIPT_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/install.sh'

sudo apt install -y curl wget dirmngr gnupg lsb-release
Expand Down Expand Up @@ -30,8 +30,8 @@ fi
rm -f $TMP_FILE

arch=$(uname -m)
if [ "$arch" != "x86_64" ]; then
echo -ne "${RED}ERROR: Only x86_64 arch is supported, not ${arch}${NC}\n"
if [[ "$arch" != "x86_64" ]] && [[ "$arch" != "aarch64" ]]; then
echo -ne "${RED}ERROR: Only x86_64 and aarch64 is supported, not ${arch}${NC}\n"
exit 1
fi

Expand All @@ -49,19 +49,22 @@ codename=$(lsb_release -sc)
relno=$(lsb_release -sr | cut -d. -f1)
fullrelno=$(lsb_release -sr)

# Fallback if lsb_release -si returns anything else than Ubuntu, Debian or Raspbian
if [ ! "$osname" = "ubuntu" ] && [ ! "$osname" = "debian" ]; then
osname=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
osname=${osname^}
fi
not_supported() {
echo -ne "${RED}ERROR: Only Debian 11, Debian 12 and Ubuntu 22.04 are supported.${NC}\n"
}

# determine system
if ([ "$osname" = "ubuntu" ] && [ "$fullrelno" = "20.04" ]) || ([ "$osname" = "debian" ] && [ $relno -ge 10 ]); then
echo $fullrel
if [[ "$osname" == "debian" ]]; then
if [[ "$relno" -ne 11 && "$relno" -ne 12 ]]; then
not_supported
exit 1
fi
elif [[ "$osname" == "ubuntu" ]]; then
if [[ "$fullrelno" != "22.04" ]]; then
not_supported
exit 1
fi
else
echo $fullrel
echo -ne "${RED}Supported versions: Ubuntu 20.04, Debian 10 and 11\n"
echo -ne "Your system does not appear to be supported${NC}\n"
not_supported
exit 1
fi

Expand All @@ -78,16 +81,12 @@ if [[ "$LANG" != *".UTF-8" ]]; then
exit 1
fi

if ([ "$osname" = "ubuntu" ]); then
mongodb_repo="deb [arch=amd64] https://repo.mongodb.org/apt/$osname $codename/mongodb-org/4.4 multiverse"
# there is no bullseye repo yet for mongo so just use buster on debian 11
elif ([ "$osname" = "debian" ] && [ $relno -eq 11 ]); then
mongodb_repo="deb [arch=amd64] https://repo.mongodb.org/apt/$osname buster/mongodb-org/4.4 main"
if [ "$arch" = "x86_64" ]; then
pgarch='amd64'
else
mongodb_repo="deb [arch=amd64] https://repo.mongodb.org/apt/$osname $codename/mongodb-org/4.4 main"
pgarch='arm64'
fi

postgresql_repo="deb [arch=amd64] https://apt.postgresql.org/pub/repos/apt/ $codename-pgdg main"
postgresql_repo="deb [arch=${pgarch}] https://apt.postgresql.org/pub/repos/apt/ $codename-pgdg main"

# prevents logging issues with some VPS providers like Vultr if this is a freshly provisioned instance that hasn't been rebooted yet
sudo systemctl restart systemd-journald.service
Expand All @@ -98,6 +97,8 @@ MESHPASSWD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 25 | head -n 1)
pgusername=$(cat /dev/urandom | tr -dc 'a-z' | fold -w 8 | head -n 1)
pgpw=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1)
meshusername=$(cat /dev/urandom | tr -dc 'a-z' | fold -w 8 | head -n 1)
MESHPGUSER=$(cat /dev/urandom | tr -dc 'a-z' | fold -w 8 | head -n 1)
MESHPGPWD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1)

cls() {
printf "\033c"
Expand Down Expand Up @@ -136,11 +137,6 @@ while [[ $letsemail != *[@]*[.]* ]]; do
read letsemail
done

# if server is behind NAT we need to add the 3 subdomains to the host file
# so that nginx can properly route between the frontend, backend and meshcentral
# EDIT 8-29-2020
# running this even if server is __not__ behind NAT just to make DNS resolving faster
# this also allows the install script to properly finish even if DNS has not fully propagated
CHECK_HOSTS=$(grep 127.0.1.1 /etc/hosts | grep "$rmmdomain" | grep "$meshdomain" | grep "$frontenddomain")
HAS_11=$(grep 127.0.1.1 /etc/hosts)

Expand Down Expand Up @@ -230,21 +226,12 @@ done

print_green 'Installing NodeJS'

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt update
sudo apt install -y gcc g++ make
sudo apt install -y nodejs
sudo npm install -g npm

print_green 'Installing MongoDB'

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "$mongodb_repo" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt update
sudo apt install -y mongodb-org
sudo systemctl enable mongod
sudo systemctl restart mongod

print_green "Installing Python ${PYTHON_VER}"

sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev
Expand All @@ -268,7 +255,7 @@ echo "$postgresql_repo" | sudo tee /etc/apt/sources.list.d/pgdg.list

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
sudo apt install -y postgresql-14
sudo apt install -y postgresql-15
sleep 2
sudo systemctl enable --now postgresql

Expand All @@ -277,14 +264,27 @@ until pg_isready >/dev/null; do
sleep 3
done

print_green 'Creating database for the rmm'
print_green 'Creating database for trmm'

sudo -u postgres psql -c "CREATE DATABASE tacticalrmm"
sudo -u postgres psql -c "CREATE USER ${pgusername} WITH PASSWORD '${pgpw}'"
sudo -u postgres psql -c "ALTER ROLE ${pgusername} SET client_encoding TO 'utf8'"
sudo -u postgres psql -c "ALTER ROLE ${pgusername} SET default_transaction_isolation TO 'read committed'"
sudo -u postgres psql -c "ALTER ROLE ${pgusername} SET timezone TO 'UTC'"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE tacticalrmm TO ${pgusername}"
sudo -u postgres psql -c "ALTER DATABASE tacticalrmm OWNER TO ${pgusername}"
sudo -u postgres psql -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${pgusername}"

print_green 'Creating database for meshcentral'

sudo -u postgres psql -c "CREATE DATABASE meshcentral"
sudo -u postgres psql -c "CREATE USER ${MESHPGUSER} WITH PASSWORD '${MESHPGPWD}'"
sudo -u postgres psql -c "ALTER ROLE ${MESHPGUSER} SET client_encoding TO 'utf8'"
sudo -u postgres psql -c "ALTER ROLE ${MESHPGUSER} SET default_transaction_isolation TO 'read committed'"
sudo -u postgres psql -c "ALTER ROLE ${MESHPGUSER} SET timezone TO 'UTC'"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE meshcentral TO ${MESHPGUSER}"
sudo -u postgres psql -c "ALTER DATABASE meshcentral OWNER TO ${MESHPGUSER}"
sudo -u postgres psql -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${MESHPGUSER}"

print_green 'Cloning repos'

Expand All @@ -308,11 +308,17 @@ git checkout main

print_green 'Downloading NATS'

if [ "$arch" = "x86_64" ]; then
natsarch='amd64'
else
natsarch='arm64'
fi

NATS_SERVER_VER=$(grep "^NATS_SERVER_VER" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}')
nats_tmp=$(mktemp -d -t nats-XXXXXXXXXX)
wget https://github.com/nats-io/nats-server/releases/download/v${NATS_SERVER_VER}/nats-server-v${NATS_SERVER_VER}-linux-amd64.tar.gz -P ${nats_tmp}
tar -xzf ${nats_tmp}/nats-server-v${NATS_SERVER_VER}-linux-amd64.tar.gz -C ${nats_tmp}
sudo mv ${nats_tmp}/nats-server-v${NATS_SERVER_VER}-linux-amd64/nats-server /usr/local/bin/
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 mv ${nats_tmp}/nats-server-v${NATS_SERVER_VER}-linux-${natsarch}/nats-server /usr/local/bin/
sudo chmod +x /usr/local/bin/nats-server
sudo chown ${USER}:${USER} /usr/local/bin/nats-server
rm -rf ${nats_tmp}
Expand All @@ -332,24 +338,27 @@ meshcfg="$(
{
"settings": {
"cert": "${meshdomain}",
"mongoDb": "mongodb://127.0.0.1:27017",
"mongoDbName": "meshcentral",
"WANonly": true,
"minify": 1,
"port": 4430,
"aliasPort": 443,
"redirPort": 800,
"allowLoginToken": true,
"allowFraming": true,
"_agentPing": 60,
"agentPong": 300,
"agentPing": 35,
"allowHighQualityDesktop": true,
"tlsOffload": "127.0.0.1",
"agentCoreDump": false,
"compression": true,
"wsCompression": true,
"agentWsCompression": true,
"maxInvalidLogin": { "time": 5, "count": 5, "coolofftime": 30 }
"maxInvalidLogin": { "time": 5, "count": 5, "coolofftime": 30 },
"postgres": {
"user": "${MESHPGUSER}",
"password": "${MESHPGPWD}",
"port": "5432",
"host": "localhost"
}
},
"domains": {
"": {
Expand Down Expand Up @@ -400,7 +409,13 @@ EOF
)"
echo "${localvars}" >/rmm/api/tacticalrmm/tacticalrmm/local_settings.py

sudo cp /rmm/natsapi/bin/nats-api /usr/local/bin
if [ "$arch" = "x86_64" ]; then
natsapi='nats-api'
else
natsapi='nats-api-arm64'
fi

sudo cp /rmm/natsapi/bin/${natsapi} /usr/local/bin/nats-api
sudo chown ${USER}:${USER} /usr/local/bin/nats-api
sudo chmod +x /usr/local/bin/nats-api

Expand Down Expand Up @@ -495,7 +510,7 @@ 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
Group=${USER}
Restart=always
RestartSec=5s
LimitNOFILE=1000000
Expand Down Expand Up @@ -567,6 +582,7 @@ server {
location /static/ {
root /rmm/api/tacticalrmm;
add_header "Access-Control-Allow-Origin" "https://${frontenddomain}";
}
location /private/ {
Expand All @@ -575,6 +591,12 @@ server {
alias /rmm/api/tacticalrmm/tacticalrmm/private/;
}
location /assets/ {
internal;
add_header "Access-Control-Allow-Origin" "https://${frontenddomain}";
alias /opt/tactical/reporting/assets/;
}
location ~ ^/ws/ {
proxy_pass http://unix:/rmm/daphne.sock;
Expand Down Expand Up @@ -736,7 +758,7 @@ meshservice="$(
cat <<EOF
[Unit]
Description=MeshCentral Server
After=network.target mongod.service nginx.service
After=network.target postgresql.service nginx.service
[Service]
Type=simple
LimitNOFILE=1000000
Expand Down Expand Up @@ -840,7 +862,7 @@ sleep 3
while ! [[ $CHECK_MESH_READY ]]; do
CHECK_MESH_READY=$(sudo journalctl -u meshcentral.service -b --no-pager | grep "MeshCentral HTTP server running on port")
echo -ne "${GREEN}Mesh Central not ready yet...${NC}\n"
sleep 3
sleep 5
done

print_green 'Generating meshcentral login token key'
Expand Down Expand Up @@ -870,7 +892,7 @@ sleep 5
while ! [[ $CHECK_MESH_READY2 ]]; do
CHECK_MESH_READY2=$(sudo journalctl -u meshcentral.service -b --no-pager | grep "MeshCentral HTTP server running on port")
echo -ne "${GREEN}Mesh Central not ready yet...${NC}\n"
sleep 3
sleep 5
done

node node_modules/meshcentral/meshctrl.js --url wss://${meshdomain}:443 --loginuser ${meshusername} --loginpass ${MESHPASSWD} AddDeviceGroup --name TacticalRMM
Expand Down
Loading

0 comments on commit af694f1

Please sign in to comment.