Commit 2fbda219 authored by mlsuyt2718's avatar mlsuyt2718

script of installation of gmixer

parent 7617a657
#!/usr/bin/env bash
# gmixer-py installation : installation de gmixer-py : mixeur de monnaie libre
# License : Creative Commons http://creativecommons.org/licenses/by-nd/4.0/deed.fr
VERSION="2019.04.25"
set -e
# VARIABLES
blanc="\033[1;37m"
gris="\033[0;37m"
magenta="\033[0;35m"
rouge="\033[1;31m"
vert="\033[1;32m"
jaune="\033[1;33m"
bleu="\033[1;34m"
rescolor="\033[0m"
# DEBUT DU SCRIPT
echo -e "$vert"
echo -e "#########################################################"
echo -e "# #"
echo -e "# Script d'installation de GMIXER #"
echo -e "# #"
echo -e "# Testé sur Debian 9.8 x64 #"
echo -e "# by @pytlin #"
echo -e "# #"
echo -e "#########################################################"
echo -e " $VERSION"
echo -e "$rescolor\n\n"
sleep 3
if [ "$UID" -eq "0" ]
then
echo -e "\n${jaune}\tDon't Run this script as root.$rescolor \n\n"
exit 1
fi
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
# Older SuSE/etc.
...
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
...
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
#---------------------------functions-------------------------------------------------------------
#retrieve public ip
getPublicIp () {
curl -s ifconfig.me
}
#retrieve project gmixer from gitlab
#todo : test if folder exists
getGmixerProject () {
cd ~
git clone https://git.duniter.org/tuxmain/gmixer-py.git
}
#generate configuration folder (default folder : ~/.gmixer)
generateConfFolder () {
cd ~/gmixer-py
if [ "$OS" == "Debian GNU/Linux" ]; then
python3.7 server.py -i
elif [ "$OS" == "CentOS Linux" ]; then
python3.6 server.py -i
else
python3.7 server.py -i
fi
}
#update system with package manager : apt for debian derivative system and yum for centos derivated system
updateSystem () {
if [ "$OS" == "Debian GNU/Linux" ]; then
sudo apt update -y && sudo apt upgrade -y
elif [ "$OS" == "CentOS Linux" ]; then
sudo yum update -y && sudo yum upgrade -y
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
#installation of dependancies for Python
installDepPython () {
if [ "$OS" == "Debian GNU/Linux" ]; then
sudo apt install build-essential sqlite3 bzip2 libbz2-dev zlib1g-dev openssl libgdbm-dev liblzma-dev libreadline-dev libffi-dev -y
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
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
installDepPythonForGMixer () {
if [ "$OS" == "Debian GNU/Linux" ]; then
sudo apt install python3-pip -y
sudo apt install python3 python-dev python3-dev build-essential libssl-dev libffi-dev libxml2-dev libxslt1-dev zlib1g-dev python-pip
sudo pip3.7 install --upgrade pip
sudo pip3.7 install libnacl duniterpy silkaj py-ubjson plyvel PySocks
# seulement si antérieure à 3.6, entrer la ligne suivante
#sudo pip3 install python2-secrets
elif [ "$OS" == "CentOS Linux" ]; then
#todo
echo "todo"
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
#installation of dependancies for Gmixer
installDepGMixer () {
if [ "$OS" == "Debian GNU/Linux" ]; then
sudo apt install libsodium-dev -y
elif [ "$OS" == "CentOS Linux" ]; then
sudo yum install libsodium-devel -y
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
installPython () {
if [ "$OS" == "Debian GNU/Linux" ]; then
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
sudo tar xzf Python-3.7.3.tgz
sudo rm -f /usr/src/Python-3.7.3.tgz
cd Python-3.7.3
sudo ./configure --enable-optimizations
sudo make altinstall
elif [ "$OS" == "CentOS Linux" ]; then
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
sudo tar xzf Python-3.7.0.tgz
sudo rm -f /usr/src/Python-3.7.0.tgz
cd Python-3.7.0
sudo ./configure --enable-optimizations
sudo make altinstall
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
checkInstallPython () {
if [ "$OS" == "Debian GNU/Linux" ]; then
vPython=`python3.7 -V`
if [[ "$vPython" =~ "Python" ]]; then
echo -e "\n${vert}Python is well installed...${rescolor}"
else
echo -e "\n${red}Python is not correctly installed, please check your python installation...${rescolor}"
exit 1
fi
elif [ "$OS" == "CentOS Linux" ]; then
vPython=`python3.6 -V`
if [[ "$vPython" =~ "Python" ]]; then
echo -e "\n${vert}Python is well installed...${rescolor}"
else
echo -e "\n${red}Python is not correctly installed, please check your python installation...${rescolor}"
exit 1
fi
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
launchGMixer () {
if [ "$OS" == "Debian GNU/Linux" ]; then
python3.7 ~/gmixer-py/server.py -s -d ~/.gmixer
elif [ "$OS" == "CentOS Linux" ]; then
python3.6 ~/gmixer-py/server.py -s -d ~/.gmixer
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
installOrBuildCmake () {
if [ "$OS" == "Debian GNU/Linux" ]; then
#sudo apt install build-essential cmake -y #pour installer cmake nécessaire au build de leveldb >=1.21 #fonctionne sur debian stretch 9.8
#si installation au-dessus échoue, construire à la main cmake
sudo wget https://cmake.org/files/LatestRelease/cmake-3.14.3.tar.gz -O cmake.tar.gz
sudo tar -xvf cmake.tar.gz
cd cmake-3.14.3/
sudo chmod +x bootstrap
sudo ./bootstrap
sudo make && sudo make install
elif [ "$OS" == "CentOS Linux" ]; then
#sudo yum install build-essential cmake -y #pour installer cmake nécessaire au build de leveldb >=1.21 #fonctionne sur debian stretch 9.8
#si installation au-dessus échoue, construire à la main cmake
sudo wget https://cmake.org/files/LatestRelease/cmake-3.14.3.tar.gz -O cmake.tar.gz
sudo tar -xvf cmake.tar.gz
cd cmake-3.14.3/
sudo chmod +x bootstrap
sudo ./bootstrap
sudo make && sudo make install
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
buildLevelDB () {
if [ "$OS" == "Debian GNU/Linux" ]; then
cd ~
#for plylevel install leveldb >=1.21 (build it by hand on debian stretch, CMake 3.9 or higher is required)
wget https://github.com/google/leveldb/archive/1.21.tar.gz
tar xvzf 1.21.tar.gz
cd leveldb-1.21
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .
sudo mv libleveldb.* /usr/local/lib
sudo ldconfig
rm -rf ~/1.21.tar.gz
elif [ "$OS" == "CentOS Linux" ]; then
#for plylevel install leveldb >=1.21 (build it by hand on debian stretch, CMake 3.9 or higher is required)
wget https://github.com/google/leveldb/archive/1.21.tar.gz
tar xvzf 1.21.tar.gz
cd leveldb-1.21
mkdir -p build && cd build
~/cmake-3.14.3/bin/cmake -DCMAKE_BUILD_TYPE=Release .. && ~/cmake-3.14.3/bin/cmake --build .
sudo mv libleveldb.* /usr/local/lib
sudo ldconfig
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
openPortGMixer () {
if [ "$OS" == "Debian GNU/Linux" ]; 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
elif [ "$OS" == "CentOS Linux" ]; then
sudo firewall-cmd --permanent --add-port=10951/tcp
sudo firewall-cmd --reload
else
echo -e "\n${jaune}distribution not yet supported...${rescolor}"
exit 1
fi
}
#---------------------------end functions-------------------------------------------------------------
#---------------------------programm-----------------------------------------------------------------
if [ "$OS" == "Debian GNU/Linux" ]; then
echo -e "\n${jaune}Update system...${rescolor}"
updateSystem
echo -e "\n${jaune}Installation of dependancies for installing python 3.7...${rescolor}"
installDepPython
echo -e "\n${jaune}build of python 3.7, this step may take time, don't hesitate to take a coffee...${rescolor}"
installPython
echo -e "\n${jaune}check installation of python 3.7${rescolor}"
checkInstallPython
echo -e "\n${jaune}Installation of dependancies for gmixer-py...${rescolor}"
installDepGMixer
echo -e "\n${jaune}Installation of cmake for building leveldb 1.21...${rescolor}"
installOrBuildCmake
echo -e "\n${jaune}Build of leveldb 1.21...${rescolor}"
buildLevelDB
echo -e "\n${jaune}installation of python dependancies for gmixer...${rescolor}"
installDepPythonForGMixer
echo -e "\n${jaune}open port 10951 (default port)...${rescolor}"
openPortGMixer
echo -e "\n${jaune}retrieve project gmixer from gitlab...${rescolor}"
getGmixerProject
echo -e "\n${jaune}generate configuration folder : ~/.gmixer...${rescolor}"
generateConfFolder
echo -e "\n${jaune}retrieve public ip...${rescolor}"
ip=$( getPublicIp )
#add this address in ~/.gmixer/config.json
sed -i "s/127.0.1.1/`echo $ip`/g" ~/.gmixer/config.json
sudo sed -i "s/"null,"/"[\"127.0.0.1\",9050],"/g" ~/.gmixer/config.json
sudo sed -i "s/"false"/"true"/g" ~/.gmixer/config.json
echo -e "\n${jaune}................Installation of tor...${rescolor}"
echo -e "\n${jaune}Update system...${rescolor}"
sudo apt update -y && sudo apt upgrade -y
sudo apt install apt-transport-https
echo -e "\n${jaune}Import signatures...${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
echo -e "\n${jaune}Configuration of tor...${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
echo -e "\n${jaune}Reload configuration...${rescolor}"
sudo systemctl reload tor
echo -e "\n${jaune}restart of tor...${rescolor}"
sudo systemctl restart tor
echo -e "\n${jaune}Print of your onion domain...${rescolor}"
sudo cat "/var/lib/tor/hidden_service/hostname"
echo -e "\n${jaune}launch GMixer...${rescolor}"
launchGMixer
elif [ "$OS" == "CentOS Linux" ]; then
echo -e "\n${jaune}Update system...${rescolor}"
updateSystem
echo -e "\n${jaune}Installation of dependancies for python 3.7...${rescolor}"
installDepPython
echo -e "\n${jaune}build of python 3.7, this step may take time, don't hesitate to take a coffee...${rescolor}"
installPython
echo -e "\n${jaune}check installation of python 3.7${rescolor}"
checkInstallPython
echo -e "\n${jaune}Installation of dependancies for gmixer-py...${rescolor}"
installDepGMixer
echo -e "\n${jaune}Installation of g++...${rescolor}"
sudo yum -y install gcc-c++
echo -e "\n${jaune}Installation of cmake for building leveldb 1.21...${rescolor}"
installOrBuildCmake
echo -e "\n${jaune}Build of leveldb 1.21...${rescolor}"
buildLevelDB
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
echo -e "\n${jaune}Installation of package manager for python : pip3...${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
echo -e "\n${jaune}Open port 10951...${rescolor}"
openPortGMixer
echo -e "\n${jaune}retrieve project gmixer from gitlab...${rescolor}"
getGmixerProject
echo -e "\n${jaune}generate configuration folder : ~/.gmixer...${rescolor}"
generateConfFolder
echo -e "\n${jaune}retrieve public ip...${rescolor}"
ip=$( getPublicIp )
#add this address in ~/.gmixer/config.json
sed -i "s/`echo $HOSTNAME`/`echo $ip`/g" ~/.gmixer/config.json
sudo sed -i "s/"null,"/"[\"127.0.0.1\",9050],"/g" ~/.gmixer/config.json
sudo sed -i "s/"false"/"true"/g" ~/.gmixer/config.json
echo -e "\n${jaune}launch GMixer...${rescolor}"
launchGMixer
else
echo "distribution not yet supported, ask to support your distribution by mail : pytlin@protonmail.com"
fi
#---------------------------end of programm-----------------------------------------------------------------
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