forked from renatosilva/pactoys
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpacboy.sh
239 lines (218 loc) · 9.47 KB
/
pacboy.sh
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
#!/bin/bash
help_and_exit() {
echo "
Pacboy 2024.05.10
Copyright (C) 2015, 2016 Renato Silva
Licensed under BSD
This is a pacman wrapper for MSYS2 which handles the package prefixes
automatically, and provides human-friendly commands for common tasks.
Usage:
$(basename "$0") [command] [arguments]
Arguments will be passed to pacman after translation:
Package name translations:
name - uses the package prefix of the current environment: ${full_package_prefix}name
name:i - translates to mingw-w64-i686-name
name:x - translates to mingw-w64-x86_64-name
name:z - translates to mingw-w64-clang-i686-name
name:c - translates to mingw-w64-clang-x86_64-name
name:u - translates to mingw-w64-ucrt-x86_64-name
name:a - translates to mingw-w64-clang-aarch64-name
name:p - means the same as \"name\"
name: - disables any translation for name
repository::name - means repository/name (the name part gets translated as above)
Commands:
sync Shorthand for --sync or --upgrade
update Shorthand for --sync --refresh --sysupgrade
refresh Shorthand for --sync --refresh
find Shorthand for --sync --search
packages Shorthand for --sync --list
files Shorthand for --query --list [--file]
info Shorthand for --query --info [--file]
origin Shorthand for --query --owns or --files
remove Shorthand for --remove --recursive
debug Verbose output for the above commands
"
exit 1
}
parse_mingw_argument() {
[[ "${command}" = sync && -n "${file_argument}" ]] && { raw_argument=(${argument}); return; }
[[ "${command}" = files && -n "${file_argument}" ]] && { raw_argument=(${argument}); return; }
[[ "${command}" = info && -n "${file_argument}" ]] && { raw_argument=(${argument}); return; }
[[ "${command}" = origin ]] && { raw_argument=(${argument}); return; }
[[ "${command}" = find ]] && { raw_argument=(${argument}); return; }
[[ "${command}" = packages ]] && { raw_argument=(${argument}); return; }
[[ "${command}" = files ]] && { raw_argument=(${full_package_prefix}${argument}); return; }
[[ "${command}" = info ]] && { raw_argument=(${full_package_prefix}${argument}); return; }
raw_argument=(${full_package_prefix}${argument})
}
realname() {
test -f "${1}" && { echo "${1}"; return; }
pacman -Q "${1}" > /dev/null 2>&1 && { echo "${1}"; return; }
pacman -Q "${1}-git" > /dev/null 2>&1 && { echo "${1}-git"; return; }
pacman -Q "${1}-svn" > /dev/null 2>&1 && { echo "${1}-svn"; return; }
pacman -Q "${1}-hg" > /dev/null 2>&1 && { echo "${1}-hg"; return; }
pacman -Q "${1}-cvs" > /dev/null 2>&1 && { echo "${1}-cvs"; return; }
pacman -Q "${1}-bzr" > /dev/null 2>&1 && { echo "${1}-bzr"; return; }
echo "${1}"
}
status() {
if [[ -t 1 ]]; then
local blue='\e[1;34m'
local white='\e[1;37m'
local normal='\e[0m'
fi
echo -e "${blue}::${white}" "${@}...${normal}"
}
warning() {
if [[ -t 1 ]]; then
local yellow='\e[1;33m'
local white='\e[1;37m'
local normal='\e[0m'
fi
echo -e "${yellow}warning:${white}" "${@}${normal}"
}
execute() {
[[ -n "${debug}" && $(type -t "${1}") != function ]] && status Executing "${@}"
if [[ -z "${exclude_lines}" ]]
then "${@}"
else "${@}" | grep --invert-match "${exclude_lines}"
fi
}
packages() {
local repository="${1}"
for package in $(pacman --sync --list --quiet ${repository}); do
case "${package}" in
mingw-w64-x86_64-*) package="${package/mingw-w64-x86_64-/}" ;;
mingw-w64-i686-*) package="${package/mingw-w64-i686-/}" ;;
mingw-w64-clang-x86_64-*) package="${package/mingw-w64-clang-x86_64-/}" ;;
mingw-w64-clang-i686-*) package="${package/mingw-w64-clang-i686-/}" ;;
mingw-w64-ucrt-x86_64-*) package="${package/mingw-w64-ucrt-x86_64-/}" ;;
mingw-w64-clang-aarch64-*) package="${package/mingw-w64-clang-aarch64-/}" ;;
*) package="${package}:"
esac
echo "${package}"
done
}
refresh_cache() {
local package="${1}"
local repositories=("${@:2}")
local repository
for file in /var/cache/${package}/*; do
test -e "${file}" || break
for repository in "${repositories[@]}"; do
[[ "${file}" =~ ^"/var/cache/${package}/${repository}." ]] && break
unset repository
done
test -z "${repository}" && rm "${file}"
done
}
refresh_database_checksum() {
local repository="${1}"
local checksum_file="/var/cache/pacboy/${repository}.checksum"
local updated_checksum=($(sha256sum "/var/lib/pacman/sync/${repository}.db"))
local current_checksum="$(cat "${checksum_file}" 2> /dev/null)"
echo "${updated_checksum}" > "${checksum_file}"
[[ "${current_checksum}" != "${updated_checksum}" ]]
}
refresh_package_names() {
local repositories=("${@}")
for repository in "${repositories[@]}"; do
if ! refresh_database_checksum "${repository}"
then echo " ${repository} is up to date"
else echo " updating ${repository}..."
packages "${repository}" | sort | uniq > "/var/cache/pacboy/${repository}.packages"
fi
done
}
refresh_databases() {
execute ${pacman} --sync --refresh "${@}" || exit
test -n "${help_tip}" && exit
local repositories=()
for database in /var/lib/pacman/sync/*.db; do
database="${database##*/}"
repositories+=("${database%.db}")
done
status 'Updating package content databases'
execute ${pacman} --files --refresh || exit
status 'Updating package name databases'
refresh_cache 'pacboy' "${repositories[@]}"
refresh_package_names "${repositories[@]}"
}
arguments=()
raw_arguments=()
pacman='pacman --color auto'
full_package_prefix="${MINGW_PACKAGE_PREFIX:+${MINGW_PACKAGE_PREFIX}-}"
test -z "${1}" && help_and_exit
for argument in "${@}"; do
case "${argument}" in
help) help_and_exit ;;
debug) debug='true'
continue ;;
esac
if [[ -n "${command}" ]]; then
arguments+=("${argument}")
continue
fi
case "${argument}" in
sync) command="${argument}"; raw_command="${pacman} --sync" ;;
update) command="${argument}"; raw_command="${pacman} --sync --sysupgrade" ;;
refresh) command="${argument}"; raw_command='refresh_databases' ;;
find) command="${argument}"; raw_command="${pacman} --sync --search" ;;
packages) command="${argument}"; raw_command="${pacman} --sync --list" ;;
files) command="${argument}"; raw_command="${pacman} --query --list" ;;
info) command="${argument}"; raw_command="${pacman} --query --info" ;;
remove) command="${argument}"; raw_command="${pacman} --remove --recursive" ;;
origin) command="${argument}"; raw_command="${pacman} --files" ;;
*) arguments+=("${argument}")
esac
done
for argument in "${arguments[@]}"; do
if [[ "${argument}" = *::* ]]; then
repository="${argument%::*}/"
argument="${argument##*::}"
fi
case "${command}" in
sync) test -f "${argument}" && { file_argument='true'; raw_command="${pacman} --upgrade"; } ;;
origin) test -f "${argument}" && { file_argument='true'; raw_command="${pacman} --query --owns"; } ;;
files) test -f "${argument}" && { file_argument='true'; raw_command="${raw_command} --file"; } ;;
info) test -f "${argument}" && { file_argument='true'; raw_command="${raw_command} --file"; } ;;
esac
case "${argument}" in
*\\*) raw_argument=("${argument}") ;;
*/*) raw_argument=("${argument}") ;;
-*) raw_argument=("${argument}") ;;
*:) raw_argument=("${argument%:}") ;;
*:i) raw_argument=(mingw-w64-i686-${argument%:i}) ;;
*:x) raw_argument=(mingw-w64-x86_64-${argument%:x}) ;;
*:m)
# deprecated
warning "'${argument}' is deprecated, use '${argument%:m}:i' and/or '${argument%:m}:x' instead"
raw_argument=(mingw-w64-x86_64-${argument%:m} mingw-w64-i686-${argument%:m})
;;
*:u) raw_argument=(mingw-w64-ucrt-x86_64-${argument%:u}) ;;
*:z) raw_argument=(mingw-w64-clang-i686-${argument%:z}) ;;
*:c) raw_argument=(mingw-w64-clang-x86_64-${argument%:c}) ;;
*:l)
# deprecated
warning "'${argument}' is deprecated, use '${argument%:l}:z' and/or '${argument%:c}:x' instead"
raw_argument=(mingw-w64-clang-x86_64-${argument%:l} mingw-w64-clang-i686-${argument%:l})
;;
*:a) raw_argument=(mingw-w64-clang-aarch64-${argument%:a}) ;;
*:p) raw_argument=(${full_package_prefix}${argument%:p}) ;;
*) parse_mingw_argument ;;
esac
[[ $argument =~ ^(-h|-[^-].*h|--help$) ]] && help_tip='true'
for raw_argument in "${raw_argument[@]}"; do
[[ "${command}" =~ ^files|info|remove$ ]] && raw_argument=$(realname "${raw_argument}")
raw_arguments+=("${repository}${raw_argument}")
done
unset file_argument
unset repository
done
case "${command}" in
update) test -z "${help_tip}" && refresh_databases ;;
files) exclude_lines='/$' ;;
esac
test -n "${help_tip}" && echo "did you mean '$(basename "$0") help'?"
test -z "${raw_command}" && raw_command="${pacman}"
execute ${raw_command} "${raw_arguments[@]}"