-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdlib.bash
More file actions
112 lines (93 loc) · 2.51 KB
/
stdlib.bash
File metadata and controls
112 lines (93 loc) · 2.51 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
db_github_latest() {
curl -fsSL "https://api.github.com/repos/$1/releases/latest" | jq -r .tag_name | sed 's/^v//'
}
db_gitlab_latest() {
curl -fsSL "https://${2:-gitlab.com}/api/v4/projects/${1/\//%2F}/releases/" | jq '.[0].tag_name' -r | sed 's/^v//'
}
db_sourcehut_latest() {
# This should be replaced with something less shitty
curl -fsSL "https://git.sr.ht/~$1/refs" | grep -E 'href="[^"]+/archive/[^"]+\.tar\.gz"' | grep -Eo '[0-9.]+[0-9]' | head -n1
}
db_gitlab_tags() {
curl -fsSL "https://${2:-gitlab.com}/api/v4/projects/${1/\//%2F}/repository/tags" | jq '.[].name' -r | sort -V
}
db_pypi_latest() {
curl -fsSL "https://pypi.org/pypi/$1/json" | jq .info.version -r
}
db_npm_latest() {
curl -fsSL "https://registry.npmjs.org/$1" | jq '.["dist-tags"].latest' -r
}
db_rebase_symlink() {
for arg; do
local target="$(readlink "${arg}")"
ln -sfT "${target#${pkg}}" "${arg}"
done
}
db_strip_file() {
sed -Ei "s|${pkg}||g" "$@"
}
# deprecated
db_python_bin_script() {
db_python_bin_script_via_syspath "$@"
}
db_python_bin_script_via_envvar() {
(
set +x
dist="$(cd "${pkg}"; ls -d "${1#/}/local/lib"/python*/dist-packages)"
cat <<EOF
#!/usr/bin/env bash
export PYTHONPATH="/${dist}"
$(cat)
exec "${1}/local/bin/${2}" "\$@"
EOF
)
}
db_python_bin_script_via_syspath() {
(
set +x
dist="$(cd "${pkg}"; ls -d "${1#/}/local/lib"/python*/dist-packages)"
launcher="$(cd "${pkg}"; grep < ${1#/}/local/bin/$2 -Ev '^#|\.exe')"
cat <<EOF
#!/usr/bin/env python3
import sys
sys.path.insert(0, "/${dist}")
$(cat)
${launcher}
EOF
)
}
db_node_bin_script() {
(
set +x
module="$(cd "${pkg}/${1#/}/lib/node_modules"; ls)"
spec="${1#/}/lib/node_modules/${module}/package.json"
query='.bin | if type == "object" then .[$name] else . end'
main="$(cd "${pkg}"; jq < "${spec}" "${query}" --arg name "$2" -r)"
cat <<EOF
#!/usr/bin/env bash
exec node $1/lib/node_modules/${module}/${main} "\$@"
EOF
)
}
# There is also a copy of this in debbie.bash
db_sponge() {
"$@" | (
sponge || status="$?"
case "${status:-0}" in
0) ;;
141) ;;
*) exit "${status}"
esac
)
}
db_parse_depends() {
sed -E 's/^[^ ]+: ?//' | grep -Eo '(,|^) ?[^, :]+' | tr -d ', '
}
db_nuke() {
rm -rf "$@" 2>/dev/null || (
chmod -R u+rwx "$@" 2>/dev/null ||:
rm -rf "$@"
)
}
osrel="$(lsb_release -cs)"
osnum="$(lsb_release -rs)"