-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall
executable file
·250 lines (219 loc) · 7.47 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/env bash
# Dayz CTL Install script
# Copyright 2022 WoozyMasta <[email protected]>
# Licensed under the Apache License, Version 2.0
set -euo pipefail
: "${HOME:=${XDG_DATA_HOME:-$HOME}}"
: "${DAYZ_CTL_VERSION:=master}"
: "${DAYZ_CTL_DIR:=$HOME/.local/share/dayz-ctl}"
: "${DAYZ_CTL_BIN_DIR:=$HOME/.local/share/dayz-ctl/bin}"
: "${USER_APPLICATIONS_DIR:=$HOME/.local/share/applications}"
: "${USER_ICONS_DIR:=$HOME/.local/share/icons}"
: "${USER_DOCK_DIR:=$HOME/.config/plank/dock1/launchers}"
: "${TEST_MODE:=false}"
jq_version='1.6'
fzf_version='0.34.0'
gum_version='0.7.0'
raw_url=https://raw.githubusercontent.com/WoozyMasta/dayz-ctl
packages_data_fresh=0
declare -a installed_packages=()
declare -A package_manageers=(
[apt]=/etc/apt/sources.list
[yum]=/etc/yum.conf
[dnf]=/etc/dnf/dnf.conf
[pacman]=/etc/pacman.conf
[apk]=/etc/apk/repositories
[zypper]=/etc/zypp/zypper.conf
)
declare -A packages=(
[tput]=ncurses
[tar]=tar
[gzip]=gzip
[who]=coreutils # missed who, logname or chcon is inidicate coreutils not installed
[bash]=bash
[ping]=iputils-ping
[geoiplookup]=geoip
[whois]=whois
[curl]=curl
[grep]=grep
[awk]=gawk
[xdg-open]=xdg-utils
)
fail() {
>&2 printf '\e[1;31mERROR:\e[0m %s\n' "$*"
exit 1
}
ghInstall() {
local cmd=$1 author=$2 file=$3
local project="https://github.com/$author/$cmd"
local release_url="$project/releases/download/$file"
if ! command -v "$cmd" &>/dev/null; then
printf '%s\t(%s)\n' "Install: $cmd" "$project"
if [[ "$file" == *.gz ]]; then
tempfile=$(mktemp "$cmd.tmp.XXXXXXXX")
trap 'rm -rf -- "$tempfile"' EXIT
curl -#fLo "$tempfile" "$release_url"|| \
fail "Can't download $cmd from $project"
tar fxz "$tempfile" -C "$bin_path" "$cmd"
rm -rf -- "$tempfile"
else
curl -#fLo "$bin_path/$cmd" "$release_url"
fi
chmod +x "$bin_path/$cmd"
installed_packages+=("$cmd")
fi
}
# Create fake steam for test
if [ "${TEST_MODE,,}" = true ]; then
# shellcheck disable=SC2016
printf '%s\n' '#!/usr/bin/env bash' \
'printf '\''Steam: %s\n'\'' "${@}"' > /bin/steam
chmod +x /bin/steam
mkdir -p "$HOME/.steam/steam/steamapps/common/DayZ"
fi
# Create working dir
mkdir -p "$DAYZ_CTL_DIR"
# Set bin install path
if [ "$EUID" -eq 0 ]; then
USER_APPLICATIONS_DIR=/usr/share/applications
USER_ICONS_DIR=/usr/share/icons
if [ -d '/usr/bin' ]; then
bin_path='/usr/bin'
else
bin_path='/bin'
fi
steamcmd_path="/usr/share/steamcmd"
else
if [ -d "$HOME/.local/bin" ]; then
bin_path="$HOME/.local/bin"
else
bin_path="$DAYZ_CTL_BIN_DIR"
mkdir -p "$DAYZ_CTL_BIN_DIR"
fi
steamcmd_path="$DAYZ_CTL_DIR/steamcmd"
package_su="sudo"
fi
# Set right path for alredy present dayz-ctl bin
dayz_bin_path=$(command -v dayz-ctl 2>/dev/null) || dayz_bin_path="$bin_path"
# Set package manager command for install
for manger in "${!package_manageers[@]}"; do
[ ! -f "${package_manageers[$manger]}" ] && continue
case $manger in
'apt')
package_update="${package_su:-} apt update"
package_manager="${package_su:-} apt install -y"
packages[geoiplookup]=geoip-bin;;
'yum'|'dnf')
package_update="${package_su:-} $manger makecache"
package_manager="${package_su:-} $manger install -y"
packages[ping]=iputils;;
'pacman')
package_manager="${package_su:-} pacman -S --noconfirm";;
'apk')
package_manager="${package_su:-} apk add";;
'zypper')
package_manager="${package_su:-} zypper -n install"
packages[geoiplookup]=GeoIP
packages[ping]=iputils;;
esac
done
# Check Steam installed
if ! command -v steam &>/dev/null && [ "${TEST_MODE,,}" = false ]; then
printf '%s\t(%s)\n' 'Install: Steam' 'https://store.steampowered.com'
[ "${packages_data_fresh:=0}" -eq 0 ] &&
${package_update:-:} && ((packages_data_fresh+=1))
$package_manager steam ||
fail 'Steam not installed, install it first please' \
'https://store.steampowered.com/about/'
installed_packages+=(steam)
fi
# Install not exists tools with package manager
for pkg in "${!packages[@]}"; do
command -v "$pkg" &>/dev/null && continue
echo "Install $pkg"
[ -z "${package_manager:-}" ] &&
echo "Cant't install $pkg" &&
fail "Failed to determine the package manager for your distribution," \
"please install these utilities yourself and run the installer again:" \
"${!packages[@]}"
[ "$EUID" -ne 0 ] &&
! command -v sudo &>/dev/null && fail "Please run as root"
[ "${packages_data_fresh:=0}" -eq 0 ] && ${package_update:-:}
((packages_data_fresh+=1))
$package_manager "${packages[$pkg]}"
installed_packages+=("${packages[$pkg]}")
done
# Install steamcmd
if ! command -v steamcmd &>/dev/null; then
printf '%s\t(%s)\n' 'Install: SteamCMD' \
'https://developer.valvesoftware.com/wiki/SteamCMD'
mkdir -p "$steamcmd_path"
tempfile=$(mktemp "steamcmd.tar.gz.tmp.XXXXXXXX")
trap 'rm -rf -- "$tempfile"' EXIT
curl -#fLo "$tempfile" \
http://media.steampowered.com/client/installer/steamcmd_linux.tar.gz
tar fxz "$tempfile" -C "$steamcmd_path"
rm -rf -- "$tempfile"
printf '%s\n' \
'#!/usr/bin/env bash' \
"export LD_LIBRARY_PATH=\"$steamcmd_path/linux32:${LD_LIBRARY_PATH:-}\"" \
"exec \"$steamcmd_path/linux32/steamcmd\" \"\$@\"" > \
"$bin_path/steamcmd"
chmod +x "$bin_path/steamcmd"
"$bin_path/steamcmd" +@ShutdownOnFailedCommand 1 +quit || steamcmd_rc=$?
if [ "$steamcmd_rc" -ne 42 ]; then
rm -r -- "$bin_path/steamcmd" "$steamcmd_path"
fail 'There is something wrong with SteamCMD installation,' \
'try installing it yourself:' \
'https://developer.valvesoftware.com/wiki/SteamCMD'
fi
installed_packages+=(steamcmd)
fi
# Install jq
ghInstall jq stedolan jq-$jq_version/jq-linux64
# Install fzf
ghInstall fzf junegunn $fzf_version/fzf-$fzf_version-linux_amd64.tar.gz
# Install gum
ghInstall gum charmbracelet v$gum_version/gum_${gum_version}_linux_x86_64.tar.gz
# Install dayz-ctl
printf '%s\t(%s)\n' 'Install: Dayz CTL' 'https://github.com/WoozyMasta/dayz-ctl'
curl -#fLo "${dayz_bin_path%/*}/dayz-ctl" \
"$raw_url/$DAYZ_CTL_VERSION/dayz-ctl" ||
fail "Can't download dayz-ctl from https://github.com/WoozyMasta/dayz-ctl"
chmod +x "${dayz_bin_path%/*}/dayz-ctl"
installed_packages+=(dayz-ctl)
# Check dayz-ctl installed success
if ! command -v dayz-ctl &>/dev/null; then
printf '%s\n\t%s\n' \
"Create a symlink for the executable file, need superuser rights" \
"ln -s \"$bin_path/dayz-ctl\" /usr/bin/dayz-ctl"
$package_su ln -s "$bin_path/dayz-ctl" /usr/bin/dayz-ctl
fi
# Create desktop entry
if [ -d "$USER_APPLICATIONS_DIR" ]; then
[ -d "$USER_ICONS_DIR" ] &&
icon_path="$USER_ICONS_DIR/dayz-ctl.svg" && icon=dayz-ctl
curl -sSfLo "${icon_path:-$bin_path/dayz-ctl.svg}" \
"$raw_url/$DAYZ_CTL_VERSION/extra/dayz-ctl.svg" ||
fail "Can't download dayz-ctl from https://github.com/WoozyMasta/dayz-ctl"
printf '%s\n' \
'[Desktop Entry]' \
'Name=DayZ Command Line Launcher' \
'Comment=dayz-ctl - DayZ Command Line Launcher' \
"Exec=$bin_path/dayz-ctl" \
"Icon=${icon:-$bin_path/dayz-ctl.svg}" \
'Terminal=true' \
'Type=Application' \
'Categories=Game;' > \
"$USER_APPLICATIONS_DIR/dayz-ctl.desktop"
# Add plank dock launch
if [ -d "$USER_DOCK_DIR" ]; then
printf '%s\n' \
'[PlankDockItemPreferences]' \
"Launcher=file://$USER_APPLICATIONS_DIR/dayz-ctl.desktop" > \
"$USER_DOCK_DIR/dayz-ctl.dockitem"
fi
fi
echo "Installed: ${installed_packages[*]}"
echo Done
exec "$bin_path/dayz-ctl"