Speedup pass on macOS and brew

pass-maillinglist at artursterz.de pass-maillinglist at artursterz.de
Fri Oct 26 12:12:06 CEST 2018


All right, looks like I have found a good solution thanks to my teammate Jonas. It’s a multi-staged lookup. First, look in $PATH, if it’s not there, try to get it from brew, then from macports.
Additionally, I implemented a lookup for macports so that we do not assume the default path any more.
The execution will also stop, of gnu-getopt could not be found. The user then has to install it.
Finally, I put everything in its own function.

All of this is done in multiple commits, which are based on each other. It should be straight forward to apply the patches.


Part 1:
Use three assumed default paths for gnu-getopt lookup

brew --prefix gnu-getopt will allways make some git lookups which may take
longer, depending on your internet connectivity. We therefore first look
in some default location for gnu-getopt. If it is not found there, make
the regular lookup.
========================
diff --git a/src/platform/darwin.sh b/src/platform/darwin.sh
index 342ecce..4905c7d 100644
--- a/src/platform/darwin.sh
+++ b/src/platform/darwin.sh
@@ -43,6 +43,9 @@ qrcode() {
        fi
 }

-GETOPT="$(brew --prefix gnu-getopt 2>/dev/null || { which port &>/dev/null && echo /opt/local; } || echo /usr/local)/bin/getopt"
+GETOPT="$(PATH="/usr/local/opt/gnu-getopt/bin:/opt/local/bin:/usr/local/bin" command -v getopt)" || \
+GETOPT="$(brew --prefix gnu-getopt 2>/dev/null)/bin/getopt" || \
+GETOPT="$(which port &>/dev/null && echo /opt/local/bin/getopt)"
+
 SHRED="srm -f -z"
 BASE64="openssl base64“


Part 2:
Speed up the brew-based gnu-getop lookup

If gnu-getopt is not installed in the brew default path,
brew --prefix gnu-getopt will be used, which is annoyingly slow.
brew --prefix is way faster and should be prefered.
========================
diff --git a/src/platform/darwin.sh b/src/platform/darwin.sh
index 4905c7d..2ee608b 100644
--- a/src/platform/darwin.sh
+++ b/src/platform/darwin.sh
@@ -44,7 +44,7 @@ qrcode() {
 }

 GETOPT="$(PATH="/usr/local/opt/gnu-getopt/bin:/opt/local/bin:/usr/local/bin" command -v getopt)" || \
-GETOPT="$(brew --prefix gnu-getopt 2>/dev/null)/bin/getopt" || \
+GETOPT="$(brew --prefix 2>/dev/null)/opt/gnu-getopt/bin/getopt" || \
 GETOPT="$(which port &>/dev/null && echo /opt/local/bin/getopt)"

 SHRED="srm -f -z“


Part 3:
Infer gnu-getopt path using MacPorts

Unlike using brew, the MacPorts default path is assumed when infering the path to gnu-getopts.
This should not be done, since it is possible to install MacPorts and the ports in
non-standard paths.
========================
diff --git a/src/platform/darwin.sh b/src/platform/darwin.sh
index 2ee608b..220dd78 100644
--- a/src/platform/darwin.sh
+++ b/src/platform/darwin.sh
@@ -45,7 +45,7 @@ qrcode() {

 GETOPT="$(PATH="/usr/local/opt/gnu-getopt/bin:/opt/local/bin:/usr/local/bin" command -v getopt)" || \
 GETOPT="$(brew --prefix 2>/dev/null)/opt/gnu-getopt/bin/getopt" || \
-GETOPT="$(which port &>/dev/null && echo /opt/local/bin/getopt)"
+GETOPT="$(port content getopt | grep -E '/s?bin/')"

 SHRED="srm -f -z"
 BASE64="openssl base64“


Part 4:
Notify the user if getopt is not installed

In the past commits we implemented a new way to find gnu-getopt on macOS.
If we can not find it, pass can not be used, thus the user should be
notified about this.
========================
diff --git a/src/platform/darwin.sh b/src/platform/darwin.sh
index 220dd78..9ff46df 100644
--- a/src/platform/darwin.sh
+++ b/src/platform/darwin.sh
@@ -47,5 +47,11 @@ GETOPT="$(PATH="/usr/local/opt/gnu-getopt/bin:/opt/local:/usr/local/bin/getopt"
 GETOPT="$(brew --prefix 2>/dev/null)/opt/gnu-getopt/bin/getopt" || \
 GETOPT="$(port content getopt | grep -E '/s?bin/')"

+echo $GETOPT
+if [ ! $GETOPT ]; then
+       echo "'getopt' is not installed. Please use 'brew' or 'port' to install it."
+       exit 1
+fi
+
 SHRED="srm -f -z"
 BASE64="openssl base64“


Part 5:
Use function for infering gnu-getopt on macOS
========================
diff --git a/src/platform/darwin.sh b/src/platform/darwin.sh
index 9ff46df..9c33c08 100644
--- a/src/platform/darwin.sh
+++ b/src/platform/darwin.sh
@@ -43,15 +43,18 @@ qrcode() {
        fi
 }

-GETOPT="$(PATH="/usr/local/opt/gnu-getopt/bin:/opt/local/bin:/usr/local/bin" command -v getopt)" || \
-GETOPT="$(brew --prefix 2>/dev/null)/opt/gnu-getopt/bin/getopt" || \
-GETOPT="$(port content getopt | grep -E '/s?bin/')"
+get_getopt() {
+       local GETOPT="$(PATH="/usr/local/opt/gnu-getopt/bin:/opt/local/bin:/usr/local/bin" command -v getopt)" || \
+       local GETOPT="$(brew --prefix 2>/dev/null)/opt/gnu-getopt/bin/getopt" || \
+       local GETOPT="$(port content getopt | grep -E '/s?bin/')"

-echo $GETOPT
-if [ ! $GETOPT ]; then
-       echo "'getopt' is not installed. Please use 'brew' or 'port' to install it."
-       exit 1
-fi
+       if [ ! $GETOPT ]; then
+               echo "'getopt' is not installed. Please use 'brew' or 'port' to install it."
+               exit 1
+       fi
+       echo $GETOPT
+}

+GETOPT=$(get_getopt)
 SHRED="srm -f -z"
 BASE64="openssl base64"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20181026/5607b1f3/attachment.html>


More information about the Password-Store mailing list