[PATCH v2 1/2] add hints script for the platform aix

Sven Willenbuecher sven.willenbuecher at kuehne-nagel.com
Wed Dec 29 12:38:30 UTC 2021


- introduce new macro variables VERBOSE_MODE and GREP_COLOR_OPTION
- get rid of the options -iname and -print0 of GNU find because the aix
find does not known these
---
 src/password-store.sh | 26 ++++++++++++++------------
 src/platform/aix.sh   |  2 ++
 2 files changed, 16 insertions(+), 12 deletions(-)
 create mode 100644 src/platform/aix.sh

diff --git a/src/password-store.sh b/src/password-store.sh
index aef8d72..3da3a61 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -137,7 +137,7 @@ reencrypt_path() {
 			mv "$passfile_temp" "$passfile" || rm -f "$passfile_temp"
 		fi
 		prev_gpg_recipients="${GPG_RECIPIENTS[*]}"
-	done < <(find "$1" -path '*/.git' -prune -o -path '*/.extensions' -prune -o -iname '*.gpg' -print0)
+	done < <(find "$1" -path '*/.git' -prune -o -path '*/.extensions' -prune -o -name '*.[Gg][Pp][Gg]' -exec printf '%s\0' {} \;)
 }
 check_sneaky_paths() {
 	local path
@@ -245,6 +245,8 @@ tmpdir() {
 GETOPT="getopt"
 SHRED="shred -f -z"
 BASE64="base64"
+VERBOSE_MODE="-v"
+GREP_COLOR_OPTION="--color=always"
 
 source "$(dirname "$0")/platform/$(uname | cut -d _ -f 1 | tr '[:upper:]' '[:lower:]').sh" 2>/dev/null # PLATFORM_FUNCTION_FILE
 
@@ -337,14 +339,14 @@ cmd_init() {
 
 	if [[ $# -eq 1 && -z $1 ]]; then
 		[[ ! -f "$gpg_id" ]] && die "Error: $gpg_id does not exist and so cannot be removed."
-		rm -v -f "$gpg_id" || exit 1
+		rm $VERBOSE_MODE -f "$gpg_id" || exit 1
 		if [[ -n $INNER_GIT_DIR ]]; then
 			git -C "$INNER_GIT_DIR" rm -qr "$gpg_id"
 			git_commit "Deinitialize ${gpg_id}${id_path:+ ($id_path)}."
 		fi
 		rmdir -p "${gpg_id%/*}" 2>/dev/null
 	else
-		mkdir -v -p "$PREFIX/$id_path"
+		mkdir -p $VERBOSE_MODE "$PREFIX/$id_path"
 		printf "%s\n" "$@" > "$gpg_id"
 		local id_print="$(printf "%s, " "$@")"
 		echo "Password store initialized for ${id_print%, }${id_path:+ ($id_path)}"
@@ -421,7 +423,7 @@ cmd_grep() {
 	[[ $# -lt 1 ]] && die "Usage: $PROGRAM $COMMAND [GREPOPTIONS] search-string"
 	local passfile grepresults
 	while read -r -d "" passfile; do
-		grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$@")"
+		grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep $GREP_COLOR_OPTION "$@")"
 		[[ $? -ne 0 ]] && continue
 		passfile="${passfile%.gpg}"
 		passfile="${passfile#$PREFIX/}"
@@ -430,7 +432,7 @@ cmd_grep() {
 		passfile="${passfile##*/}"
 		printf "\e[94m%s\e[1m%s\e[0m:\n" "$passfile_dir" "$passfile"
 		echo "$grepresults"
-	done < <(find -L "$PREFIX" -path '*/.git' -prune -o -path '*/.extensions' -prune -o -iname '*.gpg' -print0)
+	done < <(find -L "$PREFIX" -path '*/.git' -prune -o -path '*/.extensions' -prune -o -name '*.[Gg][Pp][Gg]' -exec printf '%s\0' {} \;)
 }
 
 cmd_insert() {
@@ -453,7 +455,7 @@ cmd_insert() {
 
 	[[ $force -eq 0 && -e $passfile ]] && yesno "An entry already exists for $path. Overwrite it?"
 
-	mkdir -p -v "$PREFIX/$(dirname -- "$path")"
+	mkdir -p $VERBOSE_MODE "$PREFIX/$(dirname -- "$path")"
 	set_gpg_recipients "$(dirname -- "$path")"
 
 	if [[ $multiline -eq 1 ]]; then
@@ -487,7 +489,7 @@ cmd_edit() {
 
 	local path="${1%/}"
 	check_sneaky_paths "$path"
-	mkdir -p -v "$PREFIX/$(dirname -- "$path")"
+	mkdir -p $VERBOSE_MODE "$PREFIX/$(dirname -- "$path")"
 	set_gpg_recipients "$(dirname -- "$path")"
 	local passfile="$PREFIX/$path.gpg"
 	set_git "$passfile"
@@ -529,7 +531,7 @@ cmd_generate() {
 	check_sneaky_paths "$path"
 	[[ $length =~ ^[0-9]+$ ]] || die "Error: pass-length \"$length\" must be a number."
 	[[ $length -gt 0 ]] || die "Error: pass-length must be greater than zero."
-	mkdir -p -v "$PREFIX/$(dirname -- "$path")"
+	mkdir -p $VERBOSE_MODE "$PREFIX/$(dirname -- "$path")"
 	set_gpg_recipients "$(dirname -- "$path")"
 	local passfile="$PREFIX/$path.gpg"
 	set_git "$passfile"
@@ -584,7 +586,7 @@ cmd_delete() {
 
 	[[ $force -eq 1 ]] || yesno "Are you sure you would like to delete $path?"
 
-	rm $recursive -f -v "$passfile"
+	rm $recursive -f $VERBOSE_MODE "$passfile"
 	set_git "$passfile"
 	if [[ -n $INNER_GIT_DIR && ! -e $passfile ]]; then
 		git -C "$INNER_GIT_DIR" rm -qr "$passfile"
@@ -618,7 +620,7 @@ cmd_copy_move() {
 	echo "$old_path"
 	[[ -e $old_path ]] || die "Error: $1 is not in the password store."
 
-	mkdir -p -v "${new_path%/*}"
+	mkdir -p $VERBOSE_MODE "${new_path%/*}"
 	[[ -d $old_path || -d $new_path || $new_path == */ ]] || new_path="${new_path}.gpg"
 
 	local interactive="-i"
@@ -626,7 +628,7 @@ cmd_copy_move() {
 
 	set_git "$new_path"
 	if [[ $move -eq 1 ]]; then
-		mv $interactive -v "$old_path" "$new_path" || exit 1
+		mv $interactive $VERBOSE_MODE "$old_path" "$new_path" || exit 1
 		[[ -e "$new_path" ]] && reencrypt_path "$new_path"
 
 		set_git "$new_path"
@@ -643,7 +645,7 @@ cmd_copy_move() {
 		fi
 		rmdir -p "$old_dir" 2>/dev/null
 	else
-		cp $interactive -r -v "$old_path" "$new_path" || exit 1
+		cp $interactive -r $VERBOSE_MODE "$old_path" "$new_path" || exit 1
 		[[ -e "$new_path" ]] && reencrypt_path "$new_path"
 		git_add_file "$new_path" "Copy ${1} to ${2}."
 	fi
diff --git a/src/platform/aix.sh b/src/platform/aix.sh
new file mode 100644
index 0000000..e94ee73
--- /dev/null
+++ b/src/platform/aix.sh
@@ -0,0 +1,2 @@
+VERBOSE_MODE=
+GREP_COLOR_OPTION=
-- 
2.31.1



More information about the Password-Store mailing list