-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-outdated.sh
More file actions
executable file
·167 lines (151 loc) · 4.08 KB
/
make-outdated.sh
File metadata and controls
executable file
·167 lines (151 loc) · 4.08 KB
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
#!/bin/bash
set -eo pipefail
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
list_installables() {
if [ -f "${script_dir}/installables/yoink.sh" ]; then
printf '%s\n' "${script_dir}/installables/yoink.sh"
fi
if [ -f "${script_dir}/installables/deno.sh" ]; then
printf '%s\n' "${script_dir}/installables/deno.sh"
fi
if [ -f "${script_dir}/installables/uv.sh" ]; then
printf '%s\n' "${script_dir}/installables/uv.sh"
fi
for x in "${script_dir}"/installables/*.sh; do
if ! [ -e "${x}" ]; then
continue
fi
case "$(basename "${x}")" in
yoink.sh|deno.sh|uv.sh)
continue
;;
esac
printf '%s\n' "${x}"
done
}
emit_version_function() {
local name="$1"
local file="$2"
printf '\n%s() {\n' "$name"
/usr/bin/awk '
NR == 1 && /^#!/ { next }
/^set -euo pipefail$/ { next }
/^script_path=/ { next }
/^script_dir=/ { next }
/script_dir/ { next }
{
sub(/exit /, "return ")
if ($0 == "") { print ""; next }
print $0
}
' "$file"
printf '}\n'
}
emit_installable_function() {
local name="$1"
local file="$2"
printf '\n%s() {\n' "$name"
printf ' version="$1"\n'
/usr/bin/awk '
NR == 1 && /^#!/ { next }
/^set -euo pipefail$/ { next }
/^script_path=/ { next }
/^script_dir=/ { next }
/^outdated_script=/ { next }
/^if ! version=/ { skipping = 1; next }
/^version=/ {
skipping_version = 1
if ($0 ~ /\)"$/) { skipping_version = 0 }
next
}
skipping {
if ($0 ~ /^fi$/) { skipping = 0 }
next
}
skipping_version {
if ($0 ~ /\)"$/) { skipping_version = 0 }
next
}
{
sub(/exit /, "return ")
if ($0 == "") { print ""; next }
print $0
}
' "$file"
printf '}\n'
}
emit_installable_target_matcher() {
printf '\nis_known_install_target() {\n'
printf ' case "$1" in\n'
while IFS= read -r installable; do
if [ -z "${installable}" ]; then
continue
fi
name="$(basename "${installable%.*}")"
printf ' %s)\n' "${name}"
printf ' return 0\n'
printf ' ;;\n'
done < <(list_installables)
printf ' *)\n'
printf ' return 1\n'
printf ' ;;\n'
printf ' esac\n'
printf '}\n'
}
cat "${script_dir}/outdated.sh.in"
printf '\n'
while IFS= read -r installable; do
name="$(basename "${installable%.*}")"
emit_installable_function "install_${name}" "${installable}"
done < <(list_installables)
emit_installable_target_matcher
while IFS= read -r installable; do
name="$(basename "${installable%.*}")"
emit_version_function "current_version_${name}" \
"${script_dir}/current-version/${name}.sh"
emit_version_function "latest_version_${name}" \
"${script_dir}/latest-version/${name}.sh"
printf '\noutdated_%s() {\n' "${name}"
if [ "${name}" = "yoink" ]; then
printf ' if ! [ -x /usr/local/bin/yoink ]; then\n'
printf ' printf '\''%%s\\n'\'' "latest"\n'
printf ' return 0\n'
printf ' fi\n'
fi
printf ' latest="$(latest_version_%s)" || return 1\n' "${name}"
printf ' current="$(current_version_%s || true)"\n' "${name}"
printf ' if [ -z "${current}" ]; then\n'
printf ' printf '\''%%s\\n'\'' "${latest}"\n'
printf ' return 0\n'
printf ' fi\n'
printf ' if cargox semverator lt "${current}" "${latest}" >/dev/null 2>&1; then\n'
printf ' printf '\''%%s\\n'\'' "${latest}"\n'
printf ' return 0\n'
printf ' fi\n'
printf ' return 1\n'
printf '}\n'
done < <(list_installables)
printf '\nif [ "${OUTDATED_BOOTSTRAP_ONLY:-0}" -ne 1 ]; then\n'
while IFS= read -r installable; do
name="$(basename "${installable%.*}")"
printf '\nif version="$(run_step_capture "Checking %s" outdated_%s)"; then\n' \
"${name}" "${name}"
printf ' queue_install "%s" "${version}"\n' "${name}"
printf 'fi\n'
done < <(list_installables)
printf '\n emit_plan\n'
printf 'fi\n'
printf '}\n\n'
cat <<'EOF'
if [ "${1:-}" = "--internal-run" ]; then
shift
run_internal "$@"
elif [ "${1:-}" = "--apply" ]; then
shift
OUTDATED_BOOTSTRAP_ONLY=1
run_outdated >/dev/null
run_apply "$@"
else
run_outdated "$@"
fi
EOF