1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-30 02:55:23 +00:00

Improve run.sh: (#129)

* POSIX sh
* simpler distro detection
* don't create functions for stuff used only once
* add Gentoo (portage) support
* handle other distros gracefully
* ask before stealthily installing Go
* compile even when Go is already installed
This commit is contained in:
q3cpma 2019-11-10 13:47:55 +01:00 committed by Tim Sarbin
parent b41f7f4dab
commit 7370e12b53

79
run.sh Normal file → Executable file
View File

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