-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathomelet
executable file
·123 lines (105 loc) · 3.25 KB
/
omelet
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
#!/bin/sh
# A manager for Glorious-Eggroll's custom proton versions
# https://github.com/GloriousEggroll/proton-ge-custom/tags
ERR_MISSING_DEP=11
ERR_BAD_USAGE=12
ERR_BROKEN_DOWNLOAD=13
ERR_TAG_ALREADY_PRESENT=14
ERR_TAG_NOT_FOUND=15
_myname="$(basename "$0")"
__usage () {
cat << EOH
$0 get [latest|<version>]
$0 list [-l]
Manage Glorious-Eggroll's custom proton versions.
- get: download and extirp a version to the right location(s)
'latest' is an alias to the most recent release name in the list of published
releases
- list: get a list of available versions.
-l: only locally available versions
EOH
}
__req () {
command -v "$1" >/dev/null 2>&1
}
__err () {
echo "$@" >&2
}
__die () {
__err "$1"
exit "${2:-10}"
}
for _dep in curl jq bsdtar; do
__req "$_dep" || __die "missing $_dep" $ERR_MISSING_DEP
done
if [ -z "$OMELET_DEST" ]; then
for _dest in \
~/.var/app/com.valvesoftware.Steam/.local/share/Steam/compatibilitytools.d \
; do
[ -d "$_dest" ] && OMELET_DEST="$_dest"
done
fi
## TODO: only create tmpdir if needed
_tmpdir="$(mktemp -d -t "$_myname.XXXXXX")"
__cleanup () {
[ -d "$_tmpdir" ] && rm -r "$_tmpdir"
}
trap __cleanup INT TERM
__get_releases () {
curl --location \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--output versions.json \
https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases
}
__do_get () {
cd "$_tmpdir"
[ -r versions.json ] || __get_releases
case "$1" in
latest)
# I didn't write that jq(1) code. Don't ask.
jq -r '.[] | [.published_at, .tag_name] | join(",")' < versions.json |
sort |
tail -n 1 |
# we get a single line of sorted releases (the latest one)
while IFS=',' read -r _date _tag; do
__do_get "$_tag"
done
;;
*)
_tag="$1"
# bail if we already have a matching release in the
# compatibilitytools.d dir.
if [ -d "$OMELET_DEST/$_tag" ]; then
__die "$OMELET_DEST/$_tag already exists, nothing to do" $ERR_TAG_ALREADY_PRESENT
fi
if [ "$(jq -r --arg _tag "$_tag" '.[]|select(.tag_name == $_tag ).assets[]' < versions.json | wc -l)" -lt 1 ]; then
__die "Couldn't find any release named '$_tag' (it might just be too old and $0 can't deal with it)." $ERR_TAG_NOT_FOUND
fi
jq -r --arg _tag "$_tag" '.[]|select(.tag_name == $_tag ).assets[]| [.browser_download_url, .name] | join(",")' < versions.json |
while IFS=',' read -r _url _name; do
# we download the assets for that release
curl --location --output "$_name" "$_url"
done
find . -iname '*.sha*sum' |
while IFS= read -r _f; do
# shasum checks never hurt
case "$_f" in
*.sha512sum) sha512sum -c "$_f" || __die "broken download" $ERR_BROKEN_DOWNLOAD ;;
*.sha256sum) sha256sum -c "$_f" || __die "broken download" $ERR_BROKEN_DOWNLOAD ;;
esac
done
find . -iname '*.tar.gz' |
while IFS= read -r _archive; do
bsdtar xvf "$_archive" -C "$OMELET_DEST"
done
;;
esac
}
case "$1" in
get) shift; __do_get "$@" ;;
list) shift; __do_list "$@" ;;
-h|help) __usage ; exit 0;;
*) __die "$(__usage)" $ERR_BAD_USAGE ;;
esac
__cleanup