You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
7.8 KiB

4 years ago
#!/bin/bash
4 years ago
4 years ago
if [[ $EUID -ne 0 ]]; then
4 years ago
wdir=$PWD
wdir_connect="$wdir/src-local/hybrid/connect"
toolsok='ok'
3 years ago
if [[ $EUID -eq 0 ]]; then
echo ""
echo "This script must be run without root privileges"
echo ""
echo "Do not run this script with root privileges. Do not use 'sudo'. "
echo ""
exit 1
fi
4 years ago
# create wdir connect dir
4 years ago
if [ ! -d $wdir_connect ];then
4 years ago
mkdir -p $wdir_connect
fi
4 years ago
#check for jq
if ! command -v jq &> /dev/null
then
toolsok='no'
echo "jq could not be found"
exit
fi
# check version >15
if ! command -v node &> /dev/null
then
toolsok='no'
4 years ago
echo ""
4 years ago
echo "No node found"
4 years ago
echo ""
4 years ago
echo "Install: https://github.com/nodesource/distributions"
echo "Install it and try again!"
4 years ago
echo ""
echo "-----------USING UBUNTU------------"
echo "curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -"
echo "sudo apt-get install -y nodejs"
echo ""
4 years ago
exit
4 years ago
else
nodeversion=$(node -v | cut -d'.' -f1)
nodeversion="${nodeversion#v}"
if [ $nodeversion -lt 15 ];then
4 years ago
echo ""
4 years ago
echo "node version < 15"
4 years ago
echo ""
4 years ago
echo "Update: https://github.com/nodesource/distributions"
echo "Update it and try again!"
4 years ago
echo ""
echo "-----------USING UBUNTU------------"
echo "curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -"
echo "sudo apt-get install -y nodejs"
echo ""
4 years ago
toolsok='no'
4 years ago
exit
4 years ago
fi
4 years ago
fi
#check for docker
4 years ago
if ! command -v docker &> /dev/null
then
4 years ago
echo ""
4 years ago
echo "Cannot find docker"
4 years ago
echo ""
4 years ago
echo "Install it and try again!"
echo "http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install.adoc.html"
4 years ago
echo ""
echo "-----------USING UBUNTU------------"
echo "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -"
echo "sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\""
echo "sudo apt update"
echo "sudo apt install -y docker-ce"
echo "sudo usermod -aG docker [USERNAME]"
echo ""
4 years ago
toolsok='no'
4 years ago
exit
4 years ago
else
4 years ago
4 years ago
#check if docker UP
4 years ago
dockerserverdown=$(docker info --format "{{json .}}" | jq .ServerErrors)
4 years ago
if [[ $dockerversion == *denied* ]]; then
4 years ago
echo ""
echo "docker server is down"
echo ""
docker info --format "{{json .}}" | jq .ServerErrors
echo ""
echo "-----------USING UBUNTU------------"
echo ""
echo "Using the following commands you can enable and run docker server";
echo "sudo systemctl enable docker"
echo "sudo systemctl start docker"
echo "sudo systemctl status docker"
echo ""
echo "After adding to the group (usermod command) your shell needs to be restarted. If you dont know what this means please just logout and log in again.";
echo ""
toolsok='no'
exit
fi
4 years ago
#check docker version
4 years ago
dockerversion=$(docker info --format "{{json .}}" | jq .ServerVersion | cut -d'.' -f1)
4 years ago
if [[ ! -z $dockerversion && $dockerversion != 'null' ]] ;then
4 years ago
dockerversion="${dockerversion#\"}"
if [ $dockerversion -lt 19 ];then
echo ""
echo "docker version < 19"
echo ""
echo "Update docker and try again!"
echo "http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install.adoc.html"
echo ""
echo "-----------USING UBUNTU------------"
echo "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -"
echo "sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\""
echo "sudo apt update"
echo "sudo apt install -y docker-ce"
echo "sudo usermod -aG docker [USERNAME]"
echo ""
toolsok='no'
exit
fi
else
4 years ago
echo ""
4 years ago
echo "-----------USING UBUNTU------------"
4 years ago
echo ""
4 years ago
echo "Using the following commands you can enable and run docker server";
echo "sudo systemctl enable docker"
echo "sudo systemctl start docker"
echo "sudo systemctl status docker"
4 years ago
echo ""
4 years ago
echo "After adding to the group (usermod command) your shell needs to be restarted. If you dont know what this means please just logout and log in again.";
4 years ago
echo ""
4 years ago
toolsok='no'
4 years ago
exit
4 years ago
fi
4 years ago
fi
#check for docker-compose
4 years ago
if ! command -v docker-compose &> /dev/null
then
4 years ago
echo ""
4 years ago
echo "Cannot find docker-compose"
echo "Install it and try again!"
echo "http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install.adoc.html"
4 years ago
echo ""
echo "-----------USING UBUNTU------------"
echo ""
echo "sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose"
echo "sudo chmod +x /usr/local/bin/docker-compose"
echo "sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose"
echo ""
4 years ago
toolsok='no'
4 years ago
exit
4 years ago
else
dockercomposeversion=$(docker-compose -f $wdir/test/run.yml config --services)
if [ $dockercomposeversion != 'swarmlabclient' ];then
4 years ago
echo ""
4 years ago
echo "Cannot find docker-compose"
echo "Install it and try again!"
echo "http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install.adoc.html"
4 years ago
echo ""
echo "-----------USING UBUNTU------------"
echo ""
echo "sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose"
echo "sudo chmod +x /usr/local/bin/docker-compose"
echo "sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose"
echo ""
4 years ago
toolsok='no'
4 years ago
exit
4 years ago
fi
4 years ago
fi
#check for wireguard
4 years ago
if ! command -v wg &> /dev/null
then
4 years ago
echo ""
4 years ago
/bin/bash ./install/install-wg.sh
4 years ago
echo ""
4 years ago
# echo "Cannot find wg"
# echo "Install it and try again!"
# echo "https://www.wireguard.com/install/"
# echo ""
# echo "-----------USING UBUNTU------------"
# echo ""
# echo "sudo apt install wireguard"
# echo ""
4 years ago
toolsok='no'
4 years ago
exit
4 years ago
fi
4 years ago
#check for pm2
if ! command -v pm2 &> /dev/null
then
toolsok='no'
echo "pm2 could not be found"
echo "sudo npm install -g pm2"
exit
fi
4 years ago
4 years ago
# npm install
4 years ago
4 years ago
#if [ $toolsok == 'ok' ];then
# npm install
# npm audit fix
#fi
4 years ago
if [ $toolsok == 'ok' ];then
cd src-local
npm install
4 years ago
npm audit fix
4 years ago
cd $wdir
fi
4 years ago
if [ $toolsok == 'ok' ];then
#cp -f $wdir/files/VuetableCssConfig.js $wdir/node_modules/vuetable-2/src/components/VuetableCssConfig.js
#cp -f $wdir/files/serve.js $wdir/node_modules/@vue/cli-service/lib/commands/serve.js
4 years ago
cp -f $wdir/files/status.sh $wdir/src-local/hybrid/connect/status.sh
cp -f $wdir/files/container-stop.sh $wdir/src-local/hybrid/connect/container-stop.sh
4 years ago
cp -f $wdir/files/get-swarmlab-ca $wdir/src-local/hybrid/connect/get-swarmlab-ca
4 years ago
cp -f $wdir/files/get-base-ca $wdir/src-local/hybrid/connect/get-base-ca
4 years ago
mkdir -p $wdir/src-local/instance
4 years ago
mkdir -p $wdir/src-local/builders
4 years ago
cat << FOE > $wdir/src-local/ecosystem.config.js
module.exports = {
"apps": [
{
4 years ago
"name" : "hybridserver",
4 years ago
"autorestart" : true,
"watch" : true,
"cwd" : "$wdir/src-local",
"script" : "./llo/new.js",
"run_as_user" : "node",
"args" : "start",
"pid_file" : "$wdir/src-local/pid.pid",
"log_type" : "json",
"log_file" : "$wdir/src-local/logs/logfile",
"error_file" : "$wdir/src-local/logs/errorfile",
"out_file" : "$wdir/src-local/logs/outfile",
"log_date_format": "YYYY-MM-DD HH:mm Z",
"merge_logs" : true,
"exec_mode" : "fork",
"max_restarts": 10,
"max_memory_restart": "500M",
"restart_delay": 1000
},
]
}
FOE
fi
4 years ago
4 years ago
sudo bash ./src-local/hybrid/connect/get-base-ca
sudo bash ./src-local/hybrid/connect/get-swarmlab-ca
4 years ago
4 years ago
#echo $nodeversion
#echo $dockerversion
#echo $dockercomposeversion
4 years ago
4 years ago
#echo $wdir
#echo $wdir_connect
echo "-------------------------"
echo " --------READY------- "
echo "-------------------------"
echo " Start Server: ./start.sh "
echo ""
echo " Stop Server: ./stop.sh "
echo ""
4 years ago
else
echo ""
echo "-------------------------"
echo "Run ./install.sh as Non-Root User"
echo "-------------------------"
echo ""
fi