Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] common/environment/setup/install.sh: fix v* funcs for paths with spaces
@ 2024-02-12 19:57 classabbyamp
  0 siblings, 0 replies; only message in thread
From: classabbyamp @ 2024-02-12 19:57 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 847 bytes --]

There is a new pull request by classabbyamp against master on the void-packages repository

https://github.com/classabbyamp/void-packages mr-globby
https://github.com/void-linux/void-packages/pull/48676

common/environment/setup/install.sh: fix v* funcs for paths with spaces
also quote, fix tabs, and shellcheck the file

revival of #42850

re: @Chocimier's comment:

> How about pushing setting IFS down to cp call? We may need word splitting later on for vsv's LN_OPTS.

this does not work, it still splits the arguments if done at that level. also, `LN_OPTS` is a single word (either `-s` or `-sf`).

<!-- Uncomment relevant sections and delete options which are not applicable -->

#### Testing the changes
- I tested the changes in this PR: **YES**


A patch file from https://github.com/void-linux/void-packages/pull/48676.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-mr-globby-48676.patch --]
[-- Type: text/x-diff, Size: 4686 bytes --]

From bd26ebf45cdd451dfe3db15a71eac152d9943edf Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Mon, 12 Feb 2024 14:48:47 -0500
Subject: [PATCH] common/environment/setup/install.sh: fix v* funcs for paths
 with spaces

also quote, fix tabs, and shellcheck the file
---
 common/environment/setup/install.sh | 62 +++++++++++++++++------------
 1 file changed, 37 insertions(+), 25 deletions(-)

diff --git a/common/environment/setup/install.sh b/common/environment/setup/install.sh
index ba0845bba5d12..3d2fde7d2b165 100644
--- a/common/environment/setup/install.sh
+++ b/common/environment/setup/install.sh
@@ -8,13 +8,15 @@ unalias -a
 
 # disable wildcards helper
 _noglob_helper() {
-       set +f
-       "$@"
+	set +f
+	IFS= "$@"
 }
 
 # Apply _noglob to v* commands
 for cmd in vinstall vcopy vcompletion vmove vmkdir vbin vman vdoc vconf vsconf vlicense vsv; do
-       alias ${cmd}="set -f; _noglob_helper _${cmd}"
+	# intentionally expanded when defined
+	# shellcheck disable=SC2139
+	alias ${cmd}="set -f; _noglob_helper _${cmd}"
 done
 
 _vsv() {
@@ -24,6 +26,8 @@ _vsv() {
 	local svdir="${PKGDESTDIR}/etc/sv/${service}"
 
 	if [ $# -lt 1 ] || [ $# -gt 2 ]; then
+		# pkgver is defined in common/xbps-src/shutils/commmon.sh
+		# shellcheck disable=SC2154
 		msg_red "$pkgver: vsv: up to 2 arguments expected: <service> [<log facility>]\n"
 		return 1
 	fi
@@ -34,26 +38,26 @@ _vsv() {
 
 	vmkdir etc/sv
 	vcopy "${FILESDIR}/$service" etc/sv
-	if [ ! -L $svdir/run ]; then
-		grep -Fq 'exec 2>&1' $svdir/run || msg_warn "$pkgver: vsv: service '$service' does not contain 'exec 2>&1' to log stderr\n"
-		chmod 755 $svdir/run
+	if [ ! -L "$svdir/run" ]; then
+		grep -Fq 'exec 2>&1' "$svdir/run" || msg_warn "$pkgver: vsv: service '$service' does not contain 'exec 2>&1' to log stderr\n"
+		chmod 755 "$svdir/run"
 	fi
-	if [ -e $svdir/finish ] && [ ! -L $svdir/finish ]; then
-		chmod 755 $svdir/finish
+	if [ -e "$svdir/finish" ] && [ ! -L "$svdir/finish" ]; then
+		chmod 755 "$svdir/finish"
 	fi
-	ln ${LN_OPTS} /run/runit/supervise.${service} $svdir/supervise
-	if [ -d $svdir/log ] || [ -L $svdir/log ]; then
+	ln ${LN_OPTS} "/run/runit/supervise.${service}" "$svdir/supervise"
+	if [ -d "$svdir/log" ] || [ -L "$svdir/log" ]; then
 		msg_warn "$pkgver: vsv: overriding default log service\n"
 	else
-		mkdir $svdir/log
-		cat <<-EOF > $svdir/log/run
+		mkdir "$svdir/log"
+		cat <<-EOF > "$svdir/log/run"
 		#!/bin/sh
 		exec vlogger -t $service -p $facility
 		EOF
 	fi
-	ln ${LN_OPTS} /run/runit/supervise.${service}-log $svdir/log/supervise
-	if [ -e $svdir/log/run ] && [ ! -L $svdir/log/run ]; then
-		chmod 755 ${PKGDESTDIR}/etc/sv/${service}/log/run
+	ln ${LN_OPTS} "/run/runit/supervise.${service}-log" "$svdir/log/supervise"
+	if [ -e "$svdir/log/run" ] && [ ! -L "$svdir/log/run" ]; then
+		chmod 755 "${PKGDESTDIR}/etc/sv/${service}/log/run"
 	fi
 }
 
@@ -120,6 +124,8 @@ _vdoc() {
 		return 1
 	fi
 
+	# pkgname is defined in the package
+	# shellcheck disable=SC2154
 	vinstall "$file" 644 "usr/share/doc/${pkgname}" "$targetfile"
 }
 
@@ -175,9 +181,9 @@ _vinstall() {
 	fi
 
 	if [ -z "$targetfile" ]; then
-		install -Dm${mode} "${file}" "${PKGDESTDIR}/${targetdir}/${file##*/}"
+		install -Dm"${mode}" "${file}" "${PKGDESTDIR}/${targetdir}/${file##*/}"
 	else
-		install -Dm${mode} "${file}" "${PKGDESTDIR}/${targetdir}/${targetfile##*/}"
+		install -Dm"${mode}" "${file}" "${PKGDESTDIR}/${targetdir}/${targetfile##*/}"
 	fi
 }
 
@@ -193,7 +199,9 @@ _vcopy() {
 		return 1
 	fi
 
-	cp -a $files ${PKGDESTDIR}/${targetdir}
+	# intentionally unquoted for globbing
+	# shellcheck disable=SC2086
+	cp -a $files "${PKGDESTDIR}/${targetdir}"
 }
 
 _vmove() {
@@ -219,13 +227,17 @@ _vmove() {
 	done
 
 	if [ -z "${_targetdir}" ]; then
-		[ ! -d ${PKGDESTDIR} ] && install -d ${PKGDESTDIR}
-		mv ${DESTDIR}/$files ${PKGDESTDIR}
+		[ ! -d "${PKGDESTDIR}" ] && install -d "${PKGDESTDIR}"
+		# intentionally unquoted for globbing
+		# shellcheck disable=SC2086
+		mv "${DESTDIR}"/$files "${PKGDESTDIR}"
 	else
-		if [ ! -d ${PKGDESTDIR}/${_targetdir} ]; then
-			install -d ${PKGDESTDIR}/${_targetdir}
+		if [ ! -d "${PKGDESTDIR}/${_targetdir}" ]; then
+			install -d "${PKGDESTDIR}/${_targetdir}"
 		fi
-		mv ${DESTDIR}/$files ${PKGDESTDIR}/${_targetdir}
+		# intentionally unquoted for globbing
+		# shellcheck disable=SC2086
+		mv "${DESTDIR}"/$files "${PKGDESTDIR}/${_targetdir}"
 	fi
 }
 
@@ -243,9 +255,9 @@ _vmkdir() {
 	fi
 
 	if [ -z "$mode" ]; then
-		install -d ${PKGDESTDIR}/${dir}
+		install -d "${PKGDESTDIR}/${dir}"
 	else
-		install -dm${mode} ${PKGDESTDIR}/${dir}
+		install -dm"${mode}" "${PKGDESTDIR}/${dir}"
 	fi
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-12 19:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-12 19:57 [PR PATCH] common/environment/setup/install.sh: fix v* funcs for paths with spaces classabbyamp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).