Skip to content

Commit

Permalink
Add shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
klightspeed committed Aug 9, 2022
1 parent 6e2c925 commit 5ca9446
Show file tree
Hide file tree
Showing 9 changed files with 504 additions and 44 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: ShellCheck

on: [push]

jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
severity: warning
env:
SHELLCHECK_OPTS: --norc --external-sources --source-path=SCRIPTDIR

24 changes: 12 additions & 12 deletions netinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ steamcmd_user="$1"
shift

args=()
output=/dev/null
unstable=
userinstall=
userinstall2=
installservice=

for arg in "$@"; do
case "$arg" in
--verbose) output=/dev/fd/1; ;;
--output=*) output="${arg#--output=}"; ;;
--unstable) unstable=1; ;;
--repo=*) arkstGithubRepo="${arg#--repo=}"; ;;
--perform-user-install) userinstall2=yes; ;;
--yes-i-really-want-to-perform-a-user-install) userinstall=yes; ;;
*)
if [[ -n "$channel" || "$arg" == --* ]]; then
args+="$arg"
args+=("$arg")
else
channel="$arg"
fi
Expand Down Expand Up @@ -57,15 +53,20 @@ elif [[ "$steamcmd_user" == "--me" ]]; then
echo "You have been warned."
fi

function die(){
echo "$@" >&2
exit
}

function doInstallFromCommit(){
local commit="$1"
shift
tmpdir="$(mktemp -t -d "ark-server-tools-XXXXXXXX")"
if [ -z "$tmpdir" ]; then echo "Unable to create temporary directory"; exit 1; fi
cd "$tmpdir"
cd "$tmpdir" || die "Unable to change to temporary directory"
echo "Downloading installer"
curl -s -L "https://github.com/${arkstGithubRepo}/archive/${commit}.tar.gz" | tar -xz
cd "ark-server-tools-${commit}/tools"
cd "ark-server-tools-${commit}/tools" || die "Unable to change to extracted directory"
if [ ! -f "install.sh" ]; then echo "install.sh not found in $PWD"; exit 1; fi
sed -i -e "s|^arkstCommit='.*'|arkstCommit='${commit}'|" \
-e "s|^arkstTag='.*'|arkstTag='${tagname}'|" \
Expand All @@ -86,20 +87,19 @@ function doInstallFromCommit(){

function doInstallFromRelease(){
local tagname=
local desc=

echo "Getting latest release..."
# Read the variables from github
while IFS=$'\t' read n v; do
while IFS=$'\t' read -r n v; do
case "${n}" in
tag_name) tagname="${v}"; ;;
body) desc="${v}"
esac
done < <(curl -s "https://api.github.com/repos/${arkstGithubRepo}/releases/latest" | sed -n 's/^ "\([^"]*\)": "*\([^"]*\)"*,*/\1\t\2/p')

if [ -n "$tagname" ]; then
echo "Latest release is ${tagname}"
echo "Getting commit for latest release..."
# shellcheck disable=SC2155
local commit="$(curl -s "https://api.github.com/repos/${arkstGithubRepo}/git/refs/tags/${tagname}" | sed -n 's/^ *"sha": "\(.*\)",.*/\1/p')"
doInstallFromCommit "$commit" "$@"
else
Expand All @@ -111,7 +111,7 @@ function doInstallFromRelease(){
function doInstallFromBranch(){
channel="$1"
shift
commit="`curl -s "https://api.github.com/repos/${arkstGithubRepo}/git/refs/heads/${channel}" | sed -n 's/^ *"sha": "\(.*\)",.*/\1/p'`"
commit="$(curl -s "https://api.github.com/repos/${arkstGithubRepo}/git/refs/heads/${channel}" | sed -n 's/^ *"sha": "\(.*\)",.*/\1/p')"

if [ -z "$commit" ]; then
if [ -n "$unstable" ]; then
Expand All @@ -126,7 +126,7 @@ function doInstallFromBranch(){
}

# Download and untar installation files
cd "$TEMP"
cd "$TEMP" || die "Unable to change to temporary directory"

if [ "$channel" = "master" ] && [ -z "$unstable" ]; then
doInstallFromRelease "${args[@]}"
Expand Down
Loading

0 comments on commit 5ca9446

Please sign in to comment.