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

108 lines
2.8 KiB
Bash

1 year ago
#!/bin/sh
ACTION=${1}
shift 1
get_image() {
GEN_PASS=$(< /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c14; echo)
}
do_install_detail() {
local config=`uci get simplex.@simplex[0].config_path 2>/dev/null`
local port=`uci get simplex.@simplex[0].port 2>/dev/null`
local IMAGE_NAME=`uci get simplex.@simplex[0].image_name 2>/dev/null`
local username=`uci get simplex.@simplex[0].username 2>/dev/null`
local password=`uci get simplex.@simplex[0].password 2>/dev/null`
#Generate the generic environment variables for the docker-compose
# Get our local LAN IP Address
LAN_IP=$(uci get network.lan.ipaddr)
# Strip trailing network mask
LAN_IP="${LAN_IP%/*}"
if [ -z "$config" ]; then
echo "config path is empty!"
exit 1
fi
[ -z "$port" ] && port=5223
echo "Removing Previous Simplex SMP server"
rm -R $config/simplex/
echo "installing Simplex SMP server"
mkdir -p $config/simplex/{config,logs}
echo "Generating Simplex SMP password..."
GEN_PASS2=$(< /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c14; echo)
docker run -d \
--name simplex-smp \
-e "addr=$IMAGE_NAME" \
-e "pass=$GEN_PASS2" \
-p $port:5223 \
-v /opt/docker2/compose/simplex/config:/etc/opt/simplex:z \
-v /opt/docker2/compose/simplex/logs:/var/opt/simplex:z \
simplexchat/simplexmq:latest
sleep 4
address=$(grep "Server address:" $config/simplex/logs/smp-server.log | sed "s/Server address: //")
echo "***********************************************************"
echo "Your SMP server address is:"
echo $address
echo "***********************************************************"
echo "*Copy the server address now and save for use with Simplex*"
echo "***********************************************************"
sleep 1
echo "This local log file will now be deleted."
sleep 1
rm $config/simplex/logs/smp-server.log
echo "Done."
sleep 1
echo "Make sure to forward internal port $port and external port 5223"
echo "on TorGuard WireGuard (Private VPN Cloud)"
}
usage() {
echo "usage: $0 sub-command"
echo "where sub-command is one of:"
echo " install Install simplex"
echo " upgrade Upgrade simplex"
echo " rm/start/stop/restart Remove/Start/Stop/Restart simplex"
echo " status simplex status"
echo " port simplex port"
}
case ${ACTION} in
"install")
get_image
do_install_detail
;;
"upgrade")
get_image
do_install_detail
;;
"rm")
docker rm -f simplex
;;
"start" | "stop" | "restart")
docker ${ACTION} simplex
;;
"status")
docker ps --all -f 'name=simplex' --format '{{.State}}'
;;
"port")
docker ps --all -f 'name=simplex' --format '{{.Ports}}' | grep -om1 '0.0.0.0:[0-9]*' | sed 's/0.0.0.0://'
;;
*)
usage
exit 1
;;
esac