From 55e8c6aacf377146d940393bb356765ab2ae48d1 Mon Sep 17 00:00:00 2001 From: poka Date: Thu, 19 Mar 2020 21:25:39 +0100 Subject: [PATCH] Improve install.sh --- .install/export_colors.sh | 2 +- .install/ipfs.sh | 29 ++++++++++++++++++ .install/scuttlebutt.sh | 5 ++++ install.sh | 76 ++++++++++++++++++++--------------------------- 4 files changed, 67 insertions(+), 45 deletions(-) create mode 100755 .install/ipfs.sh create mode 100755 .install/scuttlebutt.sh diff --git a/.install/export_colors.sh b/.install/export_colors.sh index 08ef4f0..b1ed53d 100755 --- a/.install/export_colors.sh +++ b/.install/export_colors.sh @@ -1,6 +1,6 @@ #!/bin/bash -[[ -f ~/.bash_aliases && ! -z $(cat ~/.bash_aliases | grep c_red) ]] && echo "Les couleurs sont déjà déclarés dans l'environnement" && exit 1 +[[ -f ~/.bash_aliases && ! -z $(cat ~/.bash_aliases | grep c_red) ]] && exit 1 echo 'export c_blinkfast="\033[6m" export c_light="\033[1m" diff --git a/.install/ipfs.sh b/.install/ipfs.sh new file mode 100755 index 0000000..7967e4f --- /dev/null +++ b/.install/ipfs.sh @@ -0,0 +1,29 @@ +# Install IPFS +ipfs() { + echo -e "${c_yellow}Onboarding IPFS...$c_" + [[ -f /usr/local/bin/ipfs ]] && sudo service ipfs stop + if [[ $ARM == "yes" ]]; then + wget https://dist.ipfs.io/ipfs-update/v1.5.2/ipfs-update_v1.5.2_linux-arm.tar.gz -O $MY_PATH/ipfs-update.tar.gz || err+="Download ipfs-update" + else + wget https://dist.ipfs.io/ipfs-update/v1.5.2/ipfs-update_v1.5.2_linux-amd64.tar.gz -O $MY_PATH/ipfs-update.tar.gz || err+="Download ipfs-update" + fi + + echo "INSTALL ipfs-update" + sudo tar -xvzf $MY_PATH/ipfs-update.tar.gz -C /usr/src/ || err+="Untar ipfs-update" + rm $MY_PATH/ipfs-update.tar.gz + cd /usr/src/ipfs-update/ + sudo ./install.sh || err+="Install ipfs-update" + cd $MY_PATH + + echo "INSTALL latest ipfs" + sudo ipfs-update install latest || err+="Install IPFS" + + echo "CREATE SYSTEMD ipfs SERVICE" + [[ -f /etc/systemd/system/ipfs.service ]] && sudo rm /etc/systemd/system/ipfs.service + sudo cp -f $MY_PATH/templates/1/ipfs.service /etc/systemd/system/ + sudo sed -i "s/_USER/$USER/g" /etc/systemd/system/ipfs.service + + sudo systemctl daemon-reload || err+="Restart IPFS" + sudo systemctl enable ipfs || err+="Enable IPFS daemon" +} + diff --git a/.install/scuttlebutt.sh b/.install/scuttlebutt.sh new file mode 100755 index 0000000..de4717d --- /dev/null +++ b/.install/scuttlebutt.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +scuttlebutt() { + echo "TODO" +} diff --git a/install.sh b/install.sh index 6e1e832..a570a20 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,7 @@ ################################################################################ # Author: Poka (poka@p2p.legal) # Author: Fred (support@qo-op.com) -# Version: 0.1 +# Version: 0.2 # License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) # Git: https://git.p2p.legal/axiom-team/astroport ################################################################################ @@ -18,6 +18,8 @@ echo -e "Installing Astroport" MY_PATH="`dirname \"$0\"`" MY_PATH="`( cd \"$MY_PATH\" && pwd )`" now=$(date +%Y-%m-%d) +unset apps +errors=0 ## Get profile [[ -f $MY_PATH/.profile ]] && source $MY_PATH/.profile || touch $MY_PATH/.profile @@ -32,7 +34,7 @@ help() { ## Get arguments args="$@" -[[ $args =~ all ]] && all=true +apps=$(echo "$@" | tr " " ",") ## Vérifie le type de système [[ $(uname -a | grep arm) ]] && ARM=yes || unset isARM @@ -47,45 +49,21 @@ chmod u+x $MY_PATH/.install/*.sh $MY_PATH/.install/export_colors.sh [[ -f ~/.bash_aliases ]] && source ~/.bash_aliases - # -------------------------------------------- # Install IPFS -ipfs() { - echo -e "${c_yellow}Onboarding IPFS...$c_" - [[ -f /usr/local/bin/ipfs ]] && sudo service ipfs stop - if [[ $ARM == "yes" ]]; then - wget https://dist.ipfs.io/ipfs-update/v1.5.2/ipfs-update_v1.5.2_linux-arm.tar.gz -O $MY_PATH/ipfs-update.tar.gz || err+="Download ipfs-update" - else - wget https://dist.ipfs.io/ipfs-update/v1.5.2/ipfs-update_v1.5.2_linux-amd64.tar.gz -O $MY_PATH/ipfs-update.tar.gz || err+="Download ipfs-update" - fi - - echo "INSTALL ipfs-update" - sudo tar -xvzf $MY_PATH/ipfs-update.tar.gz -C /usr/src/ || err+="Untar ipfs-update" - rm $MY_PATH/ipfs-update.tar.gz - cd /usr/src/ipfs-update/ - sudo ./install.sh || err+="Install ipfs-update" - cd $MY_PATH - - echo "INSTALL latest ipfs" - sudo ipfs-update install latest || err+="Install IPFS" - - echo "CREATE SYSTEMD ipfs SERVICE" - [[ -f /etc/systemd/system/ipfs.service ]] && sudo rm /etc/systemd/system/ipfs.service - sudo cp -f $MY_PATH/templates/1/ipfs.service /etc/systemd/system/ - sudo sed -i "s/_USER/$USER/g" /etc/systemd/system/ipfs.service - - sudo systemctl daemon-reload || err+="Restart IPFS" - sudo systemctl enable ipfs || err+="Enable IPFS daemon" -} +source .install/ipfs.sh # Install ScuttleButt -scuttlebutt() { - echo "TODO" +source .install/scuttlebutt.sh + +# Install iptubes +iptubes() { + source iptubes/install.sh } -# Install IPTubes -iptubes() { +# Install Torrengo +torrengo() { cd $MY_PATH/iptubes ## Install GO wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz -P /tmp/ @@ -108,21 +86,31 @@ iptubes() { rm /tmp/go1.13.4.linux-amd64.tar.gz } +# -------------------------- + # Check installs +functions=$(declare -F | awk '{print $NF}' | sort | egrep -v "^_" ) + ## Check IPFS install [[ -z $(which ipfs) ]] && ipfs - echo -e "${c_green}Astroport UP$c_" -echo -e "Select a gate to install:" -#read gate -gate="iptubes" -case $gate in - iptubes) iptubes;; -# flattg) flattg;; - *) echo -e "${c_yellow}Bye !$c_";; -esac +[[ -z $args ]] && echo -e "Select a gate to install:" && read apps +[[ -z $apps ]] && echo -e "${c_red}Unknown gate \"$args\"$c_" && exit 1 -echo -e "${c_green}Good trip !$c_" +while read gate; do + if [[ "$functions" == *"$gate"* ]]; then + echo -e "${c_yellow}Installing gate $gate ...$c_" + $gate + else + errors="${c_red}Unknown gate \"$gate\"$c_" + fi +done <<<$(echo "$apps" | sed -n 1'p' | tr ',' '\n') + +if [[ $errors == 0 ]]; then + echo -e "${c_green}Good trip !$c_" +else + echo -e "${c_red}An error has occurred:$c_ \n- $errors" +fi exit 0