2019-10-22 22:22:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-06-07 02:54:52 +00:00
|
|
|
SCRIPT_VERSION="50"
|
2020-11-26 03:42:27 +00:00
|
|
|
SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/install.sh'
|
2020-08-24 20:10:40 +00:00
|
|
|
|
2021-01-30 21:31:01 +00:00
|
|
|
sudo apt install -y curl wget dirmngr gnupg lsb-release
|
2020-12-30 19:04:14 +00:00
|
|
|
|
2020-10-03 01:00:19 +00:00
|
|
|
GREEN='\033[0;32m'
|
|
|
|
YELLOW='\033[1;33m'
|
|
|
|
BLUE='\033[0;34m'
|
2020-10-05 02:51:48 +00:00
|
|
|
RED='\033[0;31m'
|
2020-10-03 01:00:19 +00:00
|
|
|
NC='\033[0m'
|
|
|
|
|
2020-08-24 20:10:40 +00:00
|
|
|
TMP_FILE=$(mktemp -p "" "rmminstall_XXXXXXXXXX")
|
|
|
|
curl -s -L "${SCRIPT_URL}" > ${TMP_FILE}
|
|
|
|
NEW_VER=$(grep "^SCRIPT_VERSION" "$TMP_FILE" | awk -F'[="]' '{print $3}')
|
|
|
|
|
2020-09-28 05:19:40 +00:00
|
|
|
if [ "${SCRIPT_VERSION}" -ne "${NEW_VER}" ]; then
|
2020-11-21 02:47:23 +00:00
|
|
|
printf >&2 "${YELLOW}Old install script detected, downloading and replacing with the latest version...${NC}\n"
|
|
|
|
wget -q "${SCRIPT_URL}" -O install.sh
|
|
|
|
printf >&2 "${YELLOW}Script updated! Please re-run ./install.sh${NC}\n"
|
2020-08-24 20:10:40 +00:00
|
|
|
rm -f $TMP_FILE
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f $TMP_FILE
|
|
|
|
|
2020-12-17 22:28:01 +00:00
|
|
|
osname=$(lsb_release -si); osname=${osname^}
|
|
|
|
osname=$(echo "$osname" | tr '[A-Z]' '[a-z]')
|
|
|
|
fullrel=$(lsb_release -sd)
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
# determine system
|
2020-12-19 07:45:21 +00:00
|
|
|
if ([ "$osname" = "ubuntu" ] && [ "$fullrelno" = "20.04" ]) || ([ "$osname" = "debian" ] && [ $relno -ge 10 ]); then
|
2020-12-17 22:28:01 +00:00
|
|
|
echo $fullrel
|
|
|
|
else
|
|
|
|
echo $fullrel
|
2020-12-19 07:45:21 +00:00
|
|
|
echo -ne "${RED}Only Ubuntu release 20.04 and Debian 10 and later, are supported\n"
|
|
|
|
echo -ne "Your system does not appear to be supported${NC}\n"
|
|
|
|
exit 1
|
2020-08-15 04:25:42 +00:00
|
|
|
fi
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
if [ $EUID -eq 0 ]; then
|
2020-12-19 07:45:21 +00:00
|
|
|
echo -ne "${RED}Do NOT run this script as root. Exiting.${NC}\n"
|
2019-10-22 22:22:36 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-10-20 01:01:45 +00:00
|
|
|
if [[ "$LANG" != *".UTF-8" ]]; then
|
|
|
|
printf >&2 "\n${RED}System locale must be ${GREEN}<some language>.UTF-8${RED} not ${YELLOW}${LANG}${NC}\n"
|
|
|
|
printf >&2 "${RED}Run the following command and change the default locale to your language of choice${NC}\n\n"
|
2020-10-05 02:51:48 +00:00
|
|
|
printf >&2 "${GREEN}sudo dpkg-reconfigure locales${NC}\n\n"
|
|
|
|
printf >&2 "${RED}You will need to log out and back in for changes to take effect, then re-run this script.${NC}\n\n"
|
2020-10-05 02:54:25 +00:00
|
|
|
exit 1
|
2020-10-05 02:51:48 +00:00
|
|
|
fi
|
|
|
|
|
2020-12-17 22:28:01 +00:00
|
|
|
if ([ "$osname" = "ubuntu" ]); then
|
|
|
|
mongodb_repo="deb [arch=amd64] https://repo.mongodb.org/apt/$osname $codename/mongodb-org/4.4 multiverse"
|
|
|
|
else
|
|
|
|
mongodb_repo="deb [arch=amd64] https://repo.mongodb.org/apt/$osname $codename/mongodb-org/4.4 main"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
postgresql_repo="deb [arch=amd64] https://apt.postgresql.org/pub/repos/apt/ $codename-pgdg main"
|
|
|
|
|
|
|
|
|
2020-09-28 05:19:40 +00:00
|
|
|
# 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
|
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
DJANGO_SEKRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 80 | head -n 1)
|
|
|
|
ADMINURL=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 70 | head -n 1)
|
|
|
|
MESHPASSWD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 25 | head -n 1)
|
2020-08-21 19:46:05 +00:00
|
|
|
pgusername=$(cat /dev/urandom | tr -dc 'a-z' | fold -w 8 | head -n 1)
|
2020-08-21 19:19:29 +00:00
|
|
|
pgpw=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1)
|
2021-01-22 00:40:09 +00:00
|
|
|
meshusername=$(cat /dev/urandom | tr -dc 'a-z' | fold -w 8 | head -n 1)
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
cls() {
|
|
|
|
printf "\033c"
|
|
|
|
}
|
|
|
|
|
|
|
|
print_green() {
|
|
|
|
printf >&2 "${GREEN}%0.s-${NC}" {1..80}
|
|
|
|
printf >&2 "\n"
|
|
|
|
printf >&2 "${GREEN}${1}${NC}\n"
|
|
|
|
printf >&2 "${GREEN}%0.s-${NC}" {1..80}
|
|
|
|
printf >&2 "\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
cls
|
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
while [[ $rmmdomain != *[.]*[.]* ]]
|
|
|
|
do
|
|
|
|
echo -ne "${YELLOW}Enter the subdomain for the backend (e.g. api.example.com)${NC}: "
|
2019-10-22 22:22:36 +00:00
|
|
|
read rmmdomain
|
2020-06-24 17:28:04 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
while [[ $frontenddomain != *[.]*[.]* ]]
|
|
|
|
do
|
2020-08-12 10:52:42 +00:00
|
|
|
echo -ne "${YELLOW}Enter the subdomain for the frontend (e.g. rmm.example.com)${NC}: "
|
2019-10-22 22:22:36 +00:00
|
|
|
read frontenddomain
|
2020-06-24 17:28:04 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
while [[ $meshdomain != *[.]*[.]* ]]
|
|
|
|
do
|
|
|
|
echo -ne "${YELLOW}Enter the subdomain for meshcentral (e.g. mesh.example.com)${NC}: "
|
2019-10-22 22:22:36 +00:00
|
|
|
read meshdomain
|
2020-06-24 17:28:04 +00:00
|
|
|
done
|
|
|
|
|
2020-10-18 20:08:51 +00:00
|
|
|
echo -ne "${YELLOW}Enter the root domain (e.g. example.com or example.co.uk)${NC}: "
|
2020-08-13 02:35:14 +00:00
|
|
|
read rootdomain
|
|
|
|
|
2020-10-18 20:08:51 +00:00
|
|
|
while [[ $letsemail != *[@]*[.]* ]]
|
|
|
|
do
|
|
|
|
echo -ne "${YELLOW}Enter a valid email address for django and meshcentral${NC}: "
|
|
|
|
read letsemail
|
|
|
|
done
|
|
|
|
|
2020-12-17 22:28:01 +00:00
|
|
|
# if server is behind NAT we need to add the 3 subdomains to the host file
|
2020-08-15 04:25:42 +00:00
|
|
|
# so that nginx can properly route between the frontend, backend and meshcentral
|
2020-08-30 02:41:44 +00:00
|
|
|
# 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")
|
2020-10-03 01:00:19 +00:00
|
|
|
HAS_11=$(grep 127.0.1.1 /etc/hosts)
|
2020-08-30 02:41:44 +00:00
|
|
|
|
|
|
|
if ! [[ $CHECK_HOSTS ]]; then
|
2021-04-04 01:13:27 +00:00
|
|
|
print_green 'Adding subdomains to hosts file'
|
|
|
|
if [[ $HAS_11 ]]; then
|
|
|
|
sudo sed -i "/127.0.1.1/s/$/ ${rmmdomain} ${frontenddomain} ${meshdomain}/" /etc/hosts
|
|
|
|
else
|
|
|
|
echo "127.0.1.1 ${rmmdomain} ${frontenddomain} ${meshdomain}" | sudo tee --append /etc/hosts > /dev/null
|
|
|
|
fi
|
2020-08-15 04:25:42 +00:00
|
|
|
fi
|
|
|
|
|
2020-08-30 02:41:44 +00:00
|
|
|
BEHIND_NAT=false
|
|
|
|
IPV4=$(ip -4 addr | sed -ne 's|^.* inet \([^/]*\)/.* scope global.*$|\1|p' | head -1)
|
|
|
|
if echo "$IPV4" | grep -qE '^(10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.|192\.168)'; then
|
2020-12-17 22:28:01 +00:00
|
|
|
BEHIND_NAT=true
|
2020-08-30 02:41:44 +00:00
|
|
|
fi
|
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
sudo apt install -y software-properties-common
|
|
|
|
sudo apt update
|
2020-10-17 23:48:58 +00:00
|
|
|
sudo apt install -y certbot openssl
|
2020-06-24 17:28:04 +00:00
|
|
|
|
2020-11-26 03:42:27 +00:00
|
|
|
print_green 'Getting wildcard cert'
|
2020-10-17 23:48:58 +00:00
|
|
|
|
2020-12-17 22:32:40 +00:00
|
|
|
sudo certbot certonly --manual -d *.${rootdomain} --agree-tos --no-bootstrap --manual-public-ip-logging-ok --preferred-challenges dns -m ${letsemail} --no-eff-email
|
2020-11-26 03:42:27 +00:00
|
|
|
while [[ $? -ne 0 ]]
|
|
|
|
do
|
2020-12-17 22:32:40 +00:00
|
|
|
sudo certbot certonly --manual -d *.${rootdomain} --agree-tos --no-bootstrap --manual-public-ip-logging-ok --preferred-challenges dns -m ${letsemail} --no-eff-email
|
2020-11-26 03:42:27 +00:00
|
|
|
done
|
2020-10-17 23:48:58 +00:00
|
|
|
|
2020-11-26 03:42:27 +00:00
|
|
|
CERT_PRIV_KEY=/etc/letsencrypt/live/${rootdomain}/privkey.pem
|
|
|
|
CERT_PUB_KEY=/etc/letsencrypt/live/${rootdomain}/fullchain.pem
|
2020-10-17 23:48:58 +00:00
|
|
|
|
2020-11-26 03:42:27 +00:00
|
|
|
sudo chown ${USER}:${USER} -R /etc/letsencrypt
|
|
|
|
sudo chmod 775 -R /etc/letsencrypt
|
2020-10-17 23:48:58 +00:00
|
|
|
|
2020-11-26 03:42:27 +00:00
|
|
|
print_green 'Downloading NATS'
|
|
|
|
|
|
|
|
nats_tmp=$(mktemp -d -t nats-XXXXXXXXXX)
|
2021-05-29 02:53:16 +00:00
|
|
|
wget https://github.com/nats-io/nats-server/releases/download/v2.2.6/nats-server-v2.2.6-linux-amd64.tar.gz -P ${nats_tmp}
|
2020-11-26 03:42:27 +00:00
|
|
|
|
2021-05-29 02:53:16 +00:00
|
|
|
tar -xzf ${nats_tmp}/nats-server-v2.2.6-linux-amd64.tar.gz -C ${nats_tmp}
|
2020-11-26 03:42:27 +00:00
|
|
|
|
2021-05-29 02:53:16 +00:00
|
|
|
sudo mv ${nats_tmp}/nats-server-v2.2.6-linux-amd64/nats-server /usr/local/bin/
|
2020-11-26 03:42:27 +00:00
|
|
|
sudo chmod +x /usr/local/bin/nats-server
|
|
|
|
sudo chown ${USER}:${USER} /usr/local/bin/nats-server
|
|
|
|
rm -rf ${nats_tmp}
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
print_green 'Installing Nginx'
|
|
|
|
|
|
|
|
sudo apt install -y nginx
|
2020-06-23 01:34:48 +00:00
|
|
|
sudo systemctl stop nginx
|
2021-01-17 01:16:28 +00:00
|
|
|
sudo sed -i 's/worker_connections.*/worker_connections 2048;/g' /etc/nginx/nginx.conf
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
print_green 'Installing NodeJS'
|
|
|
|
|
2021-03-26 06:32:24 +00:00
|
|
|
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
|
2019-10-22 22:22:36 +00:00
|
|
|
sudo apt update
|
|
|
|
sudo apt install -y gcc g++ make
|
|
|
|
sudo apt install -y nodejs
|
2021-03-16 23:09:38 +00:00
|
|
|
sudo npm install -g npm
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
print_green 'Installing MongoDB'
|
|
|
|
|
2020-12-17 22:28:01 +00:00
|
|
|
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
|
2019-10-22 22:22:36 +00:00
|
|
|
sudo apt update
|
|
|
|
sudo apt install -y mongodb-org
|
|
|
|
sudo systemctl enable mongod
|
|
|
|
sudo systemctl restart mongod
|
|
|
|
|
2021-02-21 07:37:19 +00:00
|
|
|
print_green 'Installing Python 3.9'
|
2020-12-02 10:40:20 +00:00
|
|
|
|
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 ~
|
|
|
|
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
|
2020-12-02 10:40:20 +00:00
|
|
|
|
|
|
|
|
2021-02-21 07:37:19 +00:00
|
|
|
print_green 'Installing redis and git'
|
|
|
|
sudo apt install -y ca-certificates redis git
|
2020-12-02 10:40:20 +00:00
|
|
|
|
2021-06-07 02:54:52 +00:00
|
|
|
# apply redis configuration
|
|
|
|
sudo redis-cli config set appendonly yes
|
|
|
|
sudo redis-cli config rewrite
|
|
|
|
|
2020-12-02 10:40:20 +00:00
|
|
|
print_green 'Installing postgresql'
|
|
|
|
|
2020-12-17 22:28:01 +00:00
|
|
|
echo "$postgresql_repo" | sudo tee /etc/apt/sources.list.d/pgdg.list
|
|
|
|
|
2020-12-02 10:40:20 +00:00
|
|
|
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
|
|
|
sudo apt update
|
|
|
|
sudo apt install -y postgresql-13
|
2021-03-16 23:09:38 +00:00
|
|
|
sleep 2
|
|
|
|
sudo systemctl enable postgresql
|
|
|
|
sudo systemctl restart postgresql
|
|
|
|
sleep 5
|
2020-12-02 10:40:20 +00:00
|
|
|
|
|
|
|
print_green 'Creating database for the rmm'
|
|
|
|
|
|
|
|
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 mkdir /rmm
|
|
|
|
sudo chown ${USER}:${USER} /rmm
|
|
|
|
sudo mkdir -p /var/log/celery
|
|
|
|
sudo chown ${USER}:${USER} /var/log/celery
|
|
|
|
git clone https://github.com/wh1te909/tacticalrmm.git /rmm/
|
|
|
|
cd /rmm
|
|
|
|
git config user.email "admin@example.com"
|
|
|
|
git config user.name "Bob"
|
|
|
|
git checkout master
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
print_green 'Installing MeshCentral'
|
|
|
|
|
2020-12-02 10:40:20 +00:00
|
|
|
MESH_VER=$(grep "^MESH_VER" /rmm/api/tacticalrmm/tacticalrmm/settings.py | awk -F'[= "]' '{print $5}')
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
sudo mkdir -p /meshcentral/meshcentral-data
|
2020-02-01 21:58:23 +00:00
|
|
|
sudo chown ${USER}:${USER} -R /meshcentral
|
2019-10-22 22:22:36 +00:00
|
|
|
cd /meshcentral
|
2020-12-02 10:40:20 +00:00
|
|
|
npm install meshcentral@${MESH_VER}
|
2019-10-22 22:22:36 +00:00
|
|
|
sudo chown ${USER}:${USER} -R /meshcentral
|
|
|
|
|
|
|
|
meshcfg="$(cat << EOF
|
|
|
|
{
|
|
|
|
"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,
|
|
|
|
"AllowHighQualityDesktop": true,
|
|
|
|
"TlsOffload": "127.0.0.1",
|
2021-01-17 01:16:28 +00:00
|
|
|
"agentCoreDump": false,
|
|
|
|
"Compression": true,
|
|
|
|
"WsCompression": true,
|
|
|
|
"AgentWsCompression": true,
|
2019-12-14 21:41:37 +00:00
|
|
|
"MaxInvalidLogin": { "time": 5, "count": 5, "coolofftime": 30 }
|
2019-10-22 22:22:36 +00:00
|
|
|
},
|
|
|
|
"domains": {
|
|
|
|
"": {
|
2020-06-24 17:28:04 +00:00
|
|
|
"Title": "Tactical RMM",
|
|
|
|
"Title2": "Tactical RMM",
|
2019-10-22 22:22:36 +00:00
|
|
|
"NewAccounts": false,
|
|
|
|
"CertUrl": "https://${meshdomain}:443/",
|
|
|
|
"GeoLocation": true,
|
2020-06-23 01:34:48 +00:00
|
|
|
"CookieIpCheck": false,
|
2021-01-10 00:15:11 +00:00
|
|
|
"mstsc": true
|
2019-10-22 22:22:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${meshcfg}" > /meshcentral/meshcentral-data/config.json
|
|
|
|
|
|
|
|
localvars="$(cat << EOF
|
|
|
|
SECRET_KEY = "${DJANGO_SEKRET}"
|
|
|
|
|
|
|
|
DEBUG = False
|
|
|
|
|
|
|
|
ALLOWED_HOSTS = ['${rmmdomain}']
|
|
|
|
|
2020-01-18 02:05:29 +00:00
|
|
|
ADMIN_URL = "${ADMINURL}/"
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
CORS_ORIGIN_WHITELIST = [
|
|
|
|
"https://${frontenddomain}"
|
|
|
|
]
|
|
|
|
|
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.postgresql',
|
2019-12-14 10:17:16 +00:00
|
|
|
'NAME': 'tacticalrmm',
|
2019-10-22 22:22:36 +00:00
|
|
|
'USER': '${pgusername}',
|
|
|
|
'PASSWORD': '${pgpw}',
|
|
|
|
'HOST': 'localhost',
|
|
|
|
'PORT': '5432',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 08:15:08 +00:00
|
|
|
REST_FRAMEWORK = {
|
|
|
|
'DATETIME_FORMAT': "%b-%d-%Y - %H:%M",
|
|
|
|
|
|
|
|
'DEFAULT_PERMISSION_CLASSES': (
|
|
|
|
'rest_framework.permissions.IsAuthenticated',
|
|
|
|
),
|
|
|
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
|
|
'knox.auth.TokenAuthentication',
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
if not DEBUG:
|
|
|
|
REST_FRAMEWORK.update({
|
|
|
|
'DEFAULT_RENDERER_CLASSES': (
|
|
|
|
'rest_framework.renderers.JSONRenderer',
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
MESH_USERNAME = "${meshusername}"
|
|
|
|
MESH_SITE = "https://${meshdomain}"
|
2020-02-12 16:23:44 +00:00
|
|
|
REDIS_HOST = "localhost"
|
2021-01-21 23:58:31 +00:00
|
|
|
KEEP_SALT = False
|
2021-03-10 22:32:36 +00:00
|
|
|
ADMIN_ENABLED = True
|
2019-10-22 22:22:36 +00:00
|
|
|
EOF
|
|
|
|
)"
|
2020-06-24 17:28:04 +00:00
|
|
|
echo "${localvars}" > /rmm/api/tacticalrmm/tacticalrmm/local_settings.py
|
2019-10-22 22:22:36 +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-01-19 23:50:31 +00:00
|
|
|
print_green 'Installing the backend'
|
|
|
|
|
2021-05-05 01:41:39 +00:00
|
|
|
SETUPTOOLS_VER=$(grep "^SETUPTOOLS_VER" /rmm/api/tacticalrmm/tacticalrmm/settings.py | awk -F'[= "]' '{print $5}')
|
|
|
|
WHEEL_VER=$(grep "^WHEEL_VER" /rmm/api/tacticalrmm/tacticalrmm/settings.py | awk -F'[= "]' '{print $5}')
|
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
cd /rmm/api
|
2021-02-21 07:37:19 +00:00
|
|
|
python3.9 -m venv env
|
2020-06-24 17:28:04 +00:00
|
|
|
source /rmm/api/env/bin/activate
|
|
|
|
cd /rmm/api/tacticalrmm
|
2020-05-11 20:32:37 +00:00
|
|
|
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-06-24 17:28:04 +00:00
|
|
|
pip install --no-cache-dir -r /rmm/api/tacticalrmm/requirements.txt
|
2020-01-19 23:50:31 +00:00
|
|
|
python manage.py migrate
|
2020-08-10 20:29:42 +00:00
|
|
|
python manage.py collectstatic --no-input
|
2020-02-22 23:14:31 +00:00
|
|
|
python manage.py load_chocos
|
2020-08-27 04:13:51 +00:00
|
|
|
python manage.py load_community_scripts
|
2020-01-19 23:50:31 +00:00
|
|
|
printf >&2 "${YELLOW}%0.s*${NC}" {1..80}
|
|
|
|
printf >&2 "\n"
|
|
|
|
printf >&2 "${YELLOW}Please create your login for the RMM website and django admin${NC}\n"
|
|
|
|
printf >&2 "${YELLOW}%0.s*${NC}" {1..80}
|
|
|
|
printf >&2 "\n"
|
|
|
|
echo -ne "Username: "
|
|
|
|
read djangousername
|
|
|
|
python manage.py createsuperuser --username ${djangousername} --email ${letsemail}
|
|
|
|
RANDBASE=$(python manage.py generate_totp)
|
|
|
|
cls
|
2020-05-02 23:27:24 +00:00
|
|
|
python manage.py generate_barcode ${RANDBASE} ${djangousername} ${frontenddomain}
|
2020-01-19 23:50:31 +00:00
|
|
|
deactivate
|
|
|
|
read -n 1 -s -r -p "Press any key to continue..."
|
|
|
|
|
2021-02-27 05:28:42 +00:00
|
|
|
uwsgiprocs=4
|
|
|
|
if [[ "$numprocs" == "1" ]]; then
|
|
|
|
uwsgiprocs=2
|
|
|
|
else
|
|
|
|
uwsgiprocs=$numprocs
|
|
|
|
fi
|
2020-01-19 23:50:31 +00:00
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
uwsgini="$(cat << EOF
|
|
|
|
[uwsgi]
|
2020-06-24 17:28:04 +00:00
|
|
|
chdir = /rmm/api/tacticalrmm
|
2019-12-14 10:17:16 +00:00
|
|
|
module = tacticalrmm.wsgi
|
2020-06-24 17:28:04 +00:00
|
|
|
home = /rmm/api/env
|
2019-10-22 22:22:36 +00:00
|
|
|
master = true
|
2021-02-27 05:28:42 +00:00
|
|
|
processes = ${uwsgiprocs}
|
|
|
|
threads = ${uwsgiprocs}
|
2021-02-06 00:39:22 +00:00
|
|
|
enable-threads = true
|
2020-06-24 17:28:04 +00:00
|
|
|
socket = /rmm/api/tacticalrmm/tacticalrmm.sock
|
2019-10-22 22:22:36 +00:00
|
|
|
harakiri = 300
|
|
|
|
chmod-socket = 660
|
2021-02-06 00:39:22 +00:00
|
|
|
buffer-size = 65535
|
2019-10-22 22:22:36 +00:00
|
|
|
vacuum = true
|
|
|
|
die-on-term = true
|
2020-03-01 12:31:04 +00:00
|
|
|
max-requests = 500
|
2019-10-22 22:22:36 +00:00
|
|
|
EOF
|
|
|
|
)"
|
2020-06-24 17:28:04 +00:00
|
|
|
echo "${uwsgini}" > /rmm/api/tacticalrmm/app.ini
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
rmmservice="$(cat << EOF
|
|
|
|
[Unit]
|
2019-12-14 10:17:16 +00:00
|
|
|
Description=tacticalrmm uwsgi daemon
|
2020-11-19 07:18:48 +00:00
|
|
|
After=network.target postgresql.service
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
[Service]
|
|
|
|
User=${USER}
|
|
|
|
Group=www-data
|
2020-06-24 17:28:04 +00:00
|
|
|
WorkingDirectory=/rmm/api/tacticalrmm
|
|
|
|
Environment="PATH=/rmm/api/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
ExecStart=/rmm/api/env/bin/uwsgi --ini app.ini
|
2020-03-28 05:17:01 +00:00
|
|
|
Restart=always
|
|
|
|
RestartSec=10s
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${rmmservice}" | sudo tee /etc/systemd/system/rmm.service > /dev/null
|
|
|
|
|
2021-04-03 00:24:31 +00:00
|
|
|
daphneservice="$(cat << EOF
|
|
|
|
[Unit]
|
|
|
|
Description=django channels daemon
|
|
|
|
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"
|
|
|
|
ExecStart=/rmm/api/env/bin/daphne -u /rmm/daphne.sock tacticalrmm.asgi:application
|
|
|
|
Restart=always
|
|
|
|
RestartSec=3s
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${daphneservice}" | sudo tee /etc/systemd/system/daphne.service > /dev/null
|
|
|
|
|
2020-11-26 03:42:27 +00:00
|
|
|
natsservice="$(cat << EOF
|
|
|
|
[Unit]
|
|
|
|
Description=NATS Server
|
|
|
|
After=network.target ntp.service
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${natsservice}" | sudo tee /etc/systemd/system/nats.service > /dev/null
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
nginxrmm="$(cat << EOF
|
|
|
|
server_tokens off;
|
|
|
|
|
2019-12-14 10:17:16 +00:00
|
|
|
upstream tacticalrmm {
|
2020-06-24 17:28:04 +00:00
|
|
|
server unix:////rmm/api/tacticalrmm/tacticalrmm.sock;
|
2019-10-22 22:22:36 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 03:07:59 +00:00
|
|
|
map \$http_user_agent \$ignore_ua {
|
2020-11-21 02:47:23 +00:00
|
|
|
"~python-requests.*" 0;
|
|
|
|
"~go-resty.*" 0;
|
|
|
|
default 1;
|
|
|
|
}
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
server {
|
|
|
|
listen 80;
|
2021-06-08 09:43:55 +00:00
|
|
|
listen [::]:80;
|
2019-10-22 22:22:36 +00:00
|
|
|
server_name ${rmmdomain};
|
|
|
|
return 301 https://\$server_name\$request_uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 443 ssl;
|
2021-06-08 09:43:55 +00:00
|
|
|
listen [::]:443 ssl;
|
2019-10-22 22:22:36 +00:00
|
|
|
server_name ${rmmdomain};
|
2019-10-23 00:56:07 +00:00
|
|
|
client_max_body_size 300M;
|
2020-12-22 05:14:44 +00:00
|
|
|
access_log /rmm/api/tacticalrmm/tacticalrmm/private/log/access.log combined if=\$ignore_ua;
|
2020-06-24 17:28:04 +00:00
|
|
|
error_log /rmm/api/tacticalrmm/tacticalrmm/private/log/error.log;
|
2020-10-17 23:48:58 +00:00
|
|
|
ssl_certificate ${CERT_PUB_KEY};
|
|
|
|
ssl_certificate_key ${CERT_PRIV_KEY};
|
2020-06-24 17:28:04 +00:00
|
|
|
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
location /static/ {
|
2020-06-24 17:28:04 +00:00
|
|
|
root /rmm/api/tacticalrmm;
|
2019-10-22 22:22:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-01 08:16:00 +00:00
|
|
|
location /private/ {
|
2019-10-22 22:22:36 +00:00
|
|
|
internal;
|
|
|
|
add_header "Access-Control-Allow-Origin" "https://${frontenddomain}";
|
2020-06-24 17:28:04 +00:00
|
|
|
alias /rmm/api/tacticalrmm/tacticalrmm/private/;
|
2019-10-22 22:22:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 03:02:03 +00:00
|
|
|
location ~ ^/(natsapi) {
|
|
|
|
allow 127.0.0.1;
|
|
|
|
deny all;
|
|
|
|
uwsgi_pass tacticalrmm;
|
|
|
|
include /etc/nginx/uwsgi_params;
|
2021-01-17 01:16:28 +00:00
|
|
|
uwsgi_read_timeout 500s;
|
2021-01-12 03:02:03 +00:00
|
|
|
uwsgi_ignore_client_abort on;
|
|
|
|
}
|
2019-10-22 22:22:36 +00:00
|
|
|
|
2021-04-03 00:24:31 +00:00
|
|
|
location ~ ^/ws/ {
|
|
|
|
proxy_pass http://unix:/rmm/daphne.sock;
|
|
|
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_set_header Upgrade \$http_upgrade;
|
2021-04-03 00:50:28 +00:00
|
|
|
proxy_set_header Connection "upgrade";
|
2021-04-03 00:24:31 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
location / {
|
2019-12-14 10:17:16 +00:00
|
|
|
uwsgi_pass tacticalrmm;
|
2019-10-22 22:22:36 +00:00
|
|
|
include /etc/nginx/uwsgi_params;
|
|
|
|
uwsgi_read_timeout 9999s;
|
|
|
|
uwsgi_ignore_client_abort on;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${nginxrmm}" | sudo tee /etc/nginx/sites-available/rmm.conf > /dev/null
|
|
|
|
|
|
|
|
|
|
|
|
nginxmesh="$(cat << EOF
|
|
|
|
server {
|
|
|
|
listen 80;
|
2021-06-08 09:43:55 +00:00
|
|
|
listen [::]:80;
|
2019-10-22 22:22:36 +00:00
|
|
|
server_name ${meshdomain};
|
2020-12-02 10:40:20 +00:00
|
|
|
return 301 https://\$server_name\$request_uri;
|
2019-10-22 22:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
|
|
|
|
listen 443 ssl;
|
2021-06-08 09:43:55 +00:00
|
|
|
listen [::]:443 ssl;
|
2019-10-22 22:22:36 +00:00
|
|
|
proxy_send_timeout 330s;
|
|
|
|
proxy_read_timeout 330s;
|
|
|
|
server_name ${meshdomain};
|
2020-10-17 23:48:58 +00:00
|
|
|
ssl_certificate ${CERT_PUB_KEY};
|
|
|
|
ssl_certificate_key ${CERT_PRIV_KEY};
|
2019-10-22 22:22:36 +00:00
|
|
|
ssl_session_cache shared:WEBSSL:10m;
|
|
|
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
|
|
|
ssl_prefer_server_ciphers on;
|
|
|
|
|
|
|
|
location / {
|
|
|
|
proxy_pass http://127.0.0.1:4430/;
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
2020-12-02 10:40:20 +00:00
|
|
|
proxy_set_header Host \$host;
|
2019-10-22 22:22:36 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${nginxmesh}" | sudo tee /etc/nginx/sites-available/meshcentral.conf > /dev/null
|
|
|
|
|
|
|
|
sudo ln -s /etc/nginx/sites-available/rmm.conf /etc/nginx/sites-enabled/rmm.conf
|
|
|
|
sudo ln -s /etc/nginx/sites-available/meshcentral.conf /etc/nginx/sites-enabled/meshcentral.conf
|
|
|
|
|
|
|
|
sudo mkdir /etc/conf.d
|
|
|
|
|
|
|
|
celeryservice="$(cat << EOF
|
|
|
|
[Unit]
|
2021-01-17 01:16:28 +00:00
|
|
|
Description=Celery Service V2
|
2020-11-19 07:18:48 +00:00
|
|
|
After=network.target redis-server.service postgresql.service
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=forking
|
|
|
|
User=${USER}
|
|
|
|
Group=${USER}
|
|
|
|
EnvironmentFile=/etc/conf.d/celery.conf
|
2020-06-24 17:28:04 +00:00
|
|
|
WorkingDirectory=/rmm/api/tacticalrmm
|
2021-01-17 01:16:28 +00:00
|
|
|
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'
|
2020-03-28 05:17:01 +00:00
|
|
|
Restart=always
|
|
|
|
RestartSec=10s
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${celeryservice}" | sudo tee /etc/systemd/system/celery.service > /dev/null
|
|
|
|
|
|
|
|
celeryconf="$(cat << EOF
|
|
|
|
CELERYD_NODES="w1"
|
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
CELERY_BIN="/rmm/api/env/bin/celery"
|
2019-10-22 22:22:36 +00:00
|
|
|
|
2019-12-14 10:17:16 +00:00
|
|
|
CELERY_APP="tacticalrmm"
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
CELERYD_MULTI="multi"
|
|
|
|
|
2021-01-20 22:11:54 +00:00
|
|
|
CELERYD_OPTS="--time-limit=9999 --autoscale=100,5"
|
2019-10-22 22:22:36 +00:00
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
CELERYD_PID_FILE="/rmm/api/tacticalrmm/%n.pid"
|
2019-10-22 22:22:36 +00:00
|
|
|
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
|
2020-12-22 05:14:44 +00:00
|
|
|
CELERYD_LOG_LEVEL="ERROR"
|
2019-10-22 22:22:36 +00:00
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
CELERYBEAT_PID_FILE="/rmm/api/tacticalrmm/beat.pid"
|
2019-10-22 22:22:36 +00:00
|
|
|
CELERYBEAT_LOG_FILE="/var/log/celery/beat.log"
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${celeryconf}" | sudo tee /etc/conf.d/celery.conf > /dev/null
|
|
|
|
|
2020-09-08 02:57:05 +00:00
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
celerybeatservice="$(cat << EOF
|
|
|
|
[Unit]
|
2021-01-17 01:16:28 +00:00
|
|
|
Description=Celery Beat Service V2
|
2020-11-19 07:18:48 +00:00
|
|
|
After=network.target redis-server.service postgresql.service
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
User=${USER}
|
|
|
|
Group=${USER}
|
|
|
|
EnvironmentFile=/etc/conf.d/celery.conf
|
2020-06-24 17:28:04 +00:00
|
|
|
WorkingDirectory=/rmm/api/tacticalrmm
|
2021-01-17 01:16:28 +00:00
|
|
|
ExecStart=/bin/sh -c '\${CELERY_BIN} -A \${CELERY_APP} beat --pidfile=\${CELERYBEAT_PID_FILE} --logfile=\${CELERYBEAT_LOG_FILE} --loglevel=\${CELERYD_LOG_LEVEL}'
|
2020-03-28 05:17:01 +00:00
|
|
|
Restart=always
|
|
|
|
RestartSec=10s
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${celerybeatservice}" | sudo tee /etc/systemd/system/celerybeat.service > /dev/null
|
|
|
|
|
2020-09-08 02:57:05 +00:00
|
|
|
sudo chown ${USER}:${USER} -R /etc/conf.d/
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
meshservice="$(cat << EOF
|
|
|
|
[Unit]
|
|
|
|
Description=MeshCentral Server
|
2021-01-20 22:11:54 +00:00
|
|
|
After=network.target mongod.service nginx.service
|
2019-10-22 22:22:36 +00:00
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
LimitNOFILE=1000000
|
2020-02-01 21:58:23 +00:00
|
|
|
ExecStart=/usr/bin/node node_modules/meshcentral
|
2019-10-22 22:22:36 +00:00
|
|
|
Environment=NODE_ENV=production
|
|
|
|
WorkingDirectory=/meshcentral
|
2020-02-01 21:58:23 +00:00
|
|
|
User=${USER}
|
|
|
|
Group=${USER}
|
2019-10-22 22:22:36 +00:00
|
|
|
Restart=always
|
2020-03-28 05:17:01 +00:00
|
|
|
RestartSec=10s
|
|
|
|
|
2019-10-22 22:22:36 +00:00
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${meshservice}" | sudo tee /etc/systemd/system/meshcentral.service > /dev/null
|
|
|
|
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
|
|
|
sudo chown -R $USER:$GROUP /home/${USER}/.npm
|
|
|
|
sudo chown -R $USER:$GROUP /home/${USER}/.config
|
|
|
|
|
2020-06-06 19:20:35 +00:00
|
|
|
quasarenv="$(cat << EOF
|
|
|
|
PROD_URL = "https://${rmmdomain}"
|
2020-06-24 17:28:04 +00:00
|
|
|
DEV_URL = "https://${rmmdomain}"
|
2019-10-22 22:22:36 +00:00
|
|
|
EOF
|
|
|
|
)"
|
2020-06-24 17:28:04 +00:00
|
|
|
echo "${quasarenv}" | tee /rmm/web/.env > /dev/null
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
print_green 'Installing the frontend'
|
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
cd /rmm/web
|
2019-10-22 22:22:36 +00:00
|
|
|
npm install
|
|
|
|
npm run build
|
|
|
|
sudo mkdir -p /var/www/rmm
|
2020-06-24 17:28:04 +00:00
|
|
|
sudo cp -pvr /rmm/web/dist /var/www/rmm/
|
2019-10-22 22:22:36 +00:00
|
|
|
sudo chown www-data:www-data -R /var/www/rmm/dist
|
|
|
|
|
|
|
|
nginxfrontend="$(cat << EOF
|
|
|
|
server {
|
|
|
|
server_name ${frontenddomain};
|
|
|
|
charset utf-8;
|
|
|
|
location / {
|
|
|
|
root /var/www/rmm/dist;
|
|
|
|
try_files \$uri \$uri/ /index.html;
|
2019-12-01 08:27:41 +00:00
|
|
|
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
2019-11-17 10:12:40 +00:00
|
|
|
add_header Pragma "no-cache";
|
2019-10-22 22:22:36 +00:00
|
|
|
}
|
|
|
|
error_log /var/log/nginx/frontend-error.log;
|
|
|
|
access_log /var/log/nginx/frontend-access.log;
|
|
|
|
|
|
|
|
listen 443 ssl;
|
2021-06-08 09:43:55 +00:00
|
|
|
listen [::]:443 ssl;
|
2020-10-17 23:48:58 +00:00
|
|
|
ssl_certificate ${CERT_PUB_KEY};
|
|
|
|
ssl_certificate_key ${CERT_PRIV_KEY};
|
2020-06-24 17:28:04 +00:00
|
|
|
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
|
2019-10-22 22:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
if (\$host = ${frontenddomain}) {
|
|
|
|
return 301 https://\$host\$request_uri;
|
|
|
|
}
|
|
|
|
|
2021-06-08 09:43:55 +00:00
|
|
|
listen 80;
|
|
|
|
listen [::]:80;
|
2019-10-22 22:22:36 +00:00
|
|
|
server_name ${frontenddomain};
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
echo "${nginxfrontend}" | sudo tee /etc/nginx/sites-available/frontend.conf > /dev/null
|
|
|
|
|
|
|
|
sudo ln -s /etc/nginx/sites-available/frontend.conf /etc/nginx/sites-enabled/frontend.conf
|
|
|
|
|
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
print_green 'Enabling Services'
|
2019-10-22 22:22:36 +00:00
|
|
|
|
2021-04-03 00:24:31 +00:00
|
|
|
for i in rmm.service daphne.service celery.service celerybeat.service nginx
|
2019-10-22 22:22:36 +00:00
|
|
|
do
|
|
|
|
sudo systemctl enable ${i}
|
2021-01-17 01:16:28 +00:00
|
|
|
sudo systemctl stop ${i}
|
|
|
|
sudo systemctl start ${i}
|
2019-10-22 22:22:36 +00:00
|
|
|
done
|
|
|
|
sleep 5
|
|
|
|
sudo systemctl enable meshcentral
|
|
|
|
|
2020-08-16 00:50:17 +00:00
|
|
|
print_green 'Starting meshcentral and waiting for it to install plugins'
|
2019-10-22 22:22:36 +00:00
|
|
|
|
|
|
|
sudo systemctl restart meshcentral
|
|
|
|
|
2020-08-16 00:50:17 +00:00
|
|
|
sleep 3
|
|
|
|
|
|
|
|
# The first time we start meshcentral, it will need some time to generate certs and install plugins.
|
|
|
|
# This will take anywhere from a few seconds to a few minutes depending on the server's hardware
|
|
|
|
# We will know it's ready once the last line of the systemd service stdout is 'MeshCentral HTTP server running on port.....'
|
|
|
|
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
|
|
|
|
done
|
2019-10-22 22:22:36 +00:00
|
|
|
|
2020-04-13 00:09:01 +00:00
|
|
|
print_green 'Generating meshcentral login token key'
|
|
|
|
|
|
|
|
MESHTOKENKEY=$(node /meshcentral/node_modules/meshcentral --logintokenkey)
|
|
|
|
|
|
|
|
meshtoken="$(cat << EOF
|
|
|
|
MESH_TOKEN_KEY = "${MESHTOKENKEY}"
|
|
|
|
EOF
|
|
|
|
)"
|
2020-06-24 17:28:04 +00:00
|
|
|
echo "${meshtoken}" | tee --append /rmm/api/tacticalrmm/tacticalrmm/local_settings.py > /dev/null
|
|
|
|
|
|
|
|
|
|
|
|
print_green 'Creating meshcentral account and group'
|
|
|
|
|
|
|
|
sudo systemctl stop meshcentral
|
2020-08-16 00:50:17 +00:00
|
|
|
sleep 3
|
2020-06-24 17:28:04 +00:00
|
|
|
cd /meshcentral
|
|
|
|
|
|
|
|
node node_modules/meshcentral --createaccount ${meshusername} --pass ${MESHPASSWD} --email ${letsemail}
|
2020-08-16 00:50:17 +00:00
|
|
|
sleep 2
|
2020-06-24 17:28:04 +00:00
|
|
|
node node_modules/meshcentral --adminaccount ${meshusername}
|
|
|
|
|
|
|
|
sudo systemctl start meshcentral
|
|
|
|
sleep 5
|
|
|
|
|
2020-08-16 00:50:17 +00:00
|
|
|
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
|
|
|
|
done
|
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
node node_modules/meshcentral/meshctrl.js --url wss://${meshdomain}:443 --loginuser ${meshusername} --loginpass ${MESHPASSWD} AddDeviceGroup --name TacticalRMM
|
2020-08-16 00:50:17 +00:00
|
|
|
sleep 5
|
2020-06-24 17:28:04 +00:00
|
|
|
MESHEXE=$(node node_modules/meshcentral/meshctrl.js --url wss://${meshdomain}:443 --loginuser ${meshusername} --loginpass ${MESHPASSWD} GenerateInviteLink --group TacticalRMM --hours 8)
|
2020-04-13 00:09:01 +00:00
|
|
|
|
2020-11-26 03:42:27 +00:00
|
|
|
sudo systemctl enable nats.service
|
2020-07-02 08:02:56 +00:00
|
|
|
cd /rmm/api/tacticalrmm
|
|
|
|
source /rmm/api/env/bin/activate
|
|
|
|
python manage.py initial_db_setup
|
2020-11-26 03:42:27 +00:00
|
|
|
python manage.py reload_nats
|
2020-07-02 08:02:56 +00:00
|
|
|
deactivate
|
2020-11-26 03:42:27 +00:00
|
|
|
sudo systemctl start nats.service
|
2020-07-02 08:02:56 +00:00
|
|
|
|
2021-03-10 22:32:36 +00:00
|
|
|
## disable django admin
|
|
|
|
sed -i 's/ADMIN_ENABLED = True/ADMIN_ENABLED = False/g' /rmm/api/tacticalrmm/tacticalrmm/local_settings.py
|
2020-07-02 08:02:56 +00:00
|
|
|
|
2020-06-24 17:28:04 +00:00
|
|
|
print_green 'Restarting services'
|
2021-04-03 00:24:31 +00:00
|
|
|
for i in rmm.service daphne.service celery.service celerybeat.service
|
2020-04-13 00:09:01 +00:00
|
|
|
do
|
2021-01-17 01:16:28 +00:00
|
|
|
sudo systemctl stop ${i}
|
|
|
|
sudo systemctl start ${i}
|
2020-04-13 00:09:01 +00:00
|
|
|
done
|
|
|
|
|
2020-03-01 00:46:23 +00:00
|
|
|
printf >&2 "${YELLOW}%0.s*${NC}" {1..80}
|
2019-10-22 22:22:36 +00:00
|
|
|
printf >&2 "\n\n"
|
2020-03-01 00:46:23 +00:00
|
|
|
printf >&2 "${YELLOW}Installation complete!${NC}\n\n"
|
2020-08-27 09:38:51 +00:00
|
|
|
printf >&2 "${YELLOW}Download the meshagent 64 bit EXE from:\n\n${GREEN}"
|
|
|
|
echo ${MESHEXE} | sed 's/{.*}//'
|
|
|
|
printf >&2 "${NC}\n\n"
|
2020-06-24 17:28:04 +00:00
|
|
|
printf >&2 "${YELLOW}Access your rmm at: ${GREEN}https://${frontenddomain}${NC}\n\n"
|
2020-03-01 00:46:23 +00:00
|
|
|
printf >&2 "${YELLOW}Django admin url: ${GREEN}https://${rmmdomain}/${ADMINURL}${NC}\n\n"
|
2021-01-22 00:40:09 +00:00
|
|
|
printf >&2 "${YELLOW}MeshCentral username: ${GREEN}${meshusername}${NC}\n"
|
2020-06-24 17:28:04 +00:00
|
|
|
printf >&2 "${YELLOW}MeshCentral password: ${GREEN}${MESHPASSWD}${NC}\n\n"
|
2020-08-15 04:25:42 +00:00
|
|
|
|
|
|
|
if [ "$BEHIND_NAT" = true ]; then
|
2020-12-17 22:28:01 +00:00
|
|
|
echo -ne "${YELLOW}Read below if your router does NOT support Hairpin NAT${NC}\n\n"
|
2020-08-15 04:25:42 +00:00
|
|
|
echo -ne "${GREEN}If you will be accessing the web interface of the RMM from the same LAN as this server,${NC}\n"
|
|
|
|
echo -ne "${GREEN}you'll need to make sure your 3 subdomains resolve to ${IPV4}${NC}\n"
|
|
|
|
echo -ne "${GREEN}This also applies to any agents that will be on the same local network as the rmm.${NC}\n"
|
2021-01-20 22:11:54 +00:00
|
|
|
echo -ne "${GREEN}You'll also need to setup port forwarding in your router on ports 80, 443 and 4222 tcp.${NC}\n\n"
|
2020-08-15 04:25:42 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-01 00:46:23 +00:00
|
|
|
printf >&2 "${YELLOW}Please refer to the github README for next steps${NC}\n\n"
|
|
|
|
printf >&2 "${YELLOW}%0.s*${NC}" {1..80}
|
2019-11-17 10:12:40 +00:00
|
|
|
printf >&2 "\n"
|