소스 검색

Update mkit to version from fastfoo 0.7.0+master.g7e6e358

Alois Mahdal 9 년 전
부모
커밋
f80dd649d1
6개의 변경된 파일112개의 추가작업 그리고 78개의 파일을 삭제
  1. 30
    41
      utils/mkit/include/build.sh
  2. 50
    5
      utils/mkit/include/deploy.sh
  3. 10
    10
      utils/mkit/include/ini.sh
  4. 10
    13
      utils/mkit/include/mkit.sh
  5. 11
    8
      utils/mkit/include/release.sh
  6. 1
    1
      utils/mkit/make

+ 30
- 41
utils/mkit/include/build.sh 파일 보기

1
 #!/bin/bash
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
 build() {
6
 build() {
23
     srcpath=$1
23
     srcpath=$1
24
     dstpath=${srcpath%.skel}
24
     dstpath=${srcpath%.skel}
25
     case $dstpath in
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
     esac
28
     esac
34
-    echo $dstpath >> built.list
29
+    echo "$dstpath" >> built.list
35
 }
30
 }
36
 
31
 
37
 build_manpages() {
32
 build_manpages() {
41
         ini lskeys "files:man" \
36
         ini lskeys "files:man" \
42
           | while read manfile;
37
           | while read manfile;
43
             do
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
             done
42
             done
48
     else
43
     else
49
         echo "ronn is not installed"
44
         echo "ronn is not installed"
56
     # Clean up tree after building
51
     # Clean up tree after building
57
     #
52
     #
58
     test -f built.list && {
53
     test -f built.list && {
59
-        cat built.list | xargs rm -f
54
+        <built.list xargs rm -f
60
         rm -f built.list
55
         rm -f built.list
61
-    } || :
56
+    }
57
+    true
62
 }
58
 }
63
 
59
 
64
 dist() {
60
 dist() {
67
     #
63
     #
68
     local version=$(get_version)
64
     local version=$(get_version)
69
     local dirname=$MKIT_PKGNAME-$version
65
     local dirname=$MKIT_PKGNAME-$version
70
-    mkdir -p $dirname
66
+    mkdir -p "$dirname"
71
     local item
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
 expand_includes() {
75
 expand_includes() {
111
       | while read varname;
107
       | while read varname;
112
         do
108
         do
113
             varvalue="$(ini 1value "vars:$varname" | sed -e 's/\$/\\$/' )"
109
             varvalue="$(ini 1value "vars:$varname" | sed -e 's/\$/\\$/' )"
114
-            echo "s|$varname|$varvalue|;" >> $script
110
+            echo "s|$varname|$varvalue|;" >> "$script"
115
         done
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
 get_version() {
118
 get_version() {
161
     # meta-data is to *identify* the code, and provide safe path back
157
     # meta-data is to *identify* the code, and provide safe path back
162
     # to tree; commit refs are already perfect for that.
158
     # to tree; commit refs are already perfect for that.
163
     #
159
     #
164
-    # FIXME:  The assumpton "if we are in git repo, we can read version
165
-    #         from tags" fails if we are in shallow clone made from
166
-    #         other than a tagged commit.
167
-    #
168
     # FIXME:  Using PRERELEASE for release IDs may not be compatible with
160
     # FIXME:  Using PRERELEASE for release IDs may not be compatible with
169
     #         release strategy implemented in release.sh
161
     #         release strategy implemented in release.sh
170
     #
162
     #
184
         then    # the tree is "dirty", i.e. has been edited
176
         then    # the tree is "dirty", i.e. has been edited
185
             local dirty=dirty
177
             local dirty=dirty
186
         fi
178
         fi
187
-        version=${lasttag:1}
179
+        test -n "$lasttag" && version=${lasttag:1}
188
         local suffix=""
180
         local suffix=""
189
-        case $prerl:$commit:$dirty in
190
-            ::)        suffix=""                       ;;
191
-            ::dirty)   suffix="+$dirty"                ;;
192
-            :*:)       suffix="+$commit"               ;;
193
-            :*:dirty)  suffix="+$commit"               ;;
194
-            *::)       suffix="-$prerl"                ;;
195
-            *::dirty)  suffix="-$prerl+$dirty"         ;;
196
-            *:*:)      suffix="-$prerl+$commit"        ;;
197
-            *:*:dirty) suffix="-$prerl+$commit.$dirty" ;;
181
+        case "$commit:$dirty" in
182
+            :)       suffix=""                ;;
183
+            :dirty)  suffix="+$dirty"         ;;
184
+            *:)      suffix="+$commit"        ;;
185
+            *:dirty) suffix="+$commit.$dirty" ;;
198
         esac
186
         esac
199
-        version=$version$suffix
187
+        test -b "$prerl" && suffix="-$prerl$suffix"
188
+        version="$version$suffix"
200
     fi
189
     fi
201
-    echo $version
190
+    echo "$version"
202
 }
191
 }

+ 50
- 5
utils/mkit/include/deploy.sh 파일 보기

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
 
3
 
4
+check_env() {
5
+    #
6
+    # Check that environment variables have been set properly
7
+    #
8
+    PREFIX="$(readlink -m "$PREFIX")"
9
+    test -d "$PREFIX" || die "PREFIX points to non-existent directory: $PREFIX"
10
+}
11
+
12
+deploy_item() {
13
+    #
14
+    # Deploy item and make it look like wanted
15
+    #
16
+    # usage: deploy_item src dst [mode]
17
+    #
18
+    # Both src and dst must be names of actual items[1],
19
+    # whereas dst must not exist.  On update, dst is
20
+    # usually to be replaced but that is uninstall's
21
+    # job!
22
+    #
23
+    #  [1] Ie. src=foo and dst=/foo/bar does *always*
24
+    #      mean that foo will become 'bar'.  This is
25
+    #      different than traditional `cp` behavior,
26
+    #      when this depends if 'bar' already exists
27
+    #      as a directory.
28
+    #
29
+    # If mode is omitted or empty, MKIT_DEFAULT_MODE is
30
+    # used instead.
31
+    #
32
+    # Directories are copied recursively, and mode is
33
+    # applied only to files.
34
+    #
35
+    local src="$1"
36
+    local dst="$2"
37
+    local mode="${3:-$MKIT_DEFAULT_MODE}"
38
+    if test -d "$src";
39
+    then
40
+        cp -Tvr "$src" "$dst"
41
+        find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
42
+    else
43
+        command -p install -DTvm "$mode" "$src" "$dst"
44
+    fi
45
+}
46
+
4
 get_dst() {
47
 get_dst() {
5
     #
48
     #
6
     # Find out target path for src file $2 of group $1
49
     # Find out target path for src file $2 of group $1
7
     #
50
     #
8
     local grp=$1
51
     local grp=$1
9
     local src=$2
52
     local src=$2
10
-    echo "$(get_root $grp)/$(ini 1value "files:$grp:$src")"
53
+    echo "$(get_root "$grp")/$(ini 1value "files:$grp:$src")"
11
 }
54
 }
12
 
55
 
13
 get_root() {
56
 get_root() {
24
     #
67
     #
25
     # Install product
68
     # Install product
26
     #
69
     #
70
+    check_env
27
     local dst group mode src
71
     local dst group mode src
28
     ini values "lists:group" \
72
     ini values "lists:group" \
29
       | while read group;
73
       | while read group;
30
         do
74
         do
31
             mode=$(ini 1value "modes:$group")
75
             mode=$(ini 1value "modes:$group")
32
-            mode=${mode:-$MKIT_DEFAULT_MODE}
33
             ini lskeys "files:$group" \
76
             ini lskeys "files:$group" \
34
               | while read src;
77
               | while read src;
35
                 do
78
                 do
36
                     dst=$(get_dst "$group" "$src")
79
                     dst=$(get_dst "$group" "$src")
37
-                    command -p install -DTvm $mode $src "$dst"
80
+                    deploy_item "$src" "$dst" "$mode"
38
                 done
81
                 done
39
         done
82
         done
40
-    test -f .autoclean && clean || :
83
+    test -f .autoclean && clean
84
+    true
41
 }
85
 }
42
 
86
 
43
 uninstall() {
87
 uninstall() {
44
     #
88
     #
45
     # Uninstall product
89
     # Uninstall product
46
     #
90
     #
91
+    check_env
47
     local dst group src
92
     local dst group src
48
     ini values "lists:group" \
93
     ini values "lists:group" \
49
       | while read group;
94
       | while read group;
52
               | while read src;
97
               | while read src;
53
                 do
98
                 do
54
                     dst=$(get_dst "$group" "$src")
99
                     dst=$(get_dst "$group" "$src")
55
-                    rm -vf "$dst"
100
+                    rm -vrf "$dst"
56
                 done
101
                 done
57
         done
102
         done
58
 }
103
 }

+ 10
- 10
utils/mkit/include/ini.sh 파일 보기

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

+ 10
- 13
utils/mkit/include/mkit.sh 파일 보기

1
 #!/bin/bash
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
 MKIT_INI=${MKIT_INI:-mkit.ini}
8
 MKIT_INI=${MKIT_INI:-mkit.ini}
9
 MKIT_INI_EXPAND=2
9
 MKIT_INI_EXPAND=2
15
     #
15
     #
16
     # Do basic initialization
16
     # Do basic initialization
17
     #
17
     #
18
-    # Check for ini file, load variables from config.mk, resolve
19
-    # and check for PREFIX
18
+    # Check for ini file, load variables from config.mk
20
     #
19
     #
21
     test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
20
     test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
22
     tmp=$(mktemp)
21
     tmp=$(mktemp)
23
-    sed -e 's/ = /=/' < config.mk > $tmp
24
-    . $tmp
25
-    rm -f $tmp
26
-    PREFIX="$(readlink -f "$PREFIX")"
27
-    test -d "$PREFIX" || die "PREFIX points to bad directory: $PREFIX"
22
+    sed -e 's/ = /=/' < config.mk > "$tmp"
23
+    . "$tmp"
24
+    rm -f "$tmp"
28
 }
25
 }
29
 
26
 
30
 die() {
27
 die() {
31
     #
28
     #
32
     # Exit with message and non-zero exit status
29
     # Exit with message and non-zero exit status
33
     #
30
     #
34
-    echo "fatal: $@" >&2
31
+    echo "fatal: $*" >&2
35
     exit 4
32
     exit 4
36
 }
33
 }
37
 
34
 
51
             $1
48
             $1
52
             ;;
49
             ;;
53
         *)
50
         *)
54
-            echo "usage: $(basename $0) build|clean|dist|install|uninstall" >&2
51
+            echo "usage: $(basename "$0") build|clean|dist|install|uninstall" >&2
55
     esac
52
     esac
56
 }
53
 }

+ 11
- 8
utils/mkit/include/release.sh 파일 보기

13
         z) new="$oldx.$oldy.$((oldz+1))"    ;;
13
         z) new="$oldx.$oldy.$((oldz+1))"    ;;
14
         *) die "invalid release level: $1"  ;;
14
         *) die "invalid release level: $1"  ;;
15
     esac
15
     esac
16
-    echo $new
16
+    echo "$new"
17
 }
17
 }
18
 
18
 
19
 __release() {
19
 __release() {
30
     git rev-parse HEAD >&/dev/null || die "cannot release outside git repo"
30
     git rev-parse HEAD >&/dev/null || die "cannot release outside git repo"
31
     local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD)
31
     local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD)
32
     local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
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
     local curbranch=$(git rev-parse --abbrev-ref HEAD)
34
     local curbranch=$(git rev-parse --abbrev-ref HEAD)
35
     local dirt="$(git diff --shortstat 2>/dev/null)"
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
     local newtag=v$newver
38
     local newtag=v$newver
39
     local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1)
39
     local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1)
40
 
40
 
41
+    test "$lastfile" = config.mk \
42
+     || die "last change must be version bump in config.mk"
43
+
44
+    test -n "$lasttag" \
45
+     || die "cannot find last tag"
46
+
41
     test "$newtag" = "$higher" \
47
     test "$newtag" = "$higher" \
42
      || die "generated tag looks older: $oldtag<$newtag"
48
      || die "generated tag looks older: $oldtag<$newtag"
43
 
49
 
44
     grep -qw "$newver" config.mk \
50
     grep -qw "$newver" config.mk \
45
      || die "new version not in config.mk: $newver"
51
      || die "new version not in config.mk: $newver"
46
 
52
 
47
-    test -n "$lasttag" \
48
-     || die "cannot find last tag"
49
-
50
     grep '^....... WIP ' <<<"$changelog" \
53
     grep '^....... WIP ' <<<"$changelog" \
51
      && die "WIP commit since $lasttag"
54
      && die "WIP commit since $lasttag"
52
 
55
 
59
     # FIXME: Have user prepare proper message with changelog
62
     # FIXME: Have user prepare proper message with changelog
60
 
63
 
61
     set -e
64
     set -e
62
-    git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" $newtag
63
-    git branch -f $RELDST $newtag
65
+    git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag"
66
+    git branch -f "$RELDST" "$newtag"
64
 }
67
 }
65
 
68
 
66
 release_x() {
69
 release_x() {

+ 1
- 1
utils/mkit/make 파일 보기

8
 
8
 
9
 export MKIT_DIR=${MKIT_DIR:-mkit}
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
 mkit_init
13
 mkit_init
14
 
14