Procházet zdrojové kódy

Naming convention: Sort functions aplhabetically

Alois Mahdal před 9 roky
rodič
revize
71468517c9
5 změnil soubory, kde provedl 216 přidání a 215 odebrání
  1. 101
    100
      src/include/build.sh
  2. 14
    14
      src/include/deploy.sh
  3. 19
    19
      src/include/ini.sh
  4. 48
    48
      src/include/mkit.sh
  5. 34
    34
      src/include/release.sh

+ 101
- 100
src/include/build.sh Zobrazit soubor

@@ -3,18 +3,6 @@
3 3
 . "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
4 4
 
5 5
 
6
-build() {
7
-    #
8
-    # Add meat to all skeletons
9
-    #
10
-    local srcpath
11
-    find src -type f -name '*.skel' \
12
-     | while read srcpath;
13
-       do
14
-           _build1 "$srcpath"
15
-       done
16
-}
17
-
18 6
 _build1() {
19 7
     #
20 8
     # Process one skeleton
@@ -30,6 +18,73 @@ _build1() {
30 18
     echo "$dstpath" >> "$MKIT_LOCAL/built.lst"
31 19
 }
32 20
 
21
+_build1_ftype() {
22
+    #
23
+    # Build a file of type $1
24
+    #
25
+    local ftype="$1"
26
+    case $ftype in
27
+        MKIT_COMMON)    _expand_variables "vars" ;;
28
+        markdown)       _expand_includes | _expand_variables "vars" ;;
29
+        rpmstuff)       _expand_variables "vars" "rpmstuff:vars" ;;
30
+        *)              die "unknown file type: $ftype" ;;
31
+    esac
32
+}
33
+
34
+_expand_includes() {
35
+    #
36
+    # Expand include directives
37
+    #
38
+    # Expand e.g. `<!-- include4: foo.sh -->` to include code of foo.sh
39
+    #
40
+    perl -we '
41
+        use strict;
42
+        my $text;
43
+        while (<>) {
44
+            chomp;
45
+            if (m/<!-- include4: (\S+) -->/) {
46
+                open my $fh, $1 or warn "cannot find: $1";
47
+                my $text = do { local($/); <$fh> };
48
+                close $fh;
49
+                $text =~ s/^(.)/    $1/gm;
50
+                chomp $text;
51
+                print "$text\n";
52
+            } else {
53
+                print "$_\n";
54
+            }
55
+        }
56
+    '
57
+}
58
+
59
+_expand_variables() {
60
+    #
61
+    # Expand variables from sections $@
62
+    #
63
+    local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
64
+    local section varname varvalue
65
+    {
66
+        for section in "$@";
67
+        do
68
+            debug_var section
69
+            ini lskeys "$section" \
70
+              | while read varname;
71
+                do
72
+                    varvalue="$(ini 1value "$section:$varname" | sed -e 's/\$/\\$/' )"
73
+                    echo "s|$varname|$varvalue|g;"
74
+                    debug_var varname varvalue
75
+                done
76
+        done
77
+        echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name)|g;"
78
+        echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename)|g;"
79
+        echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname)|g;"
80
+        echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline)|g;"
81
+        echo "s|__MKIT_PROJ_VERSION__|$(get_version)|g;"
82
+        echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
83
+    } >> "$script"
84
+    perl -wp "$script" || die "_expand_variables failed"
85
+    rm "$script"
86
+}
87
+
33 88
 _guess_ftype() {
34 89
     #
35 90
     # Guess file type from destination path $1
@@ -41,17 +96,17 @@ _guess_ftype() {
41 96
     esac
42 97
 }
43 98
 
44
-_build1_ftype() {
99
+
100
+build() {
45 101
     #
46
-    # Build a file of type $1
102
+    # Add meat to all skeletons
47 103
     #
48
-    local ftype="$1"
49
-    case $ftype in
50
-        MKIT_COMMON)    _expand_variables "vars" ;;
51
-        markdown)       _expand_includes | _expand_variables "vars" ;;
52
-        rpmstuff)       _expand_variables "vars" "rpmstuff:vars" ;;
53
-        *)              die "unknown file type: $ftype" ;;
54
-    esac
104
+    local srcpath
105
+    find src -type f -name '*.skel' \
106
+     | while read srcpath;
107
+       do
108
+           _build1 "$srcpath"
109
+       done
55 110
 }
56 111
 
57 112
 build_manpages() {
@@ -85,25 +140,6 @@ clean() {
85 140
     true
86 141
 }
87 142
 
88
-dist() {
89
-    #
90
-    # Create distributable tarball
91
-    #
92
-    #FIXME: lacking Makefile skills, we do this step twice fot
93
-    #       rpmstuff, hence -f hack for gzip
94
-    #
95
-    local version=$(get_version)
96
-    local dirname=$MKIT_PROJ_PKGNAME-$version
97
-    mkdir -p "$dirname"
98
-    ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
99
-    update_version "$version" "$dirname/mkit.ini"
100
-    tar -cf "$dirname.tar" "$dirname"
101
-    gzip -f "$dirname.tar"      # see above FIXME
102
-    mkdir -p "$MKIT_LOCAL"
103
-    echo "$dirname.tar.gz" >> "$MKIT_LOCAL/built.lst"
104
-    rm -rf "$dirname"
105
-}
106
-
107 143
 debstuff() {
108 144
     #
109 145
     # Build Debian stuff (eamed tarball, debian dir)
@@ -134,69 +170,23 @@ debstuff() {
134 170
     echo debian >> "$MKIT_LOCAL/built.lst"
135 171
 }
136 172
 
137
-rpmstuff() {
138
-    #
139
-    # Build specfile
140
-    #
141
-    local specname="$MKIT_PROJ_PKGNAME.spec"
142
-    local specsrc="$(ini 1value "rpmstuff:spec_skel")"
143
-    test -n "$specsrc" || die "rpmstuff:spec_skel not specified"
144
-    test -f "$specsrc" || die "specfile template not found: $specsrc"
145
-    _build1 "$specsrc" "$specname"
146
-}
147
-
148
-_expand_includes() {
149
-    #
150
-    # Expand include directives
151
-    #
152
-    # Expand e.g. `<!-- include4: foo.sh -->` to include code of foo.sh
173
+dist() {
153 174
     #
154
-    perl -we '
155
-        use strict;
156
-        my $text;
157
-        while (<>) {
158
-            chomp;
159
-            if (m/<!-- include4: (\S+) -->/) {
160
-                open my $fh, $1 or warn "cannot find: $1";
161
-                my $text = do { local($/); <$fh> };
162
-                close $fh;
163
-                $text =~ s/^(.)/    $1/gm;
164
-                chomp $text;
165
-                print "$text\n";
166
-            } else {
167
-                print "$_\n";
168
-            }
169
-        }
170
-    '
171
-}
172
-
173
-_expand_variables() {
175
+    # Create distributable tarball
174 176
     #
175
-    # Expand variables from sections $@
177
+    #FIXME: lacking Makefile skills, we do this step twice fot
178
+    #       rpmstuff, hence -f hack for gzip
176 179
     #
177
-    local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
178
-    local section varname varvalue
179
-    {
180
-        for section in "$@";
181
-        do
182
-            debug_var section
183
-            ini lskeys "$section" \
184
-              | while read varname;
185
-                do
186
-                    varvalue="$(ini 1value "$section:$varname" | sed -e 's/\$/\\$/' )"
187
-                    echo "s|$varname|$varvalue|g;"
188
-                    debug_var varname varvalue
189
-                done
190
-        done
191
-        echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name)|g;"
192
-        echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename)|g;"
193
-        echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname)|g;"
194
-        echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline)|g;"
195
-        echo "s|__MKIT_PROJ_VERSION__|$(get_version)|g;"
196
-        echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
197
-    } >> "$script"
198
-    perl -wp "$script" || die "_expand_variables failed"
199
-    rm "$script"
180
+    local version=$(get_version)
181
+    local dirname=$MKIT_PROJ_PKGNAME-$version
182
+    mkdir -p "$dirname"
183
+    ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
184
+    update_version "$version" "$dirname/mkit.ini"
185
+    tar -cf "$dirname.tar" "$dirname"
186
+    gzip -f "$dirname.tar"      # see above FIXME
187
+    mkdir -p "$MKIT_LOCAL"
188
+    echo "$dirname.tar.gz" >> "$MKIT_LOCAL/built.lst"
189
+    rm -rf "$dirname"
200 190
 }
201 191
 
202 192
 get_version() {
@@ -280,3 +270,14 @@ get_version() {
280 270
     fi
281 271
     echo "$version"
282 272
 }
273
+
274
+rpmstuff() {
275
+    #
276
+    # Build specfile
277
+    #
278
+    local specname="$MKIT_PROJ_PKGNAME.spec"
279
+    local specsrc="$(ini 1value "rpmstuff:spec_skel")"
280
+    test -n "$specsrc" || die "rpmstuff:spec_skel not specified"
281
+    test -f "$specsrc" || die "specfile template not found: $specsrc"
282
+    _build1 "$specsrc" "$specname"
283
+}

+ 14
- 14
src/include/deploy.sh Zobrazit soubor

@@ -1,19 +1,5 @@
1 1
 #!/bin/bash
2 2
 
3
-_maybe() {
4
-    #
5
-    # Call the deploy command $1 $@ unless in dry mode
6
-    #
7
-    debug "$@"
8
-    local cmd="$1"; shift
9
-    $MKIT_DRY && return
10
-    case "$cmd" in
11
-        cp|rm|rmdir|chmod|mkdir) $cmd "$@" ;;
12
-        install)                 command -p install "$@" ;;
13
-        *)                       die "bad command called";;
14
-    esac
15
-}
16
-
17 3
 _deploy_item() {
18 4
     #
19 5
     # Deploy item and make it look like wanted
@@ -78,6 +64,20 @@ _get_root() {
78 64
     esac
79 65
 }
80 66
 
67
+_maybe() {
68
+    #
69
+    # Call the deploy command $1 $@ unless in dry mode
70
+    #
71
+    debug "$@"
72
+    local cmd="$1"; shift
73
+    $MKIT_DRY && return
74
+    case "$cmd" in
75
+        cp|rm|rmdir|chmod|mkdir) $cmd "$@" ;;
76
+        install)                 command -p install "$@" ;;
77
+        *)                       die "bad command called";;
78
+    esac
79
+}
80
+
81 81
 install() {
82 82
     #
83 83
     # Install product

+ 19
- 19
src/include/ini.sh Zobrazit soubor

@@ -1,24 +1,5 @@
1 1
 #!/bin/bash
2 2
 
3
-ini() {
4
-    #
5
-    # do ini operation
6
-    #
7
-    local op=$1
8
-    local arg=$2
9
-    local fn
10
-    local limit=_ini_cat
11
-    debug_var op arg
12
-    case $op in
13
-        lskeys) fn=_ini_lskeys   ;;
14
-        sec)    fn=_ini_grepsec  ;;
15
-        values) fn=_ini_greppath ;;
16
-        1value) fn=_ini_greppath; limit="tail -1" ;;
17
-        *)      die "incorrect use of \`ini()\`"
18
-    esac
19
-    <"$MKIT_INI" $fn "$arg" | $limit
20
-}
21
-
22 3
 _ini_cat() {
23 4
     #
24 5
     # A no-op for text stream
@@ -121,3 +102,22 @@ _ini_maybe_expand() {
121 102
         _ini_cat
122 103
     fi
123 104
 }
105
+
106
+ini() {
107
+    #
108
+    # do ini operation
109
+    #
110
+    local op=$1
111
+    local arg=$2
112
+    local fn
113
+    local limit=_ini_cat
114
+    debug_var op arg
115
+    case $op in
116
+        lskeys) fn=_ini_lskeys   ;;
117
+        sec)    fn=_ini_grepsec  ;;
118
+        values) fn=_ini_greppath ;;
119
+        1value) fn=_ini_greppath; limit="tail -1" ;;
120
+        *)      die "incorrect use of \`ini()\`"
121
+    esac
122
+    <"$MKIT_INI" $fn "$arg" | $limit
123
+}

+ 48
- 48
src/include/mkit.sh Zobrazit soubor

@@ -5,6 +5,31 @@
5 5
 . "$MKIT_DIR/include/release.sh" || die "cannot import release.sh"
6 6
 . "$MKIT_DIR/include/ini.sh"    || die "cannot import ini.sh"
7 7
 
8
+MKIT_INI=${MKIT_INI:-mkit.ini}
9
+MKIT_INI_EXPAND=2
10
+MKIT_PROJ_PKGNAME=""
11
+MKIT_DEFAULT_MODE="644"
12
+
13
+_valid_targets() {
14
+    #
15
+    # List valid routes
16
+    #
17
+    echo build
18
+    echo build_manpages
19
+    echo clean
20
+    echo debstuff
21
+    echo dist
22
+    echo install
23
+    echo release_x
24
+    echo release_y
25
+    echo release_z
26
+    echo rpmstuff
27
+    echo uninstall
28
+    echo vbump_x
29
+    echo vbump_y
30
+    echo vbump_z
31
+}
32
+
8 33
 debug() {
9 34
     #
10 35
     # Print debug message
@@ -30,10 +55,13 @@ debug_var() {
30 55
     done
31 56
 }
32 57
 
33
-MKIT_INI=${MKIT_INI:-mkit.ini}
34
-MKIT_INI_EXPAND=2
35
-MKIT_PROJ_PKGNAME=""
36
-MKIT_DEFAULT_MODE="644"
58
+die() {
59
+    #
60
+    # Exit with message and non-zero exit status
61
+    #
62
+    echo "fatal: $*" >&2
63
+    exit 4
64
+}
37 65
 
38 66
 mkit_init() {
39 67
     #
@@ -47,19 +75,21 @@ mkit_init() {
47 75
      || die "MKIT_LOCAL must be non-blank: '$MKIT_LOCAL'"
48 76
 }
49 77
 
50
-die() {
51
-    #
52
-    # Exit with message and non-zero exit status
53
-    #
54
-    echo "fatal: $*" >&2
55
-    exit 4
56
-}
57
-
58
-warn() {
78
+route() {
59 79
     #
60
-    # Print warning message
80
+    # Call correct function based on $1
61 81
     #
62
-    echo "$@" >&2
82
+    if _valid_targets | grep -qwx "^$1";
83
+    then
84
+        "$1"
85
+    else
86
+        {
87
+            echo "usage: $(basename "$0") TARGET"
88
+            echo
89
+            echo "valid targets:"
90
+            _valid_targets | sed 's/^/    /'
91
+        } >&2
92
+    fi
63 93
 }
64 94
 
65 95
 update_version() {
@@ -83,39 +113,9 @@ update_version() {
83 113
     mv "$tmp" "$inifile"
84 114
 }
85 115
 
86
-route() {
87
-    #
88
-    # Call correct function based on $1
89
-    #
90
-    if _valid_targets | grep -qwx "^$1";
91
-    then
92
-        "$1"
93
-    else
94
-        {
95
-            echo "usage: $(basename "$0") TARGET"
96
-            echo
97
-            echo "valid targets:"
98
-            _valid_targets | sed 's/^/    /'
99
-        } >&2
100
-    fi
101
-}
102
-
103
-_valid_targets() {
116
+warn() {
104 117
     #
105
-    # List valid routes
118
+    # Print warning message
106 119
     #
107
-    echo build
108
-    echo build_manpages
109
-    echo clean
110
-    echo debstuff
111
-    echo dist
112
-    echo install
113
-    echo release_x
114
-    echo release_y
115
-    echo release_z
116
-    echo rpmstuff
117
-    echo uninstall
118
-    echo vbump_x
119
-    echo vbump_y
120
-    echo vbump_z
120
+    echo "$@" >&2
121 121
 }

+ 34
- 34
src/include/release.sh Zobrazit soubor

@@ -58,17 +58,17 @@ _git_info() {
58 58
     esac
59 59
 }
60 60
 
61
-_ver_info() {
62
-    #
63
-    # Get git info $1
64
-    #
65
-    local info="$1"
66
-    case "$info" in
67
-        lastver_g)  _git_info lasttag | sed s/^v// ;;
68
-        nextver_g)  _make_ver "$level" "$(_ver_info lastver_g)" ;;
69
-        currver_c)  ini 1value project:version ;;
70
-        nextver_c)  _make_ver "$level" "$(_ver_info currver_c)" ;;
71
-    esac
61
+_git_msg_vbump() {
62
+    echo "Bump version"
63
+    echo ""
64
+    echo "Overview of changes:"
65
+    echo ""
66
+    _git_info reldiff \
67
+      | sed '
68
+            s/^[a-f0-9]\{7\} / *  &/; t PATHS
69
+            s/^/        /
70
+            :PATHS
71
+        '
72 72
 }
73 73
 
74 74
 _make_ver() {
@@ -116,19 +116,6 @@ _release() {
116 116
     git branch -f "$(ini 1value project:reldst)" "$newtag"
117 117
 }
118 118
 
119
-_git_msg_vbump() {
120
-    echo "Bump version"
121
-    echo ""
122
-    echo "Overview of changes:"
123
-    echo ""
124
-    _git_info reldiff \
125
-      | sed '
126
-            s/^[a-f0-9]\{7\} / *  &/; t PATHS
127
-            s/^/        /
128
-            :PATHS
129
-        '
130
-}
131
-
132 119
 _vbump() {
133 120
     local level="$1"
134 121
     local lastver   # current from mkit.ini
@@ -147,16 +134,17 @@ _vbump() {
147 134
     git commit -e -m "$(_git_msg_vbump)"
148 135
 }
149 136
 
150
-vbump_x() {
151
-    _vbump x
152
-}
153
-
154
-vbump_y() {
155
-    _vbump y
156
-}
157
-
158
-vbump_z() {
159
-    _vbump z
137
+_ver_info() {
138
+    #
139
+    # Get git info $1
140
+    #
141
+    local info="$1"
142
+    case "$info" in
143
+        lastver_g)  _git_info lasttag | sed s/^v// ;;
144
+        nextver_g)  _make_ver "$level" "$(_ver_info lastver_g)" ;;
145
+        currver_c)  ini 1value project:version ;;
146
+        nextver_c)  _make_ver "$level" "$(_ver_info currver_c)" ;;
147
+    esac
160 148
 }
161 149
 
162 150
 release_x() {
@@ -170,3 +158,15 @@ release_y() {
170 158
 release_z() {
171 159
     _release z
172 160
 }
161
+
162
+vbump_x() {
163
+    _vbump x
164
+}
165
+
166
+vbump_y() {
167
+    _vbump y
168
+}
169
+
170
+vbump_z() {
171
+    _vbump z
172
+}