Browse Source

Apply changes suggested by ShellCheck (mkit)

Alois Mahdal 9 years ago
parent
commit
b68913c9cb

+ 24
- 28
utils/mkit/include/build.sh View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $MKIT_DIR/include/ini.sh || die "cannot import ini.sh"
3
+. "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
4 4
 
5 5
 
6 6
 build() {
@@ -23,15 +23,10 @@ build1() {
23 23
     srcpath=$1
24 24
     dstpath=${srcpath%.skel}
25 25
     case $dstpath in
26
-        *.md)   cat $srcpath \
27
-                  | expand_includes \
28
-                  | expand_variables \
29
-                > $dstpath ;;
30
-        *)      cat $srcpath \
31
-                  | expand_variables \
32
-                > $dstpath ;;
26
+        *.md) <"$srcpath" expand_includes | expand_variables >"$dstpath" ;;
27
+        *)    <"$srcpath"                   expand_variables >"$dstpath" ;;
33 28
     esac
34
-    echo $dstpath >> built.list
29
+    echo "$dstpath" >> built.list
35 30
 }
36 31
 
37 32
 build_manpages() {
@@ -41,9 +36,9 @@ build_manpages() {
41 36
         ini lskeys "files:man" \
42 37
           | while read manfile;
43 38
             do
44
-                mdfile=$manfile.md
45
-                ronn -r $mdfile
46
-                echo $manfile >> built.list
39
+                mdfile="$manfile.md"
40
+                ronn -r "$mdfile"
41
+                echo "$manfile" >> built.list
47 42
             done
48 43
     else
49 44
         echo "ronn is not installed"
@@ -56,9 +51,10 @@ clean() {
56 51
     # Clean up tree after building
57 52
     #
58 53
     test -f built.list && {
59
-        cat built.list | xargs rm -f
54
+        <built.list xargs rm -f
60 55
         rm -f built.list
61
-    } || :
56
+    }
57
+    true
62 58
 }
63 59
 
64 60
 dist() {
@@ -67,13 +63,13 @@ dist() {
67 63
     #
68 64
     local version=$(get_version)
69 65
     local dirname=$MKIT_PKGNAME-$version
70
-    mkdir -p $dirname
66
+    mkdir -p "$dirname"
71 67
     local item
72
-    cp -R $(ini values "lists:dist") $dirname
73
-    sed -i -e "s/^VERSION = .*/VERSION = $version/" $dirname/config.mk
74
-    tar -cf $dirname.tar $dirname
75
-    gzip $dirname.tar
76
-    rm -rf $dirname
68
+    cp -R "$(ini values "lists:dist")" "$dirname"
69
+    sed -i -e "s/^VERSION = .*/VERSION = $version/" "$dirname/config.mk"
70
+    tar -cf "$dirname.tar" "$dirname"
71
+    gzip "$dirname.tar"
72
+    rm -rf "$dirname"
77 73
 }
78 74
 
79 75
 expand_includes() {
@@ -111,12 +107,12 @@ expand_variables() {
111 107
       | while read varname;
112 108
         do
113 109
             varvalue="$(ini 1value "vars:$varname" | sed -e 's/\$/\\$/' )"
114
-            echo "s|$varname|$varvalue|;" >> $script
110
+            echo "s|$varname|$varvalue|;" >> "$script"
115 111
         done
116
-    echo "s|__CODENAME__|$CODENAME|;"     >> $script
117
-    echo "s|__VERSION__|$(get_version)|;" >> $script
118
-    perl -wp $script
119
-    rm $script
112
+    echo "s|__CODENAME__|$CODENAME|;"     >> "$script"
113
+    echo "s|__VERSION__|$(get_version)|;" >> "$script"
114
+    perl -wp "$script"
115
+    rm "$script"
120 116
 }
121 117
 
122 118
 get_version() {
@@ -182,14 +178,14 @@ get_version() {
182 178
         fi
183 179
         test -n "$lasttag" && version=${lasttag:1}
184 180
         local suffix=""
185
-        case $commit:$dirty in
181
+        case "$commit:$dirty" in
186 182
             :)       suffix=""                ;;
187 183
             :dirty)  suffix="+$dirty"         ;;
188 184
             *:)      suffix="+$commit"        ;;
189 185
             *:dirty) suffix="+$commit.$dirty" ;;
190 186
         esac
191 187
         test -b "$prerl" && suffix="-$prerl$suffix"
192
-        version=$version$suffix
188
+        version="$version$suffix"
193 189
     fi
194
-    echo $version
190
+    echo "$version"
195 191
 }

+ 7
- 6
utils/mkit/include/deploy.sh View File

@@ -34,13 +34,13 @@ deploy_item() {
34 34
     #
35 35
     local src="$1"
36 36
     local dst="$2"
37
-    local mode=${3:-$MKIT_DEFAULT_MODE}
37
+    local mode="${3:-$MKIT_DEFAULT_MODE}"
38 38
     if test -d "$src";
39 39
     then
40 40
         cp -vr "$src" "$dst"
41
-        find "$dst" -type f | xargs chmod -c "$mode"
41
+        find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
42 42
     else
43
-        command -p install -DTvm $mode $src "$dst"
43
+        command -p install -DTvm "$mode" "$src" "$dst"
44 44
     fi
45 45
 }
46 46
 
@@ -50,7 +50,7 @@ get_dst() {
50 50
     #
51 51
     local grp=$1
52 52
     local src=$2
53
-    echo "$(get_root $grp)/$(ini 1value "files:$grp:$src")"
53
+    echo "$(get_root "$grp")/$(ini 1value "files:$grp:$src")"
54 54
 }
55 55
 
56 56
 get_root() {
@@ -77,10 +77,11 @@ install() {
77 77
               | while read src;
78 78
                 do
79 79
                     dst=$(get_dst "$group" "$src")
80
-                    deploy_item "$src" "$dst" $mode
80
+                    deploy_item "$src" "$dst" "$mode"
81 81
                 done
82 82
         done
83
-    test -f .autoclean && clean || :
83
+    test -f .autoclean && clean
84
+    true
84 85
 }
85 86
 
86 87
 uninstall() {

+ 10
- 10
utils/mkit/include/ini.sh View File

@@ -15,7 +15,7 @@ ini() {
15 15
         1value) fn=_ini_greppath; limit="tail -1" ;;
16 16
         *)      die "incorrect use of \`ini()\`"
17 17
     esac
18
-    cat $MKIT_INI | $fn $arg | $limit
18
+    <"$MKIT_INI" $fn "$arg" | $limit
19 19
 }
20 20
 
21 21
 _ini_cat() {
@@ -66,9 +66,9 @@ _ini_greppath() {
66 66
     #     [files:share]
67 67
     #         my/lib.sh   = proj/my/lib.sh
68 68
     #
69
-    local wnt=$1
70
-    local wntkey=${wnt##*:}
71
-    local wntsec=${wnt%:$wntkey}
69
+    local wnt="$1"
70
+    local wntkey="${wnt##*:}"
71
+    local wntsec="${wnt%:$wntkey}"
72 72
     if test "$wntsec" = 'ENV';
73 73
     then
74 74
         local override="${!wntkey}"
@@ -78,14 +78,14 @@ _ini_greppath() {
78 78
             return
79 79
         fi
80 80
     fi
81
-    _ini_grepsec $wntsec | _ini_grepkey $wntkey
81
+    _ini_grepsec "$wntsec" | _ini_grepkey "$wntkey"
82 82
 }
83 83
 
84 84
 _ini_grepsec() {
85 85
     #
86 86
     # Read one INI section
87 87
     #
88
-    local wnt=$1
88
+    local wnt="$1"
89 89
     local ok=false
90 90
     grep '.' \
91 91
       | grep -v '\s*#' \
@@ -105,17 +105,17 @@ _ini_lskeys() {
105 105
     #
106 106
     # List keys from a section
107 107
     #
108
-    local sct=$1
109
-    _ini_grepsec $sct | cut -d= -f1 | sort | uniq
108
+    local sct="$1"
109
+    _ini_grepsec "$sct" | cut -d= -f1 | sort | uniq
110 110
 }
111 111
 
112 112
 _ini_maybe_expand() {
113 113
     #
114 114
     # Decide whether or not to expand
115 115
     #
116
-    if test $MKIT_INI_EXPAND -gt 0;
116
+    if test "$MKIT_INI_EXPAND" -gt 0;
117 117
     then
118
-        MKIT_INI_EXPAND=$(( $MKIT_INI_EXPAND - 1 )) _ini_expand
118
+        MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) _ini_expand
119 119
     else
120 120
         _ini_cat
121 121
     fi

+ 9
- 9
utils/mkit/include/mkit.sh View File

@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 
3
-. $MKIT_DIR/include/build.sh  || die "cannot import build.sh"
4
-. $MKIT_DIR/include/deploy.sh || die "cannot import deploy.sh"
5
-. $MKIT_DIR/include/release.sh || die "cannot import release.sh"
6
-. $MKIT_DIR/include/ini.sh    || die "cannot import ini.sh"
3
+. "$MKIT_DIR/include/build.sh"  || die "cannot import build.sh"
4
+. "$MKIT_DIR/include/deploy.sh" || die "cannot import deploy.sh"
5
+. "$MKIT_DIR/include/release.sh" || die "cannot import release.sh"
6
+. "$MKIT_DIR/include/ini.sh"    || die "cannot import ini.sh"
7 7
 
8 8
 MKIT_INI=${MKIT_INI:-mkit.ini}
9 9
 MKIT_INI_EXPAND=2
@@ -19,16 +19,16 @@ mkit_init() {
19 19
     #
20 20
     test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
21 21
     tmp=$(mktemp)
22
-    sed -e 's/ = /=/' < config.mk > $tmp
23
-    . $tmp
24
-    rm -f $tmp
22
+    sed -e 's/ = /=/' < config.mk > "$tmp"
23
+    . "$tmp"
24
+    rm -f "$tmp"
25 25
 }
26 26
 
27 27
 die() {
28 28
     #
29 29
     # Exit with message and non-zero exit status
30 30
     #
31
-    echo "fatal: $@" >&2
31
+    echo "fatal: $*" >&2
32 32
     exit 4
33 33
 }
34 34
 
@@ -48,6 +48,6 @@ route() {
48 48
             $1
49 49
             ;;
50 50
         *)
51
-            echo "usage: $(basename $0) build|clean|dist|install|uninstall" >&2
51
+            echo "usage: $(basename "$0") build|clean|dist|install|uninstall" >&2
52 52
     esac
53 53
 }

+ 5
- 5
utils/mkit/include/release.sh View File

@@ -13,7 +13,7 @@ __make_ver() {
13 13
         z) new="$oldx.$oldy.$((oldz+1))"    ;;
14 14
         *) die "invalid release level: $1"  ;;
15 15
     esac
16
-    echo $new
16
+    echo "$new"
17 17
 }
18 18
 
19 19
 __release() {
@@ -30,11 +30,11 @@ __release() {
30 30
     git rev-parse HEAD >&/dev/null || die "cannot release outside git repo"
31 31
     local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD)
32 32
     local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
33
-    local changelog="$(git log --oneline $lasttag..HEAD)"
33
+    local changelog="$(git log --oneline "$lasttag..HEAD")"
34 34
     local curbranch=$(git rev-parse --abbrev-ref HEAD)
35 35
     local dirt="$(git diff --shortstat 2>/dev/null)"
36 36
 
37
-    local newver=$(__make_ver $level ${lasttag#v})
37
+    local newver=$(__make_ver "$level" "${lasttag#v}")
38 38
     local newtag=v$newver
39 39
     local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1)
40 40
 
@@ -62,8 +62,8 @@ __release() {
62 62
     # FIXME: Have user prepare proper message with changelog
63 63
 
64 64
     set -e
65
-    git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" $newtag
66
-    git branch -f $RELDST $newtag
65
+    git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag"
66
+    git branch -f "$RELDST" "$newtag"
67 67
 }
68 68
 
69 69
 release_x() {

+ 1
- 1
utils/mkit/make View File

@@ -8,7 +8,7 @@ die() {
8 8
 
9 9
 export MKIT_DIR=${MKIT_DIR:-mkit}
10 10
 
11
-. $MKIT_DIR/include/mkit.sh || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
11
+. "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
12 12
 
13 13
 mkit_init
14 14