From 9bd38b08d1c8967ff752d9c675c0ed925b9b1460 Mon Sep 17 00:00:00 2001 From: benjamin Date: Thu, 2 May 2019 14:58:40 -0400 Subject: [PATCH] configurationTor function / parameter -t, -v and -h respectively for tor or not, verbose mode and help / installationTor function / main function / mainVerbose function / helpFunction function which prints out usage --- .gitignore | 1 + install_gmixer.sh | 420 +++++++++++++++++++++++++++++++++------------- 2 files changed, 302 insertions(+), 119 deletions(-) diff --git a/.gitignore b/.gitignore index 39c9eb9..8f3c27b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ peers default.ini +__pycache__/ diff --git a/install_gmixer.sh b/install_gmixer.sh index 976075f..a4743dd 100755 --- a/install_gmixer.sh +++ b/install_gmixer.sh @@ -3,7 +3,8 @@ # License : Creative Commons http://creativecommons.org/licenses/by-nd/4.0/deed.fr # contact mail : -VERSION="2019.05.01" + +VERSION="2019.05.02" set -e #set -x @@ -20,13 +21,16 @@ rescolor="\033[0m" noError="false" + + + # Start of script printf "\n%b$green\n" printf "#########################################################\n" printf "# #\n" printf "# Installation script GMIXER #\n" printf "# #\n" -printf "# Test on Debian 9.8 x64 #\n" +printf "# Tested on Debian 9.8 x64 #\n" printf "# by @pytlin #\n" printf "# #\n" printf "#########################################################\n" @@ -35,15 +39,12 @@ printf %b "$rescolor\n" sleep 3 -if test "$(id -u)" -eq "0" +if test "$(id -u)" = "0" then printf "\n\n%b\t\tDon't Run this script as root.%b\n\n" "${yellow}" "$rescolor" exit 1 fi - - - if [ -f /etc/os-release ]; then # freedesktop.org and systemd . /etc/os-release @@ -77,6 +78,21 @@ fi #---------------------------functions------------------------------------------------------------- +helpFunction () +{ + printf "" + echo "Usage: $0 -t [1,2,3] -v -h\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" + printf "\t\t 3 => mixer node into tor network : hidden service\n" + printf "\t-v This parameter activate verbose mode\n" + printf "\t-h This parameter print out the help\n" + exit 1 # Exit script after printing help +} + + + #retrieve public ip getPublicIp () { @@ -99,24 +115,26 @@ getGmixerProject () { #generate configuration folder (default folder : $HOME/.gmixer) generateConfFolder () { noError="false" - cd $HOME/gmixer-py if [ ! -d "$HOME/.gmixer" ]; then if [ "$OS" = "Debian GNU/Linux" ]; then - python3.7 server.py -i + $HOME/gmixer-py/python3.7 server.py -i checkCommand elif [ "$OS" = "CentOS Linux" ]; then - python3.6 server.py -i + $HOME/gmixer-py/python3.6 server.py -i checkCommand else - python3.7 server.py -i + $HOME/gmixer-py/python3.7 server.py -i checkCommand fi + else + noError="true" fi } printOkKo() { - if [ "$noError" = "true" ]; then + if test "$noError" = "true" + then printf "%bOK%b\n" "${green}" "${rescolor}" else printf "%bKO%b\n" "${red}" "${rescolor}" @@ -156,7 +174,7 @@ updateSystem () { installDepPython () { noError="false" if [ "$OS" = "Debian GNU/Linux" ]; then - sudo apt-get install build-essential sqlite3 bzip2 libbz2-dev zlib1g-dev openssl libgdbm-dev liblzma-dev libreadline-dev libffi-dev -y + sudo apt-get install build-essential sqlite3 bzip2 libbz2-dev zlib1g-dev openssl libgdbm-dev liblzma-dev libreadline-dev libffi-dev apt-transport-https -y checkCommand elif [ "$OS" = "CentOS Linux" ]; then sudo yum install build-essential sqlite3 bzip2 openssl openssl-devel bzip2-devel libffi-devel -y #non nécessaire libssl-dev @@ -170,9 +188,9 @@ installDepPython () { installDepPythonForGMixer () { noError="false" if [ "$OS" = "Debian GNU/Linux" ]; then - sudo apt-get install python3-pip python3 python-dev python3-dev build-essential libffi-dev libxml2-dev libxslt1-dev zlib1g-dev -y - sudo pip3.7 install --upgrade pip - sudo pip3.7 install libnacl duniterpy silkaj py-ubjson plyvel PySocks + sudo apt-get install python3-pip python3 python-dev python3-dev build-essential libffi-dev libxml2-dev libxslt1-dev zlib1g-dev -y 2> /dev/null + sudo pip3.7 install --upgrade pip 2> /dev/null + sudo pip3.7 install libnacl duniterpy silkaj py-ubjson plyvel PySocks 2> /dev/null checkCommand # seulement si antérieure à 3.6, entrer la ligne suivante #sudo pip3 install python2-secrets @@ -229,6 +247,26 @@ installPython () { cd Python-3.7.0 sudo ./configure --enable-optimizations sudo make altinstall + + #centos to modify + #sudo yum install python36 -y + #sudo yum install python36-devel -y + #sudo yum install python36-setuptools -y + #sudo easy_install-3.6 pip -y + #sudo yum remove python-setuptools + #sudo yum install python-setuptools + #sudo yum install python36-pip + #printf "\n%bInstallation of package manager for python : pip3...%b\n" "${yellow}" "${rescolor}" + #sudo yum install epel-release + #sudo yum install python36-setuptools + #sudo easy_install-3.6 pip3 + #sudo python -m pip install --upgrade pip + #sudo yum install python-pkg-resources + #sudo pip3 install setuptools + #sudo pip3 install libnacl duniterpy silkaj py-ubjson plyvel PySocks + # seulement si antérieure à 3.6, entrer la ligne suivante + #sudo pip3 install python2-secrets + else printf "\n%bPython 3.7.3 is already installed, nothing to do...%b\n" "${green}" "${rescolor}" fi @@ -413,6 +451,21 @@ buildLevelDB () { +} + +checkTorInstallation () { + noError="false" + vTor=$(tor --version) + torStr="Tor version" + if [ -z "${vTor##*$torStr*}" ] + then + printf "\n%bTor is well installed...%b\n" "${green}" "${rescolor}" + noError="true" + else + printf "\n%Tor is not correctly installed, please check your Tor installation...%b\n" "${red}" "${rescolor}" + noError="false" + exit 1 + fi } openPortGMixer () { @@ -445,8 +498,11 @@ modifiyConfigurationFile () { printf "%bretrieve public ip...%b" "${yellow}" "${rescolor}" ip=$( getPublicIp ) sed -i "s/127.0.1.1/`echo $ip`/g" $HOME/.gmixer/config.json - sudo sed -i "s/"null,"/"[\"127.0.0.1\",9050],"/g" $HOME/.gmixer/config.json - sudo sed -i "s/"false"/"true"/g" $HOME/.gmixer/config.json + if test "$parameterT" = "2" || test "$parameterT" = "3" + then + sudo sed -i "s/"null,"/"[\"127.0.0.1\",9050],"/g" $HOME/.gmixer/config.json + sudo sed -i "s/"false"/"true"/g" $HOME/.gmixer/config.json + fi checkCommand elif [ "$OS" = "CentOS Linux" ]; then printf "ok" @@ -457,6 +513,205 @@ modifiyConfigurationFile () { +} + +installationTor () { + noError="false" + curl -s https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --import 2>/dev/null + gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add - 2>/dev/null + numberOccTorProject=$(grep -c "deb.torproject.org" /etc/apt/sources.list) + if test "$numberOccTorProject" = "0" + then + echo "deb http://deb.torproject.org/torproject.org stretch main" | sudo tee -a /etc/apt/sources.list + echo "deb-src http://deb.torproject.org/torproject.org stretch main" | sudo tee -a /etc/apt/sources.list + fi + sudo apt-get update -y && sudo apt-get upgrade -y + sudo apt-get install tor deb.torproject.org-keyring -y + +} + +configurationTor () { + noError="false" + numberOccHiddenServiceDir=$(grep -c "#HiddenServiceDir" /etc/tor/torrc) + numberOccHiddenServicePort=$(grep -c "#HiddenServicePort" /etc/tor/torrc) + if test "$numberOccHiddenServiceDir" = "2" && test "$numberOccHiddenServicePort" = "3" + then + printf "ok" + sudo sed -i "s/"#DataDirectory"/"DataDirectory"/g" /etc/tor/torrc + sudo sed -ie '0,/#HiddenServiceDir/ s/#HiddenServiceDir/HiddenServiceDir/' /etc/tor/torrc + sudo sed -ie '0,/#HiddenServicePort/ s/#HiddenServicePort/HiddenServicePort/' /etc/tor/torrc + checkCommand + fi + + + + if test "$numberOccHiddenServiceDir" = "1" && test "$numberOccHiddenServicePort" = "2" + then + noError="true" + fi +} + +main () { + + printf "\n%bUpdate system...%b" "${yellow}" "${rescolor}" + updateSystem > /dev/null + printOkKo + printf "%bInstallation of dependancies for installing python 3.7...%b" "${yellow}" "${rescolor}" + installDepPython > /dev/null + printOkKo + printf "%bBuild of python 3.7, this step may take time, don't hesitate to take a coffee...%b" "${yellow}" "${rescolor}" + installPython > /dev/null + checkInstallPython > /dev/null + printOkKo + printf "%bInstallation of dependancies for gmixer-py...%b" "${yellow}" "${rescolor}" + installDepGMixer > /dev/null + printOkKo + #for centos + #printf "\n%bInstallation of g++...%b\n" "${yellow}" "${rescolor}" + #sudo yum -y install gcc-c++ + printf "%bBuild of cmake 3.14.3 (necessary for leveldb 1.21), this step may take time, don't hesitate to take a coffee...%b" "${yellow}" "${rescolor}" + installOrBuildCmake > /dev/null + checkInstallCmake > /dev/null + printOkKo + printf "%bBuild of leveldb 1.21, this step may take time, don't hesitate to take a coffee....%b" "${yellow}" "${rescolor}" + buildLevelDB > /dev/null + checkBuildLevelDB > /dev/null + printOkKo + 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 + printf "%bRetrieve project gmixer from gitlab...%b" "${yellow}" "${rescolor}" + getGmixerProject > /dev/null + printOkKo + printf "%bGenerate configuration folder : $HOME/.gmixer...%b" "${yellow}" "${rescolor}" + generateConfFolder > /dev/null + printOkKo + printf "%bModify configuration file...%b" "${yellow}" "${rescolor}" + modifiyConfigurationFile > /dev/null + printOkKo + if test "$parameterT" = "2" || test "$parameterT" = "3" + then + printf "%bInstallation of Tor...%b" "${yellow}" "${rescolor}" + installationTor > /dev/null + checkTorInstallation > /dev/null + printOkKo + if test "$parameterT" = "3" + then + printf "%bConfiguration of tor...%b" "${yellow}" "${rescolor}" + configurationTor > /dev/null + printOkKo + printf "%bReload configuration...%b" "${yellow}" "${rescolor}" + sudo systemctl reload tor > /dev/null + noError="false" + checkCommand + printOkKo + fi + printf "%bRestart of tor...%b" "${yellow}" "${rescolor}" + sudo systemctl restart tor > /dev/null + noError="false" + checkCommand + printOkKo + if test "$parameterT" = "3" + then + printf "%bYour onion domain is :%b\n" "${yellow}" "${rescolor}" + if [ ! -f "/var/lib/tor/hidden_service/hostname" ] + then + sudo cat "/var/lib/tor/hidden_service/hostname" + printf "%bCopy this onion domain in the gmixer config.json in public_host and bind_host :%b\n" "${yellow}" "${rescolor}" + else + printf "%b/var/lib/tor/hidden_service/hostname doesn't exists, check your configuration of tor%b\n" "${red}" "${rescolor}" + + fi + fi + fi + printf "%bLaunch GMixer : %b\n" "${yellow}" "${rescolor}" + launchGMixer + +} + + + +mainVerbose () { + + printf "\n%bUpdate system...%b" "${yellow}" "${rescolor}" + updateSystem + printOkKo + printf "%bInstallation of dependancies for installing python 3.7...%b" "${yellow}" "${rescolor}" + installDepPython + printOkKo + printf "%bBuild of python 3.7, this step may take time, don't hesitate to take a coffee...%b" "${yellow}" "${rescolor}" + installPython + checkInstallPython + printOkKo + printf "%bInstallation of dependancies for gmixer-py...%b" "${yellow}" "${rescolor}" + installDepGMixer + printOkKo + #for centos + #printf "\n%bInstallation of g++...%b\n" "${yellow}" "${rescolor}" + #sudo yum -y install gcc-c++ + printf "%bBuild of cmake 3.14.3 (necessary for leveldb 1.21), this step may take time, don't hesitate to take a coffee...%b" "${yellow}" "${rescolor}" + installOrBuildCmake + checkInstallCmake + printOkKo + printf "%bBuild of leveldb 1.21, this step may take time, don't hesitate to take a coffee....%b" "${yellow}" "${rescolor}" + buildLevelDB + checkBuildLevelDB + printOkKo + printf "%bInstallation of python dependancies for gmixer...%b" "${yellow}" "${rescolor}" + installDepPythonForGMixer + printOkKo + printf "%bOpen port 10951 (default port)...%b" "${yellow}" "${rescolor}" + openPortGMixer + printOkKo + printf "%bRetrieve project gmixer from gitlab...%b" "${yellow}" "${rescolor}" + getGmixerProject + printOkKo + printf "%bGenerate configuration folder : $HOME/.gmixer...%b" "${yellow}" "${rescolor}" + generateConfFolder + printOkKo + printf "%bModify configuration file...%b" "${yellow}" "${rescolor}" + modifiyConfigurationFile + printOkKo + if test "$parameterT" = "2" || test "$parameterT" = "3" + then + printf "%bInstallation of Tor...%b" "${yellow}" "${rescolor}" + installationTor + checkTorInstallation + printOkKo + if test "$parameterT" = "3" + then + printf "%bConfiguration of tor...%b" "${yellow}" "${rescolor}" + configurationTor + printOkKo + printf "%bReload configuration...%b" "${yellow}" "${rescolor}" + sudo systemctl reload tor + noError="false" + checkCommand + printOkKo + fi + printf "%bRestart of tor...%b" "${yellow}" "${rescolor}" + sudo systemctl restart tor + noError="false" + checkCommand + printOkKo + if test "$parameterT" = "3" + then + printf "%bYour onion domain is :%b\n" "${yellow}" "${rescolor}" + if [ ! -f "/var/lib/tor/hidden_service/hostname" ] + then + sudo cat "/var/lib/tor/hidden_service/hostname" + printf "%bCopy this onion domain in the gmixer config.json in public_host and bind_host :%b\n" "${yellow}" "${rescolor}" + else + printf "%b/var/lib/tor/hidden_service/hostname doesn't exists, check your configuration of tor%b\n" "${red}" "${rescolor}" + fi + fi + fi + printf "%bLaunch GMixer : %b\n" "${yellow}" "${rescolor}" + launchGMixer + } #-----------------------------------------------------------------------------------end functions------------------------------------------------------------- @@ -465,113 +720,40 @@ modifiyConfigurationFile () { #-------------------------programm-------------------------------------------------------------------------------------------------------- -printf "\n%bUpdate system...%b" "${yellow}" "${rescolor}" -updateSystem > /dev/null -printOkKo -printf "%bInstallation of dependancies for installing python 3.7...%b" "${yellow}" "${rescolor}" -installDepPython > /dev/null -printOkKo -printf "%bbuild of python 3.7, this step may take time, don't hesitate to take a coffee...%b" "${yellow}" "${rescolor}" -installPython > /dev/null -checkInstallPython > /dev/null -printOkKo - -printf "%bInstallation of dependancies for gmixer-py...%b" "${yellow}" "${rescolor}" -installDepGMixer > /dev/null -printOkKo -#for centos -#printf "\n%bInstallation of g++...%b\n" "${yellow}" "${rescolor}" -#sudo yum -y install gcc-c++ -printf "%bBuild of cmake 3.14.3 (necessary for leveldb 1.21), this step may take time, don't hesitate to take a coffee...%b" "${yellow}" "${rescolor}" -installOrBuildCmake > /dev/null -checkInstallCmake > /dev/null -printOkKo -printf "%bBuild of leveldb 1.21, this step may take time, don't hesitate to take a coffee....%b" "${yellow}" "${rescolor}" -buildLevelDB > /dev/null -checkBuildLevelDB > /dev/null -printOkKo - - - -#for centos -#centos to modify -#sudo yum install python36 -y -#sudo yum install python36-devel -y -#sudo yum install python36-setuptools -y -#sudo easy_install-3.6 pip -y -#sudo yum remove python-setuptools -#sudo yum install python-setuptools -#sudo yum install python36-pip - -#printf "\n%bInstallation of package manager for python : pip3...%b\n" "${yellow}" "${rescolor}" -#sudo yum install epel-release -#sudo yum install python36-setuptools -#sudo easy_install-3.6 pip3 -#sudo python -m pip install --upgrade pip -#sudo yum install python-pkg-resources -#sudo pip3 install setuptools -#sudo pip3 install libnacl duniterpy silkaj py-ubjson plyvel PySocks - - -# seulement si antérieure à 3.6, entrer la ligne suivante -#sudo pip3 install python2-secrets - - -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 -printf "%bretrieve project gmixer from gitlab...%b" "${yellow}" "${rescolor}" -getGmixerProject > /dev/null -printOkKo -printf "%bgenerate configuration folder : $HOME/.gmixer...%b" "${yellow}" "${rescolor}" -generateConfFolder > /dev/null -printOkKo -printf "%bmodify configuration file...%b" "${yellow}" "${rescolor}" -modifiyConfigurationFile > /dev/null -printOkKo - - - -printf "\n%b................Installation of tor...%b\n" "${yellow}" "${rescolor}" - -printf "\n%bUpdate system...%b\n" "${yellow}" "${rescolor}" -sudo apt update -y && sudo apt upgrade -y -sudo apt install apt-transport-https - -printf "\n%bImport signatures...%b\n" "${yellow}" "${rescolor}" -curl -s https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --import -gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add - - -echo "deb http://deb.torproject.org/torproject.org stretch main" | sudo tee -a /etc/apt/sources.list -echo "deb-src http://deb.torproject.org/torproject.org stretch main" | sudo tee -a /etc/apt/sources.list -sudo apt update -y && sudo apt upgrade -y -sudo apt install tor deb.torproject.org-keyring -y - -printf "\n%bConfiguration of tor...%b\n" "${yellow}" "${rescolor}" -sudo sed -i "s/"#DataDirectory"/"DataDirectory"/g" /etc/tor/torrc -sudo sed -ie '0,/#HiddenServiceDir/ s/#HiddenServiceDir/HiddenServiceDir/' /etc/tor/torrc -sudo sed -ie '0,/#HiddenServicePort/ s/#HiddenServicePort/HiddenServicePort/' /etc/tor/torrc - -printf "\n%bReload configuration...%b\n" "${yellow}" "${rescolor}" -sudo systemctl reload tor - -printf "\n%brestart of tor...%b\n" "${yellow}" "${rescolor}" -sudo systemctl restart tor - -printf "\n%bPrint of your onion domain...%b\n" "${yellow}" "${rescolor}" -sudo cat "/var/lib/tor/hidden_service/hostname" - -printf "\n%blaunch GMixer...%b\n" "${yellow}" "${rescolor}" -launchGMixer +parameterV="false" +parameterH="false" +while getopts "t:vh" opt +do + case "$opt" in + t ) parameterT="$OPTARG" ;; + v ) parameterV="true" ;; + h ) parameterH="true" ;; + ? ) helpFunction ;; # Print helpFunction in case parameter is non-existent + esac +done -#---------------------------end of programm----------------------------------------------------------------- +if [ "$parameterH" = "true" ] +then + helpFunction +fi + +if [ "$parameterV" = "false" ]; then + + main + exit 0 + +else + mainVerbose + exit 0 + +fi + + +#---------------------------end of programm----------------------------------------------------------------- -- 2.22.0