source: wspkg/freebsd/freebsd.install.sh @ f6d5ca1

Last change on this file since f6d5ca1 was f6d5ca1, checked in by Ting-Wei Lan <lantw44@…>, 3 years ago

Use 'printf' to print non-constant strings in shell scripts

It is unsafe to use 'echo' with strings with variable substitutions.
Different 'echo' implementations may accept different options, and they
can interpret strings with escape characters in different ways. The
behavior of 'printf' is much more consistent so it should be preferred.

  • Property mode set to 100755
File size: 1.1 KB
Line 
1#!/bin/sh
2
3msg_and_copy () {
4    printf '==> Copying %s to %s\n' "$1" "$2" 1>&2
5    cp -r "$1" "$2"
6}
7
8msg_and_mkdir () {
9    printf '==> Creating directory %s\n' "$1" 1>&2
10    mkdir -p "$1"
11}
12
13if [ -z "$4" ]; then
14    printf 'Usage: %s category cat_makefile cat_makefile_inc dir\n' "$0"
15    printf 'Example: %s local local.makefile local.makefile.inc 217 will do\n' "$0"
16    echo   ' mkdir -p                 /usr/ports/local'
17    echo   ' cp -r local.makefile     /usr/ports/local/Makefile'
18    echo   ' cp -r local.makefile.inc /usr/ports/local/Makefile.inc'
19    echo   ' cp -r 217                /usr/ports/local'
20    exit 1
21fi
22
23: ${PORTSDIR:="/usr/ports"}
24category="$1"
25cat_makefile="$2"
26cat_makefile_inc="$3"
27dir="$4"
28
29[ '!' -d "${PORTSDIR}/${category}" ] && \
30    msg_and_mkdir "${PORTSDIR}/${category}"
31[ '!' -f "${PORTSDIR}/${category}/Makefile" ] && \
32    msg_and_copy "${cat_makefile}" "${PORTSDIR}/${category}/Makefile"
33[ '!' -f "${PORTSDIR}/${category}/Makefile.inc" ] && \
34    msg_and_copy "${cat_makefile_inc}" "${PORTSDIR}/${category}/Makefile.inc"
35
36msg_and_copy "${dir}" "${PORTSDIR}/${category}"
Note: See TracBrowser for help on using the repository browser.