diff --git a/run.sh b/run.sh old mode 100644 new mode 100755 index 2f22b10a..36fb4929 --- a/run.sh +++ b/run.sh @@ -1,58 +1,55 @@ -#!/bin/bash +#!/bin/sh # # About: Build OpenDiablo 2 automatically # Author: liberodark # License: GNU GPLv3 +set -eu -version="0.0.1" +version="0.0.2" echo "OpenDiablo 2 Build Script $version" - #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST AND VAR #================================================= -distribution=$(cat /etc/*release | grep "PRETTY_NAME" | sed 's/PRETTY_NAME=//g' | sed 's/["]//g' | awk '{print $1}') +distro=$(sed -n 's#PRETTY_NAME="\([^"]*\)"#\1#p' /etc/os-release) -compile_od2(){ - echo "Build OpenDiablo 2" - go get - go build - chmod +x OpenDiablo2 - echo "Build finished. Please edit config.json before running OpenDiablo2" - } +# Check OS & go -go_run(){ -echo "Install Go for OpenDiablo 2 ($distribution)" +if ! command -v go >/dev/null +then + echo "Install Go for OpenDiablo 2 ($distro)? y/n" + read -r choice + [ "$choice" != y ] && [ "$choice" != Y ] && exit - # Check OS & go - - if ! command -v go &> /dev/null; then - - if [[ "$distribution" = CentOS || "$distribution" = CentOS || "$distribution" = Red\ Hat || "$distribution" = Suse || "$distribution" = Oracle ]]; then - sudo yum install -y go &> /dev/null - - compile_od2 || exit - - elif [[ "$distribution" = Fedora ]]; then - sudo dnf install -y go &> /dev/null - - compile_od2 || exit - - elif [[ "$distribution" = Debian || "$distribution" = Ubuntu || "$distribution" = Deepin ]]; then - sudo apt-get update &> /dev/null - sudo apt-get install -y go --force-yes &> /dev/null - - compile_od2 || exit - - elif [[ "$distribution" = Manjaro || "$distribution" = Arch\ Linux ]]; then - sudo pacman -S go --noconfirm &> /dev/null - - compile_od2 || exit - - fi + case "$(echo "$distro" | tr '[:upper:]' '[:lower:]')" in + centos|red\ hat|suse|oracle) + sudo yum install -y go >/dev/null 2>&1 + ;; + fedora) + sudo dnf install -y go >/dev/null 2>&1 + ;; + debian|ubuntu|deepin) + sudo apt-get update >/dev/null 2>&1 + sudo apt-get install -y go --force-yes >/dev/null 2>&1 + ;; + manjaro|arch\ linux) + sudo pacman -S go --noconfirm >/dev/null 2>&1 + ;; + gentoo/linux) + sudo emerge --ask n go /dev/null 2>&1 + ;; + *) + echo "$distro: unsupported distribution, please install Go by yourself" + exit 1 + ;; + esac fi -} -go_run +# Build +echo "Build OpenDiablo 2" +go get +go build +chmod u+x OpenDiablo2 +echo "Build finished. Please edit config.json before running OpenDiablo2"