Commit cd1b5763 authored by mlsuyt2718's avatar mlsuyt2718

add option -p which permits to enter a port different than default : 10951

parent 0833b4d8
......@@ -4,10 +4,7 @@
# Project : https://git.duniter.org/tuxmain/gmixer-py
# contact mail : <pytlin@protonmail.com>
VERSION="2019.05.03"
VERSION="2019.05.04"
set -e
#set -x
......@@ -89,7 +86,7 @@ fi
helpFunction ()
{
printf ""
echo "Usage: $0 -t [1,2,3] -v -h\n"
echo "Usage: $0 -t [1,2,3] -v -h -g -p <port>\n"
printf "\t-t This parameter enable to create onion node\n"
printf "\t\t 1 => mixer node without tor (default value)\n"
printf "\t\t 2 => mixer node connected to tor\n"
......@@ -97,6 +94,7 @@ helpFunction ()
printf "\t-g This parameter permits to generate randomly the salt and password\n"
#printf "\t-d This parameter permits to launch gmixer in daemon\n"
printf "\t-v This parameter activate verbose mode\n"
printf "\t-p This parameter permits to specify a port (default port is 10951)\n"
printf "\t-h This parameter print out the help\n"
exit 1 # Exit script after printing help
}
......@@ -104,7 +102,7 @@ helpFunction ()
helpFunctionWithoutExit ()
{
printf ""
echo "Usage: $0 -t [1,2,3] -v -h\n"
echo "Usage: $0 -t [1,2,3] -v -h -g -p <port>\n"
printf "\t-t This parameter enable to create onion node\n"
printf "\t\t 1 => mixer node without tor (default value)\n"
printf "\t\t 2 => mixer node connected to tor\n"
......@@ -112,6 +110,7 @@ helpFunctionWithoutExit ()
printf "\t-g This parameter permits to generate randomly the salt and password\n"
#printf "\t-d This parameter permits to launch gmixer in daemon\n"
printf "\t-v This parameter activate verbose mode\n"
printf "\t-p This parameter permits to specify a port (default port is 10951)\n"
printf "\t-h This parameter print out the help\n"
}
......@@ -524,12 +523,12 @@ openPortGMixer () {
noError="false"
if [ "$OS" = "Debian GNU/Linux" ] || [ "$OS" = "Ubuntu" ]; then
sudo iptables -A INPUT -p tcp -m tcp --dport 10951 -j ACCEPT
sudo iptables -A OUTPUT -p tcp -m tcp --dport 10951 -j ACCEPT
sudo iptables -A INPUT -p tcp -m tcp --dport "$@" -j ACCEPT
sudo iptables -A OUTPUT -p tcp -m tcp --dport "$@" -j ACCEPT
checkCommand
elif [ "$OS" = "CentOS Linux" ]; then
sudo firewall-cmd --permanent --add-port=10951/tcp
sudo firewall-cmd --permanent --add-port="$@"/tcp
sudo firewall-cmd --reload
checkCommand
else
......@@ -642,9 +641,28 @@ main () {
printf "%bInstallation of python dependancies for gmixer...%b" "${yellow}" "${rescolor}"
installDepPythonForGMixer > /dev/null
printOkKo
printf "%bOpen port 10951 (default port)...%b" "${yellow}" "${rescolor}"
openPortGMixer > /dev/null
printOkKo
if [ ! -z "$parameterP" ] && [ "$parameterP" != "10951" ]
then
portUse1=$(sudo lsof -i -P -n | grep LISTEN | grep $parameterP | wc -l)
portUse2=$(sudo netstat -tulpn | grep LISTEN | grep $parameterP | wc -l)
if test ${portUse1} = "0" && test ${portUse2} = "0"
then
sed -i "s/\"bind_port\": 10951,/\"bind_port\": `echo $parameterP`,/g" $HOME/.gmixer/config.json
sed -i "s/\"public_port\": 10951/\"public_port\": `echo $parameterP`/g" $HOME/.gmixer/config.json
printf "%bOpen port %s...%b" "${yellow}" "${parameterP}" "${rescolor}"
openPortGMixer ${parameterP}
printOkKo
else
printf "%bPort %s already used, default port 10951 will be used...%b" "${yellow}" "${parameterP}" "${rescolor}"
printf "%bOpen port 10951 (default port)...%b" "${yellow}" "${rescolor}"
openPortGMixer 10951
printOkKo
fi
else
printf "%bOpen port 10951 (default port)...%b" "${yellow}" "${rescolor}"
openPortGMixer 10951
printOkKo
fi
printf "%bRetrieve project gmixer from gitlab...%b" "${yellow}" "${rescolor}"
getGmixerProject > /dev/null
printOkKo
......@@ -689,16 +707,13 @@ main () {
fi
fi
fi
if [ "$parameterG" = "true" ]
then
printf "%bGenerate Salt and Password...%b" "${yellow}" "${rescolor}"
printf "%bGenerate Salt and Password...%b\n" "${yellow}" "${rescolor}"
salt=$(generateRandomSalt)
password=$(generateRandomPass)
sed -i "s/\"id_salt\": \"\",/\"id_salt\": \"`echo $salt`\",/g" $HOME/.gmixer/config.json
sed -i "s/\"id_password\": \"\"/\"id_password\": \"`echo $password`\"/g" $HOME/.gmixer/config.json
checkCommand
printOkKo
else
printf "%bEnter Salt and Password...%b\n" "${yellow}" "${rescolor}"
......@@ -709,7 +724,6 @@ main () {
sed -i "s/\"id_salt\": \"\",/\"id_salt\": \"`echo $salt`\",/g" $HOME/.gmixer/config.json
sed -i "s/\"id_password\": \"\"/\"id_password\": \"`echo $password`\"/g" $HOME/.gmixer/config.json
fi
printf "%bLaunch GMixer : %b\n" "${yellow}" "${rescolor}"
launchGMixer
......@@ -746,9 +760,28 @@ mainVerbose () {
printf "%bInstallation of python dependancies for gmixer...%b" "${yellow}" "${rescolor}"
installDepPythonForGMixer
printOkKo
printf "%bOpen port 10951 (default port)...%b" "${yellow}" "${rescolor}"
openPortGMixer
printOkKo
if [ ! -z "$parameterP" ] && [ "$parameterP" != "10951" ]
then
portUse1=$(sudo lsof -i -P -n | grep LISTEN | grep $parameterP | wc -l)
portUse2=$(sudo netstat -tulpn | grep LISTEN | grep $parameterP | wc -l)
if test ${portUse1} = "0" && test ${portUse2} = "0"
then
sed -i "s/\"bind_port\": 10951,/\"bind_port\": `echo $parameterP`,/g" $HOME/.gmixer/config.json
sed -i "s/\"public_port\": 10951/\"public_port\": `echo $parameterP`/g" $HOME/.gmixer/config.json
printf "%bOpen port %s...%b" "${yellow}" "${parameterP}" "${rescolor}"
openPortGMixer ${parameterP}
printOkKo
else
printf "%bPort %s already used, default port 10951 will be used...%b" "${yellow}" "${parameterP}" "${rescolor}"
printf "%bOpen port 10951 (default port)...%b" "${yellow}" "${rescolor}"
openPortGMixer 10951
printOkKo
fi
else
printf "%bOpen port 10951 (default port)...%b" "${yellow}" "${rescolor}"
openPortGMixer 10951
printOkKo
fi
printf "%bRetrieve project gmixer from gitlab...%b" "${yellow}" "${rescolor}"
getGmixerProject
printOkKo
......@@ -793,9 +826,13 @@ mainVerbose () {
fi
fi
if [ "$parameterG" = "true" ]
then
printf "%bGenerate Salt and Password...%b" "${yellow}" "${rescolor}"
printf "%bGenerate Salt and Password...%b\n" "${yellow}" "${rescolor}"
salt=$(generateRandomSalt)
password=$(generateRandomPass)
sed -i "s/\"id_salt\": \"\",/\"id_salt\": \"`echo $salt`\",/g" $HOME/.gmixer/config.json
......@@ -830,13 +867,14 @@ parameterH="false"
parameterG="false"
parameterD="false"
while getopts "t:vhgd" opt
while getopts "t:vhgdp:" opt
do
case "$opt" in
t ) parameterT="$OPTARG" ;;
v ) parameterV="true" ;;
h ) parameterH="true" ;;
g ) parameterG="true" ;;
p ) parameterP="$OPTARG" ;;
d ) parameterD="true" ;;
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
esac
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment