installShellFiles: rewrite functions

- Use FUNCNAME to track the name of function being called
- use long options for install commands
- use nix*Log functions for logging, instead of custom echoes
- remove silent error construction `|| return`

+25 -28
+25 -28
pkgs/by-name/in/installShellFiles/setup-hook.sh
··· 24 24 installManPage() { 25 25 local path 26 26 for path in "$@"; do 27 - if (( "${NIX_DEBUG:-0}" >= 1 )); then 28 - echo "installManPage: installing $path" 29 - fi 30 27 if test -z "$path"; then 31 - echo "installManPage: error: path cannot be empty" >&2 28 + nixErrorLog "${FUNCNAME[0]}: path cannot be empty" 32 29 return 1 33 30 fi 31 + nixInfoLog "${FUNCNAME[0]}: installing $path" 34 32 local basename 35 33 basename=$(stripHash "$path") # use stripHash in case it's a nix store path 36 34 local trimmed=${basename%.gz} # don't get fooled by compressed manpages 37 35 local suffix=${trimmed##*.} 38 36 if test -z "$suffix" -o "$suffix" = "$trimmed"; then 39 - echo "installManPage: error: path missing manpage section suffix: $path" >&2 37 + nixErrorLog "${FUNCNAME[0]}: path missing manpage section suffix: $path" 40 38 return 1 41 39 fi 42 40 local outRoot ··· 45 43 else 46 44 outRoot=${!outputMan:?} 47 45 fi 48 - install -Dm644 -T "$path" "${outRoot}/share/man/man$suffix/$basename" || return 46 + local outPath="${outRoot}/share/man/man$suffix/$basename" 47 + install -D --mode=644 --no-target-directory "$path" "$outPath" 49 48 done 50 49 } 51 50 ··· 107 106 --name) 108 107 name=$1 109 108 shift || { 110 - echo 'installShellCompletion: error: --name flag expected an argument' >&2 109 + nixErrorLog "${FUNCNAME[0]}: --name flag expected an argument" 111 110 return 1 112 111 } 113 112 continue;; ··· 118 117 --cmd) 119 118 cmdname=$1 120 119 shift || { 121 - echo 'installShellCompletion: error: --cmd flag expected an argument' >&2 120 + nixErrorLog "${FUNCNAME[0]}: --cmd flag expected an argument" 122 121 return 1 123 122 } 124 123 continue;; ··· 127 126 cmdname=${arg#--cmd=} 128 127 continue;; 129 128 --?*) 130 - echo "installShellCompletion: warning: unknown flag ${arg%%=*}" >&2 129 + nixWarnLog "${FUNCNAME[0]}: unknown flag ${arg%%=*}" 131 130 retval=2 132 131 continue;; 133 132 --) ··· 136 135 continue;; 137 136 esac 138 137 fi 139 - if (( "${NIX_DEBUG:-0}" >= 1 )); then 140 - echo "installShellCompletion: installing $arg${name:+ as $name}" 141 - fi 138 + nixInfoLog "${FUNCNAME[0]}: installing $arg${name:+ as $name}" 142 139 # if we get here, this is a path or named pipe 143 140 # Identify shell and output name 144 141 local curShell=$shell 145 142 local outName='' 146 143 if [[ -z "$arg" ]]; then 147 - echo "installShellCompletion: error: empty path is not allowed" >&2 144 + nixErrorLog "${FUNCNAME[0]}: empty path is not allowed" 148 145 return 1 149 146 elif [[ -p "$arg" ]]; then 150 147 # this is a named fd or fifo 151 148 if [[ -z "$curShell" ]]; then 152 - echo "installShellCompletion: error: named pipe requires one of --bash, --fish, or --zsh" >&2 149 + nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --bash, --fish, or --zsh" 153 150 return 1 154 151 elif [[ -z "$name" && -z "$cmdname" ]]; then 155 - echo "installShellCompletion: error: named pipe requires one of --cmd or --name" >&2 152 + nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --cmd or --name" 156 153 return 1 157 154 fi 158 155 else ··· 168 165 *) 169 166 if [[ "$argbase" = _* && "$argbase" != *.* ]]; then 170 167 # probably zsh 171 - echo "installShellCompletion: warning: assuming path \`$arg' is zsh; please specify with --zsh" >&2 168 + nixWarnLog "${FUNCNAME[0]}: assuming path \`$arg' is zsh; please specify with --zsh" 172 169 curShell=zsh 173 170 else 174 - echo "installShellCompletion: warning: unknown shell for path: $arg" >&2 171 + nixWarnLog "${FUNCNAME[0]}: unknown shell for path: $arg" >&2 175 172 retval=2 176 173 continue 177 174 fi;; ··· 188 185 zsh) outName=_$cmdname;; 189 186 *) 190 187 # Our list of shells is out of sync with the flags we accept or extensions we detect. 191 - echo 'installShellCompletion: internal error' >&2 188 + nixErrorLog "${FUNCNAME[0]}: internal: shell $curShell not recognized" 192 189 return 1;; 193 190 esac 194 191 fi ··· 206 203 fi;; 207 204 *) 208 205 # Our list of shells is out of sync with the flags we accept or extensions we detect. 209 - echo 'installShellCompletion: internal error' >&2 206 + nixErrorLog "${FUNCNAME[0]}: internal: shell $curShell not recognized" 210 207 return 1;; 211 208 esac 212 209 # Install file ··· 217 214 mkdir -p "$outDir" \ 218 215 && cat "$arg" > "$outPath" 219 216 else 220 - install -Dm644 -T "$arg" "$outPath" 221 - fi || return 217 + install -D --mode=644 --no-target-directory "$arg" "$outPath" 218 + fi 222 219 223 220 if [ ! -s "$outPath" ]; then 224 - echo "installShellCompletion: error: installed shell completion file \`$outPath' does not exist or has zero size" >&2 221 + nixErrorLog "${FUNCNAME[0]}: installed shell completion file \`$outPath' does not exist or has zero size" 225 222 return 1 226 223 fi 227 224 # Clear the per-path flags 228 225 name= 229 226 done 230 227 if [[ -n "$name" ]]; then 231 - echo 'installShellCompletion: error: --name flag given with no path' >&2 228 + nixErrorLog "${FUNCNAME[0]}: --name flag given with no path" >&2 232 229 return 1 233 230 fi 234 231 return $retval ··· 240 237 installBin() { 241 238 local path 242 239 for path in "$@"; do 243 - if (( "${NIX_DEBUG:-0}" >= 1 )); then 244 - echo "installBin: installing $path" 245 - fi 246 240 if test -z "$path"; then 247 - echo "installBin: error: path cannot be empty" >&2 241 + nixErrorLog "${FUNCNAME[0]}: path cannot be empty" 248 242 return 1 249 243 fi 244 + nixInfoLog "${FUNCNAME[0]}: installing $path" 245 + 250 246 local basename 251 247 # use stripHash in case it's a nix store path 252 248 basename=$(stripHash "$path") ··· 254 250 local outRoot 255 251 outRoot=${!outputBin:?} 256 252 257 - install -D --mode=755 --no-target-directory "$path" "${outRoot}/bin/$basename" || return 253 + local outPath="${outRoot}/bin/$basename" 254 + install -D --mode=755 --no-target-directory "$path" "${outRoot}/bin/$basename" 258 255 done 259 256 }