@@ -26,7 +26,7 @@ for arg in "$@"; do
2626 ;;
2727 --file=*)
2828 nixFile="${arg#*=}"
29− if [ ! -f "$nixFile" ]; then
29+ if [[ ! -f "$nixFile" ]]; then
3030 die "Could not find provided file $nixFile"
3131 fi
3232 ;;
@@ -38,7 +38,7 @@ for arg in "$@"; do
3838 exit 0
3939 ;;
4040 --*)
41− echo "$scriptName: Unknown argument: " $arg
41+ echo "$scriptName: Unknown argument: $arg"
4242 usage
4343 exit 1
4444 ;;
@@ -53,25 +53,25 @@ newVersion=${args[1]}
5353newHash=${args[2]}
5454newUrl=${args[3]}
5555
56−if [ "${#args[*]}" -lt 2 ]; then
56+if (( "${#args[*]}" < 2 )); then
5757 echo "$scriptName: Too few arguments"
5858 usage
5959 exit 1
6060fi
6161
62−if [ "${#args[*]}" -gt 4 ]; then
62+if (( "${#args[*]}" > 4 )); then
6363 echo "$scriptName: Too many arguments"
6464 usage
6565 exit 1
6666fi
6767
68−if [ -z "$versionKey" ]; then
68+if [[ -z "$versionKey" ]]; then
6969 versionKey=version
7070fi
7171
72−if [ -z "$nixFile" ]; then
72+if [[ -z "$nixFile" ]]; then
7373 nixFile=$(nix-instantiate $systemArg --eval --strict -A "$attr.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')
74− if [ ! -f "$nixFile" ]; then
74+ if [[ ! -f "$nixFile" ]]; then
7575 die "Couldn't evaluate '$attr.meta.position' to locate the .nix file!"
7676 fi
7777fi
@@ -79,28 +79,28 @@ fi
7979oldHashAlgo=$(nix-instantiate $systemArg --eval --strict -A "$attr.src.drvAttrs.outputHashAlgo" | tr -d '"')
8080oldHash=$(nix-instantiate $systemArg --eval --strict -A "$attr.src.drvAttrs.outputHash" | tr -d '"')
8181
82−if [ -z "$oldHashAlgo" -o -z "$oldHash" ]; then
82+if [[ -z "$oldHashAlgo" || -z "$oldHash" ]]; then
8383 die "Couldn't evaluate old source hash from '$attr.src'!"
8484fi
8585
86−if [ $(grep -c "$oldHash" "$nixFile") != 1 ]; then
86+if [[ $(grep --count "$oldHash" "$nixFile") != 1 ]]; then
8787 die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!"
8888fi
8989
9090oldUrl=$(nix-instantiate $systemArg --eval -E "with import ./. {}; builtins.elemAt ($attr.src.drvAttrs.urls or [ $attr.src.url ]) 0" | tr -d '"')
9191
92−if [ -z "$oldUrl" ]; then
92+if [[ -z "$oldUrl" ]]; then
9393 die "Couldn't evaluate source url from '$attr.src'!"
9494fi
9595
9696drvName=$(nix-instantiate $systemArg --eval -E "with import ./. {}; lib.getName $attr" | tr -d '"')
9797oldVersion=$(nix-instantiate $systemArg --eval -E "with import ./. {}; $attr.${versionKey} or (lib.getVersion $attr)" | tr -d '"')
9898
99−if [ -z "$drvName" -o -z "$oldVersion" ]; then
99+if [[ -z "$drvName" || -z "$oldVersion" ]]; then
100100 die "Couldn't evaluate name and version from '$attr.name'!"
101101fi
102102
103−if [ "$oldVersion" = "$newVersion" ]; then
103+if [[ "$oldVersion" = "$newVersion" ]]; then
104104 echo "$scriptName: New version same as old version, nothing to do." >&2
105105 exit 0
106106fi
@@ -109,9 +109,9 @@ fi
109109oldVersionEscaped=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g')
110110oldUrlEscaped=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g')
111111
112−if [ $(grep -c -E "^\s*(let\b)?\s*$versionKey\s*=\s*\"$oldVersionEscaped\"" "$nixFile") = 1 ]; then
112+if [[ $(grep --count --extended-regexp "^\s*(let\b)?\s*$versionKey\s*=\s*\"$oldVersionEscaped\"" "$nixFile") = 1 ]]; then
113113 pattern="/\b$versionKey\b\s*=/ s|\"$oldVersionEscaped\"|\"$newVersion\"|"
114−elif [ $(grep -c -E "^\s*(let\b)?\s*name\s*=\s*\"[^\"]+-$oldVersionEscaped\"" "$nixFile") = 1 ]; then
114+elif [[ $(grep --count --extended-regexp "^\s*(let\b)?\s*name\s*=\s*\"[^\"]+-$oldVersionEscaped\"" "$nixFile") = 1 ]]; then
115115 pattern="/\bname\b\s*=/ s|-$oldVersionEscaped\"|-$newVersion\"|"
116116else
117117 die "Couldn't figure out where out where to patch in new version in '$attr'!"
@@ -124,7 +124,7 @@ if cmp -s "$nixFile" "$nixFile.bak"; then
124124fi
125125
126126# Replace new URL
127−if [ -n "$newUrl" ]; then
127+if [[ -n "$newUrl" ]]; then
128128 sed -i "$nixFile" -re "s|\"$oldUrlEscaped\"|\"$newUrl\"|"
129129
130130 if cmp -s "$nixFile" "$nixFile.bak"; then
@@ -165,10 +165,10 @@ if cmp -s "$nixFile" "$nixFile.bak"; then
165165fi
166166
167167# If new hash not given on the command line, recalculate it ourselves.
168−if [ -z "$newHash" ]; then
168+if [[ -z "$newHash" ]]; then
169169 nix-build $systemArg --no-out-link -A "$attr.src" 2>"$attr.fetchlog" >/dev/null || true
170170 # FIXME: use nix-build --hash here once https://github.com/NixOS/nix/issues/1172 is fixed
171− newHash=$(egrep -v "killing process|dependencies couldn't be built|wanted: " "$attr.fetchlog" | tail -n2 | sed "s~output path .* has .* hash ‘\(.*\)’ when .* was expected\|fixed-output derivation produced path '.*' with .* hash '\(.*\)' instead of the expected hash '.*'\| got: .*:\(.*\)~\1\2\3~" | head -n1)
171+ newHash=$(grep --extended-regexp --invert-match "killing process|dependencies couldn't be built|wanted: " "$attr.fetchlog" | tail -n2 | sed "s~output path .* has .* hash ‘\(.*\)’ when .* was expected\|fixed-output derivation produced path '.*' with .* hash '\(.*\)' instead of the expected hash '.*'\| got: .*:\(.*\)~\1\2\3~" | head -n1)
172172fi
173173
174174if [[ -n "$sri" ]]; then
@@ -176,12 +176,12 @@ if [[ -n "$sri" ]]; then
176176 newHash="$(nix to-sri --type "$oldHashAlgo" "$newHash")"
177177fi
178178
179−if [ -z "$newHash" ]; then
179+if [[ -z "$newHash" ]]; then
180180 cat "$attr.fetchlog" >&2
181181 die "Couldn't figure out new hash of '$attr.src'!"
182182fi
183183
184−if [ -z "${ignoreSameHash}" ] && [ "$oldVersion" != "$newVersion" ] && [ "$oldHash" = "$newHash" ]; then
184+if [[ -z "${ignoreSameHash}" && "$oldVersion" != "$newVersion" && "$oldHash" = "$newHash" ]]; then
185185 mv "$nixFile.bak" "$nixFile"
186186 die "Both the old and new source hashes of '$attr.src' were equivalent. Please fix the package's source URL to be dependent on '\${version}'!"
187187fi