firefox: add pgo build option
[void-pkg.git] / common / environment / setup / install.sh
blobc82add219d33428207ace79b15cd01cb2746f091
1 # -*-* shell *-*-
3 # enable aliases
4 shopt -s expand_aliases
6 # clear all aliases
7 unalias -a
9 # disable wildcards helper
10 _noglob_helper() {
11 set +f
12 IFS= "$@"
15 # Apply _noglob to v* commands
16 for cmd in vinstall vcopy vcompletion vmove vmkdir vbin vman vdoc vconf vsconf vlicense vsv; do
17 # intentionally expanded when defined
18 # shellcheck disable=SC2139
19 alias ${cmd}="set -f; _noglob_helper _${cmd}"
20 done
22 _vsv() {
23 local service="$1"
24 local facility="${2:-daemon}"
25 local LN_OPTS="-s"
26 local svdir="${PKGDESTDIR}/etc/sv/${service}"
28 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
29 # pkgver is defined in common/xbps-src/shutils/commmon.sh
30 # shellcheck disable=SC2154
31 msg_red "$pkgver: vsv: up to 2 arguments expected: <service> [<log facility>]\n"
32 return 1
35 if [ -n "$XBPS_BUILD_FORCEMODE" ]; then
36 LN_OPTS+="f"
39 vmkdir etc/sv
40 vcopy "${FILESDIR}/$service" etc/sv
41 grep -Fq 'exec 2>&1' "$svdir/run" || msg_warn "$pkgver: vsv: service '$service' does not contain 'exec 2>&1' to log stderr\n"
42 for f in run finish check control/{a,c,d,h,i,k,p,q,t,u,x,1,2}; do
43 [ -e "$svdir/$f" ] && [ ! -L "$svdir/$f" ] && chmod 755 "$svdir/$f"
44 done
45 ln ${LN_OPTS} "/run/runit/supervise.${service}" "$svdir/supervise"
46 if [ -d "$svdir/log" ] || [ -L "$svdir/log" ]; then
47 msg_warn "$pkgver: vsv: overriding default log service\n"
48 else
49 mkdir "$svdir/log"
50 cat <<-EOF > "$svdir/log/run"
51 #!/bin/sh
52 exec vlogger -t $service -p $facility
53 EOF
55 ln ${LN_OPTS} "/run/runit/supervise.${service}-log" "$svdir/log/supervise"
56 if [ -e "$svdir/log/run" ] && [ ! -L "$svdir/log/run" ]; then
57 chmod 755 "${PKGDESTDIR}/etc/sv/${service}/log/run"
61 _vbin() {
62 local file="$1" targetfile="$2"
64 if [ $# -lt 1 ]; then
65 msg_red "$pkgver: vbin: 1 argument expected: <file>\n"
66 return 1
69 vinstall "$file" 755 usr/bin "$targetfile"
72 _vman() {
73 local file="$1" target="${2:-${1##*/}}"
75 if [ $# -lt 1 ]; then
76 msg_red "$pkgver: vman: 1 argument expected: <file>\n"
77 return 1
80 suffix=${target##*.}
82 if [[ $suffix == gz ]]
83 then
84 gunzip "$file"
85 file="${file:0:-3}"
86 target="${target:0:-3}"
87 suffix=${target##*.}
90 if [[ $suffix == bz2 ]]
91 then
92 bunzip2 "$file"
93 file="${file:0:-4}"
94 target="${target:0:-4}"
95 suffix=${target##*.}
98 if [[ $target =~ (.*)\.([a-z][a-z](_[A-Z][A-Z])?(\.[^.]+)?)\.(.*) ]]
99 then
100 name=${BASH_REMATCH[1]}.${BASH_REMATCH[5]}
101 mandir=${BASH_REMATCH[2]}/man${suffix:0:1}
102 else
103 name=$target
104 mandir=man${suffix:0:1}
107 if [[ ${mandir} == *man[0-9n] ]] ; then
108 vinstall "$file" 644 "usr/share/man/${mandir}" "$name"
109 return 0
112 msg_red "$pkgver: vman: Filename '${target}' does not look like a man page\n"
113 return 1
116 _vdoc() {
117 local file="$1" targetfile="$2"
119 if [ $# -lt 1 ]; then
120 msg_red "$pkgver: vdoc: 1 argument expected: <file>\n"
121 return 1
124 # pkgname is defined in the package
125 # shellcheck disable=SC2154
126 vinstall "$file" 644 "usr/share/doc/${pkgname}" "$targetfile"
129 _vconf() {
130 local file="$1" targetfile="$2"
132 if [ $# -lt 1 ]; then
133 msg_red "$pkgver: vconf: 1 argument expected: <file>\n"
134 return 1
137 vinstall "$file" 644 etc "$targetfile"
140 _vsconf() {
141 local file="$1" targetfile="$2"
143 if [ $# -lt 1 ]; then
144 msg_red "$pkgver: vsconf: 1 argument expected: <file>\n"
145 return 1
148 vinstall "$file" 644 "usr/share/examples/${pkgname}" "$targetfile"
151 _vlicense() {
152 local file="$1" targetfile="$2"
154 if [ $# -lt 1 ]; then
155 msg_red "$pkgver: vlicense: 1 argument expected: <file>\n"
156 return 1
159 vinstall "$file" 644 "usr/share/licenses/${pkgname}" "$targetfile"
162 _vinstall() {
163 local file="$1" mode="$2" targetdir="$3" targetfile="$4"
165 if [ -z "$PKGDESTDIR" ]; then
166 msg_red "$pkgver: vinstall: PKGDESTDIR unset, can't continue...\n"
167 return 1
170 if [ $# -lt 3 ]; then
171 msg_red "$pkgver: vinstall: 3 arguments expected: <file> <mode> <target-directory>\n"
172 return 1
175 if [ ! -r "${file}" ]; then
176 msg_red "$pkgver: vinstall: cannot find '$file'...\n"
177 return 1
180 if [ -z "$targetfile" ]; then
181 install -Dm"${mode}" "${file}" "${PKGDESTDIR}/${targetdir}/${file##*/}"
182 else
183 install -Dm"${mode}" "${file}" "${PKGDESTDIR}/${targetdir}/${targetfile##*/}"
187 _vcopy() {
188 local files="$1" targetdir="$2"
190 if [ -z "$PKGDESTDIR" ]; then
191 msg_red "$pkgver: vcopy: PKGDESTDIR unset, can't continue...\n"
192 return 1
194 if [ $# -ne 2 ]; then
195 msg_red "$pkgver: vcopy: 2 arguments expected: <files> <target-directory>\n"
196 return 1
199 # intentionally unquoted for globbing
200 # shellcheck disable=SC2086
201 cp -a $files "${PKGDESTDIR}/${targetdir}"
204 _vmove() {
205 local f files="$1" _targetdir
207 if [ -z "$DESTDIR" ]; then
208 msg_red "$pkgver: vmove: DESTDIR unset, can't continue...\n"
209 return 1
210 elif [ -z "$PKGDESTDIR" ]; then
211 msg_red "$pkgver: vmove: PKGDESTDIR unset, can't continue...\n"
212 return 1
213 elif [ "$DESTDIR" = "$PKGDESTDIR" ]; then
214 msg_red "$pkgver: vmove is intended to be used in pkg_install\n"
215 return 1
217 if [ $# -ne 1 ]; then
218 msg_red "$pkgver: vmove: 1 argument expected: <files>\n"
219 return 1
221 for f in ${files}; do
222 _targetdir=${f%/*}/
223 break
224 done
226 if [ -z "${_targetdir}" ]; then
227 [ ! -d "${PKGDESTDIR}" ] && install -d "${PKGDESTDIR}"
228 # intentionally unquoted for globbing
229 # shellcheck disable=SC2086
230 mv "${DESTDIR}"/$files "${PKGDESTDIR}"
231 else
232 if [ ! -d "${PKGDESTDIR}/${_targetdir}" ]; then
233 install -d "${PKGDESTDIR}/${_targetdir}"
235 # intentionally unquoted for globbing
236 # shellcheck disable=SC2086
237 mv "${DESTDIR}"/$files "${PKGDESTDIR}/${_targetdir}"
241 _vmkdir() {
242 local dir="$1" mode="$2"
244 if [ -z "$PKGDESTDIR" ]; then
245 msg_red "$pkgver: vmkdir: PKGDESTDIR unset, can't continue...\n"
246 return 1
249 if [ -z "$dir" ]; then
250 msg_red "vmkdir: directory argument unset.\n"
251 return 1
254 if [ -z "$mode" ]; then
255 install -d "${PKGDESTDIR}/${dir}"
256 else
257 install -dm"${mode}" "${PKGDESTDIR}/${dir}"
261 _vcompletion() {
262 local file="$1" shell="$2" cmd="${3:-${pkgname}}"
263 local _bash_completion_dir=usr/share/bash-completion/completions/
264 local _fish_completion_dir=usr/share/fish/vendor_completions.d/
265 local _zsh_completion_dir=usr/share/zsh/site-functions/
267 if [ $# -lt 2 ]; then
268 msg_red "$pkgver: vcompletion: 2 arguments expected: <file> <shell>\n"
269 return 1
272 if ! [ -f "$file" ]; then
273 msg_red "$pkgver: vcompletion: file $file doesn't exist\n"
276 case "$shell" in
277 bash) vinstall "$file" 0644 $_bash_completion_dir "${cmd}" ;;
278 fish) vinstall "$file" 0644 $_fish_completion_dir "${cmd}.fish" ;;
279 zsh) vinstall "$file" 0644 $_zsh_completion_dir "_${cmd}" ;;
281 msg_red "$pkgver: vcompletion: unknown shell ${shell}"
282 return 1
284 esac