Browse Source

Update own dogfood

Alois Mahdal 7 years ago
parent
commit
0b0009eafa
4 changed files with 197 additions and 97 deletions
  1. 1
    0
      utils/mkit/include/build.sh
  2. 1
    1
      utils/mkit/include/ini.sh
  3. 1
    1
      utils/mkit/include/vars.sh
  4. 194
    95
      utils/mkit/stub

+ 1
- 0
utils/mkit/include/build.sh View File

81
         done
81
         done
82
         echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name | _qfs)|g;"
82
         echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name | _qfs)|g;"
83
         echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename | _qfs)|g;"
83
         echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename | _qfs)|g;"
84
+        echo "s|__MKIT_PROJ_LICENSE__|$(ini 1value project:license | _qfs)|g;"
84
         echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname | _qfs)|g;"
85
         echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname | _qfs)|g;"
85
         echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline | _qfs)|g;"
86
         echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline | _qfs)|g;"
86
         echo "s|__MKIT_PROJ_MAINTAINER__|$(ini 1value project:maintainer | _qfs)|g;"
87
         echo "s|__MKIT_PROJ_MAINTAINER__|$(ini 1value project:maintainer | _qfs)|g;"

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

90
     # List keys from a section
90
     # List keys from a section
91
     #
91
     #
92
     local sct=$1    # section of interest
92
     local sct=$1    # section of interest
93
-    _ini_grepsec "$sct" | cut -d= -f1 | sort | uniq
93
+    _ini_grepsec "$sct" | cut -d= -f1 | awk '!x[$0]++'
94
 }
94
 }
95
 
95
 
96
 _ini_maybe_expand() {
96
 _ini_maybe_expand() {

+ 1
- 1
utils/mkit/include/vars.sh View File

57
 #
57
 #
58
 # This MKit version
58
 # This MKit version
59
 #
59
 #
60
-MKIT_VERSION=0.0.20+devel.g7c137e5
60
+MKIT_VERSION=0.0.21+HEAD.g47f8848

utils/mkit/newstub → utils/mkit/stub View File

21
 
21
 
22
 init_core
22
 init_core
23
 
23
 
24
-declare -A MKIT_INIT_LICENSES
25
-MKIT_INIT_LICENSES[GPLv1]="http://www.gnu.org/licenses/old-licenses/gpl-1.0.md"
26
-MKIT_INIT_LICENSES[GPLv2]="http://www.gnu.org/licenses/old-licenses/gpl-2.0.md"
27
-MKIT_INIT_LICENSES[GPLv3]="http://www.gnu.org/licenses/gpl-3.0.md"
28
-MKIT_INIT_LICENSES[LGPLv2]="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.md"
29
-MKIT_INIT_LICENSES[LGPLv3]="http://www.gnu.org/licenses/lgpl-3.0.md"
30
-MKIT_INIT_LICENSES[AGPLv3]="http://www.gnu.org/licenses/agpl-3.0.md"
31
-MKIT_INIT_LICENSES[FDLv1.3]="http://www.gnu.org/licenses/fdl-1.3.md"
32
-MKIT_INIT_LICENSES[FDLv1.2]="http://www.gnu.org/licenses/old-licenses/fdl-1.2.md"
33
-MKIT_INIT_LICENSES[FDLv1.1]="http://www.gnu.org/licenses/old-licenses/fdl-1.1.md"
24
+mkit_import ini
25
+
26
+declare -A MKIT_STUB_LICENSES
27
+MKIT_STUB_LICENSES[GPLv1]="http://www.gnu.org/licenses/old-licenses/gpl-1.0.md"
28
+MKIT_STUB_LICENSES[GPLv2]="http://www.gnu.org/licenses/old-licenses/gpl-2.0.md"
29
+MKIT_STUB_LICENSES[GPLv3]="http://www.gnu.org/licenses/gpl-3.0.md"
30
+MKIT_STUB_LICENSES[LGPLv2]="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.md"
31
+MKIT_STUB_LICENSES[LGPLv3]="http://www.gnu.org/licenses/lgpl-3.0.md"
32
+MKIT_STUB_LICENSES[AGPLv3]="http://www.gnu.org/licenses/agpl-3.0.md"
33
+MKIT_STUB_LICENSES[FDLv1.3]="http://www.gnu.org/licenses/fdl-1.3.md"
34
+MKIT_STUB_LICENSES[FDLv1.2]="http://www.gnu.org/licenses/old-licenses/fdl-1.2.md"
35
+MKIT_STUB_LICENSES[FDLv1.1]="http://www.gnu.org/licenses/old-licenses/fdl-1.1.md"
34
 
36
 
35
 
37
 
36
 deploy() {
38
 deploy() {
37
     local file=$1       # which known file?
39
     local file=$1       # which known file?
38
     local any_name=${NiceName:-$PackageName}
40
     local any_name=${NiceName:-$PackageName}
41
+    local tmp
42
+    tmp=$(mktemp -t mkit.stub.deploy.XXXXXXX)
39
     mkdir -p "$(dirname "$file")"
43
     mkdir -p "$(dirname "$file")"
40
     case $file in
44
     case $file in
41
 
45
 
62
             fi
66
             fi
63
             ;;
67
             ;;
64
 
68
 
65
-        mkit.ini)
66
-            echo "#mkit version=$MKIT_VERSION"
67
-            echo ""
69
+        */mkit.ini|mkit.ini)
68
             echo "[project]"
70
             echo "[project]"
69
-            echo "    version     = 0.0.0"
71
+            echo "    version     = $Version"
70
             test -n "$Codename"     && echo "    codename    = $Codename"
72
             test -n "$Codename"     && echo "    codename    = $Codename"
71
             test -n "$NiceName"     && echo "    name        = $NiceName"
73
             test -n "$NiceName"     && echo "    name        = $NiceName"
72
             test -n "$Tagline"      && echo "    tagline     = $Tagline"
74
             test -n "$Tagline"      && echo "    tagline     = $Tagline"
75
             test -n "$VcsBrowser"   && echo "    vcs_browser = $VcsBrowser"
77
             test -n "$VcsBrowser"   && echo "    vcs_browser = $VcsBrowser"
76
             test -n "$RelSrc"       && echo "    relsrc      = $RelSrc"
78
             test -n "$RelSrc"       && echo "    relsrc      = $RelSrc"
77
             test -n "$RelDst"       && echo "    reldst      = $RelDst"
79
             test -n "$RelDst"       && echo "    reldst      = $RelDst"
80
+            if updating; then
81
+                remake_section dist
82
+                remake_section ENV
83
+                remake_section roots
84
+                remake_section tokens
85
+                remake_section modes
86
+                remake_section files
87
+            else
88
+                echo ""
89
+                echo "[dist]"
90
+                $MkLicense  && echo "    tarball = LICENSE.md"
91
+                $MkMakefile && echo "    tarball = Makefile"
92
+                $MkReadme   && echo "    tarball = README.md"
93
+                echo "    tarball = mkit.ini"
94
+                $MkPackaging && echo "    tarball = packaging"
95
+                echo "    tarball = src"
96
+                echo "    tarball = tests"
97
+                echo "    tarball = utils"
98
+                $MkPackaging && echo "    rpmstuff = packaging/template.spec"
99
+                $MkPackaging && echo "    debstuff = packaging/debian"
100
+                echo ""
101
+                echo "[ENV]"
102
+                echo "    PREFIX = /usr/local"
103
+                echo ""
104
+                echo "[roots]"
105
+                echo "    bin     = [ENV:PREFIX]/bin"
106
+                echo "    doc     = [ENV:PREFIX]/share/doc/$PackageName"
107
+                echo ""
108
+                echo "[tokens]"
109
+                echo "    __BIN_DIR__ = [roots:bin]"
110
+                echo ""
111
+                echo "[modes]"
112
+                echo "    bin     = 755"
113
+                echo "    doc     = 644"
114
+                echo ""
115
+                echo "[files]"
116
+                echo "    bin      = src/$PackageName"
117
+                $MkLicense && echo "    doc      = LICENSE.md"
118
+                $MkReadme  && echo "    doc      = README.md"
119
+            fi
78
             echo ""
120
             echo ""
79
-            echo "[dist]"
80
-            echo "    tarball = LICENSE.md"
81
-            $MkMakefile && echo "    tarball = Makefile"
82
-            $MkReadme   && echo "    tarball = README.md"
83
-            echo "    tarball = mkit.ini"
84
-            $MkPackaging && echo "    tarball = packaging"
85
-            echo "    tarball = src"
86
-            echo "    tarball = tests"
87
-            echo "    tarball = utils"
88
-            $MkPackaging && echo "    rpmstuff = packaging/template.spec"
89
-            $MkPackaging && echo "    debstuff = packaging/debian"
90
-            echo ""
91
-            echo "[ENV]"
92
-            echo "    PREFIX = /usr/local"
93
-            echo ""
94
-            echo "[roots]"
95
-            echo "    bin     = [ENV:PREFIX]/bin"
96
-            echo "    doc     = [ENV:PREFIX]/share/doc/$PackageName"
97
-            echo ""
98
-            echo "[tokens]"
99
-            echo "    __BIN_DIR__ = [roots:bin]"
100
-            echo ""
101
-            echo "[modes]"
102
-            echo "    bin     = 755"
103
-            echo "    doc     = 644"
104
-            echo ""
105
-            echo "[files]"
106
-            echo "    bin      = src/$PackageName"
107
-            $MkReadme && echo "    doc      = LICENSE.md"
108
-            test -n "$License" && echo "    doc      = README.md"
121
+            echo "#mkit version=$MKIT_VERSION"
109
             ;;
122
             ;;
110
 
123
 
111
         packaging/template.spec)
124
         packaging/template.spec)
114
             echo 'Release:	1%{?dist}'
127
             echo 'Release:	1%{?dist}'
115
             echo 'Summary:	__MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
128
             echo 'Summary:	__MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
116
             echo ''
129
             echo ''
117
-            echo "License:	$License"
130
+            $MkLicense && echo "License:	$License"
118
             echo 'Source0:	%{name}-%{version}.tar.gz'
131
             echo 'Source0:	%{name}-%{version}.tar.gz'
119
             echo ''
132
             echo ''
120
             echo 'BuildArch:	noarch'
133
             echo 'BuildArch:	noarch'
121
             echo 'BuildRequires:	coreutils git'
134
             echo 'BuildRequires:	coreutils git'
122
-            echo 'Requires:	MKIT_NEWSTUB_REQUIRES'
135
+            echo 'Requires:	MKIT_STUB_REQUIRES'
123
             echo ''
136
             echo ''
124
             echo '%description'
137
             echo '%description'
125
-            echo 'MKIT_NEWSTUB_DESCRIPTION'
138
+            echo 'MKIT_STUB_DESCRIPTION'
126
             echo ''
139
             echo ''
127
             echo '%prep'
140
             echo '%prep'
128
             echo '%setup -q'
141
             echo '%setup -q'
134
             echo '%make_install'
147
             echo '%make_install'
135
             echo ''
148
             echo ''
136
             echo '%files'
149
             echo '%files'
137
-            echo 'MKIT_NEWSTUB_FILELIST'
150
+            echo 'MKIT_STUB_FILELIST'
138
             echo ''
151
             echo ''
139
             echo '%changelog'
152
             echo '%changelog'
140
             echo ''
153
             echo ''
156
             echo ''
169
             echo ''
157
             echo 'Package: __MKIT_PROJ_PKGNAME__'
170
             echo 'Package: __MKIT_PROJ_PKGNAME__'
158
             echo 'Architecture: all'
171
             echo 'Architecture: all'
159
-            echo 'Depends: MKIT_NEWSTUB_REQUIRES'
172
+            echo 'Depends: MKIT_STUB_REQUIRES'
160
             echo 'Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
173
             echo 'Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
161
-            echo ' MKIT_NEWSTUB_DESCRIPTION'
174
+            echo ' MKIT_STUB_DESCRIPTION'
162
             echo ''
175
             echo ''
163
             echo '# control file built with MKit __MKIT_SELF_VERSION__'
176
             echo '# control file built with MKit __MKIT_SELF_VERSION__'
164
             ;;
177
             ;;
196
             ;;
209
             ;;
197
 
210
 
198
         packaging/debian/*.install)
211
         packaging/debian/*.install)
199
-            echo MKIT_NEWSTUB_FILELIST
212
+            echo MKIT_STUB_FILELIST
200
             ;;
213
             ;;
201
 
214
 
202
         src/*.skel)
215
         src/*.skel)
206
 
219
 
207
         LICENSE.md)
220
         LICENSE.md)
208
             local url   # license URL
221
             local url   # license URL
209
-            url="${MKIT_INIT_LICENSES[$License]}"
222
+            url="${MKIT_STUB_LICENSES[$License]}"
210
             curl -sf "$url" \
223
             curl -sf "$url" \
211
              || die "failed to download license: $url"
224
              || die "failed to download license: $url"
212
             ;;
225
             ;;
214
         .mkit/autoclean)
227
         .mkit/autoclean)
215
             ;;
228
             ;;
216
 
229
 
217
-        MKIT_NEWSTUB_README.md)
230
+        MKIT_STUB_README.md)
218
             echo "FINISHING MKIT CONFIGURATION"
231
             echo "FINISHING MKIT CONFIGURATION"
219
             echo "============================"
232
             echo "============================"
220
             echo ""
233
             echo ""
221
             echo "Congratulations, your new project has been configured!"
234
             echo "Congratulations, your new project has been configured!"
222
             echo ""
235
             echo ""
223
-            echo "However, the *newstub* script is not able to figure out"
236
+            echo "However, the *stub* script is not able to figure out"
224
             echo "everything, so few things still need to be done manually."
237
             echo "everything, so few things still need to be done manually."
225
             echo "This document will guide you throught the rest of the"
238
             echo "This document will guide you throught the rest of the"
226
             echo "process."
239
             echo "process."
278
             echo "Placeholders"
291
             echo "Placeholders"
279
             echo "------------"
292
             echo "------------"
280
             echo ""
293
             echo ""
281
-            echo "At places where *newstub* script did not have way to get all"
294
+            echo "At places where *stub* script did not have way to get all"
282
             echo "information automatically, it has inserted placeholders."
295
             echo "information automatically, it has inserted placeholders."
283
             echo "You will need to go through all of these placeholders and"
296
             echo "You will need to go through all of these placeholders and"
284
             echo "replace them with proper data."
297
             echo "replace them with proper data."
285
             echo ""
298
             echo ""
286
             echo "Please follow instructions:"
299
             echo "Please follow instructions:"
287
             echo ""
300
             echo ""
288
-            echo " 1. Look for placeholders starting with \`MKIT_NEWSTUB_\`"
301
+            echo " 1. Look for placeholders starting with \`MKIT_STUB_\`"
289
             echo "    prefix by calling this command:"
302
             echo "    prefix by calling this command:"
290
             echo ""
303
             echo ""
291
-            echo "        grep -lw MKIT_NEWSTUB_ -r"
304
+            echo "        grep -lw MKIT_STUB_ -r"
292
             echo ""
305
             echo ""
293
             echo " 2. Go through each file and locate the placeholder.  (You"
306
             echo " 2. Go through each file and locate the placeholder.  (You"
294
             echo "    will also see placeholders like \`__MKIT_*__\`, you can"
307
             echo "    will also see placeholders like \`__MKIT_*__\`, you can"
296
             echo ""
309
             echo ""
297
             echo " 3. Replace placeholder with appropriate information:"
310
             echo " 3. Replace placeholder with appropriate information:"
298
             echo ""
311
             echo ""
299
-            echo "     *  \`MKIT_NEWSTUB_REQUIRES\` - Requirements of your"
312
+            echo "     *  \`MKIT_STUB_REQUIRES\` - Requirements of your"
300
             echo "        project."
313
             echo "        project."
301
             echo ""
314
             echo ""
302
-            echo "     *  \`MKIT_NEWSTUB_DESCRIPTION\` - Description of your"
315
+            echo "     *  \`MKIT_STUB_DESCRIPTION\` - Description of your"
303
             echo "        project (few sentences to paragraphs)."
316
             echo "        project (few sentences to paragraphs)."
304
             echo ""
317
             echo ""
305
-            echo "     *  \`MKIT_NEWSTUB_FILELIST\` - List of full paths to"
318
+            echo "     *  \`MKIT_STUB_FILELIST\` - List of full paths to"
306
             echo "        your files after installation."
319
             echo "        your files after installation."
307
             echo ""
320
             echo ""
308
             echo "    Refer to these documents for further details:"
321
             echo "    Refer to these documents for further details:"
399
             echo "Makefile"
412
             echo "Makefile"
400
             echo "--------"
413
             echo "--------"
401
             echo ""
414
             echo ""
402
-            echo "*newstub* script also created a Makefile for you, but all"
415
+            echo "*stub* script also created a Makefile for you, but all"
403
             echo "it really does is include MKit's own mkit.mk, which in turn"
416
             echo "it really does is include MKit's own mkit.mk, which in turn"
404
             echo "only maps \`make\` targets to actual mkit script calls."
417
             echo "only maps \`make\` targets to actual mkit script calls."
405
             echo "Unless your project already uses GNU Make, you should not"
418
             echo "Unless your project already uses GNU Make, you should not"
413
             echo "---------"
426
             echo "---------"
414
             echo ""
427
             echo ""
415
             echo "Each serious project needs a serious README.  Which is why"
428
             echo "Each serious project needs a serious README.  Which is why"
416
-            echo "*newstub* has created a 'stub' of one for you."
429
+            echo "*stub* has created a 'stub' of one for you."
417
             fi
430
             fi
418
 
431
 
419
             echo ""
432
             echo ""
424
             echo "Once you have reviewed everything, just delete this file!"
437
             echo "Once you have reviewed everything, just delete this file!"
425
             ;;
438
             ;;
426
 
439
 
427
-    esac >"$file"
440
+    esac >"$tmp"
441
+    cat "$tmp" > "$file"
442
+    rm "$tmp"
428
 }
443
 }
429
 
444
 
430
 known_licenses() {
445
 known_licenses() {
431
     local key
446
     local key
432
     local first=true
447
     local first=true
433
-    for key in "${!MKIT_INIT_LICENSES[@]}"; do
448
+    for key in "${!MKIT_STUB_LICENSES[@]}"; do
434
         $first && echo "$key"  && continue
449
         $first && echo "$key"  && continue
435
         echo ", $key"
450
         echo ", $key"
436
     done
451
     done
439
 usage() {
454
 usage() {
440
     {
455
     {
441
         echo "Usage:"
456
         echo "Usage:"
442
-        echo "   newstub [options] NAME"
443
-        echo "   newstub -L"
457
+        echo "   stub [options] new PKGNAME"
458
+        echo "   stub [options] update"
459
+        echo "   stub -L"
444
         echo ""
460
         echo ""
445
         echo "Options:"
461
         echo "Options:"
446
         echo ""
462
         echo ""
452
         echo "    -l LICENSE    your options's license (see -L)"
468
         echo "    -l LICENSE    your options's license (see -L)"
453
         echo "    -m MAINT      project maintainer's name and e-mail"
469
         echo "    -m MAINT      project maintainer's name and e-mail"
454
         echo "    -v URL        URL to public code browser"
470
         echo "    -v URL        URL to public code browser"
471
+        echo "    -V VERSION    initial version (default: 0.0.0)"
455
         echo "    -a            enable autoclean ('make clean' after"
472
         echo "    -a            enable autoclean ('make clean' after"
456
         echo "                  each 'make install')"
473
         echo "                  each 'make install')"
457
         echo "    -g            make git commits before and adter"
474
         echo "    -g            make git commits before and adter"
462
         echo "    -P            skip creating packaging templates"
479
         echo "    -P            skip creating packaging templates"
463
         echo "    -L            list know licenses and exit"
480
         echo "    -L            list know licenses and exit"
464
         echo ""
481
         echo ""
465
-        echo "NAME should be packaging-friendly name, ie. consist"
482
+        echo "PKGNAME should be packaging-friendly name, ie. consist"
466
         echo "only of small letters, numbers, underscore and dash."
483
         echo "only of small letters, numbers, underscore and dash."
467
         echo "For your 'real' name, use NICENAME, which can be any"
484
         echo "For your 'real' name, use NICENAME, which can be any"
468
         echo "string."
485
         echo "string."
478
         echo "current codebase.  At least following files will be"
495
         echo "current codebase.  At least following files will be"
479
         echo "created or overwritten:"
496
         echo "created or overwritten:"
480
         echo ""
497
         echo ""
481
-        $MkPackaging        && echo " *  'packaging' directory (pass -P to avoid)"
482
-        $MkMakefile         && echo " *  'Makefile' (pass -M to avoid)"
483
-        $MkReadme           && echo " *  'README.md' (pass -R to avoid)"
484
-        test -n "$License"  && echo " *  'LICENSE.md' (omit -l to avoid)"
498
+        $MkPackaging    && echo " *  'packaging' directory (pass -P to avoid)"
499
+        $MkMakefile     && echo " *  'Makefile' (pass -M to avoid)"
500
+        $MkReadme       && echo " *  'README.md' (pass -R to avoid)"
501
+        $MkLicense      && echo " *  'LICENSE.md' (omit -l to avoid)"
485
         echo " *  'mkit.ini'"
502
         echo " *  'mkit.ini'"
486
         echo ""
503
         echo ""
487
         read -p "Type 'yes' to proceed: " -r response
504
         read -p "Type 'yes' to proceed: " -r response
497
      || { warn "nothing to back up"; return 0; }
514
      || { warn "nothing to back up"; return 0; }
498
     git add .                           || return
515
     git add .                           || return
499
     git rm -r --cached utils/mkit       || return
516
     git rm -r --cached utils/mkit       || return
500
-    git commit -m "WIP [mkit/newstub] backup"   || return
517
+    git commit -m "WIP [mkit/stub] backup" || return
501
 }
518
 }
502
 
519
 
503
 mkcommit_mkit_code() {
520
 mkcommit_mkit_code() {
504
     git ls-files --others \
521
     git ls-files --others \
505
       | grep -q -e '^utils/mkit$' -e '^utils/mkit/' \
522
       | grep -q -e '^utils/mkit$' -e '^utils/mkit/' \
506
      || return 0
523
      || return 0
507
-    git add utils/mkit                                         || return
508
-    git commit -m "WIP [mkit/newstub] Add MKit version v$MKIT_VERSION" || return
524
+    git add utils/mkit || return
525
+    git commit -m "WIP [mkit/stub] Add MKit version v$MKIT_VERSION" || return
509
 }
526
 }
510
 
527
 
511
 mkcommit_mkit_conf() {
528
 mkcommit_mkit_conf() {
512
-    git add .                                                  || return
513
-    git commit -m "WIP [mkit/newstub] Add MKit configuration stub" || return
529
+    local msg       # commit message (the important art
530
+    git add . || return
531
+    case $Action in
532
+        new)    msg="Add MKit configuration stub" ;;
533
+        update) msg="Update MKit configuration"   ;;
534
+    esac
535
+    git commit -m "WIP [mkit/stub] $msg" || return
514
 }
536
 }
515
 
537
 
516
 deploy_packaging() {
538
 deploy_packaging() {
526
     deploy packaging/template.spec
548
     deploy packaging/template.spec
527
 }
549
 }
528
 
550
 
551
+init_from_existing() {
552
+    #
553
+    # Initialize variables from old mkit.ini
554
+    #
555
+    test -f "$MKIT_INI" \
556
+     || die "mkit.ini not found; aborting update: $MKIT_INI"
557
+    user_gave Codename    || Codename=$(ini_raw1v project:codename)
558
+    user_gave License     || License=$(ini_raw1v project:license)
559
+    user_gave Maintainer  || Maintainer=$(ini_raw1v project:maintainer)
560
+    user_gave NiceName    || NiceName=$(ini_raw1v project:name)
561
+    user_gave PackageName || PackageName=$(ini_raw1v project:pkgname)
562
+    user_gave RelDst      || RelDst=$(ini_raw1v project:reldst)
563
+    user_gave RelSrc      || RelSrc=$(ini_raw1v project:relsrc)
564
+    user_gave Tagline     || Tagline=$(ini_raw1v project:tagline)
565
+    user_gave VcsBrowser  || VcsBrowser=$(ini_raw1v project:vcs_browser)
566
+    user_gave Version     || Version=$(ini_raw1v project:version)
567
+}
568
+
569
+ini_raw1v() {
570
+    #
571
+    # Read raw scalar from mkit.ini
572
+    #
573
+    local path=$1
574
+    MKIT_INI_EXPAND=0 ini 1value "$path"
575
+}
576
+
577
+user_gave() {
578
+    #
579
+    # True if user gave value to variable $1
580
+    #
581
+    local var=$1    # name of the variable
582
+    { test "${UserGave[$var]}" == 1; } 2>/dev/null
583
+}
584
+
585
+updating() {
586
+    #
587
+    # Are we updating?
588
+    #
589
+    test "$Action" == update
590
+}
591
+
592
+remake_section() {
593
+    #
594
+    # Re-compose mkit.ini section $1
595
+    #
596
+    local section=$1
597
+    local key
598
+    local value
599
+    ini lskeys "$section" | grep -q . \
600
+     || return 1
601
+    echo ""
602
+    echo "[$section]"
603
+    ini lskeys "$section" \
604
+      | while read -r key; do
605
+            MKIT_INI_EXPAND=0 ini values "$section:$key" \
606
+              | while read -r value; do
607
+                    echo "$key = $value"
608
+                done
609
+        done \
610
+      | column -to' ' \
611
+      | sed 's/^/    /'
612
+}
613
+
529
 main() {
614
 main() {
530
     local NiceName          # human-readable project name
615
     local NiceName          # human-readable project name
531
     local PackageName       # machine-safe project (package) name
616
     local PackageName       # machine-safe project (package) name
535
     local Tagline           # project tagline
620
     local Tagline           # project tagline
536
     local Maintainer        # project maintainer (Name + e-mail)
621
     local Maintainer        # project maintainer (Name + e-mail)
537
     local VcsBrowser        # VCS browser (eg. GitHub URL)
622
     local VcsBrowser        # VCS browser (eg. GitHub URL)
623
+    local Version=0.0.0     # project version
538
     local AutoClean=false   # touch .mkit/autoclean?
624
     local AutoClean=false   # touch .mkit/autoclean?
539
     local MkCommits=false   # create pre/post git commits?
625
     local MkCommits=false   # create pre/post git commits?
540
     local Force=false       # go without asking?
626
     local Force=false       # go without asking?
541
     local MkReadme=true     # create README.md?
627
     local MkReadme=true     # create README.md?
542
     local MkMakefile=true   # create Makefile?
628
     local MkMakefile=true   # create Makefile?
543
     local MkPackaging=true  # create packaging templates?
629
     local MkPackaging=true  # create packaging templates?
630
+    local MkLicense=false   # create LICENSE.md file
631
+    local Action            # 'update' to respect existing, 'new' to force
632
+                            # rewrite incl. MKIT_STUB_* placeholders
633
+    declare -A UserGave
544
     while true; do case $1 in
634
     while true; do case $1 in
545
-        -n) NiceName=$2;        shift 2 || usage ;;
546
-        -b) RelSrc=$2;          shift 2 || usage ;;
547
-        -B) RelDst=$2;          shift 2 || usage ;;
548
-        -c) Codename=$2;        shift 2 || usage ;;
549
-        -t) Tagline=$2;         shift 2 || usage ;;
550
-        -l) License=$2;         shift 2 || usage ;;
551
-        -m) Maintainer=$2;      shift 2 || usage ;;
552
-        -v) VcsBrowser=$2;      shift 2 || usage ;;
635
+        -n) NiceName=$2;   UserGave[NiceName]=1;   shift 2 || usage ;;
636
+        -b) RelSrc=$2;     UserGave[RelSrc]=1;     shift 2 || usage ;;
637
+        -B) RelDst=$2;     UserGave[RelDst]=1;     shift 2 || usage ;;
638
+        -c) Codename=$2;   UserGave[Codename]=1;   shift 2 || usage ;;
639
+        -t) Tagline=$2;    UserGave[Tagline]=1;    shift 2 || usage ;;
640
+        -l) License=$2;    UserGave[License]=1;    shift 2 || usage ;;
641
+        -m) Maintainer=$2; UserGave[Maintainer]=1; shift 2 || usage ;;
642
+        -v) VcsBrowser=$2; UserGave[VcsBrowser]=1; shift 2 || usage ;;
643
+        -V) Version=$2;    UserGave[Version]=1;    shift 2 || usage ;;
553
         -M) MkMakefile=false;   shift ;;
644
         -M) MkMakefile=false;   shift ;;
554
         -R) MkReadme=false;     shift ;;
645
         -R) MkReadme=false;     shift ;;
555
         -a) AutoClean=true;     shift ;;
646
         -a) AutoClean=true;     shift ;;
560
         -*) usage ;;
651
         -*) usage ;;
561
         *)  break ;;
652
         *)  break ;;
562
     esac done
653
     esac done
563
-    PackageName="$1"
564
-    test -n "$PackageName" || usage
565
-    if test -n "$License"; then
654
+    Action=$1; PackageName=$2
655
+    case $Action:$PackageName in
656
+        new:)     usage ;;
657
+        new:*)    :     ;;
658
+        update:)  :     ;;
659
+        update:*) usage ;;
660
+        *)        usage ;;
661
+    esac
662
+    updating && init_from_existing
663
+    if $MkLicense; then
566
         known_licenses | grep -qxF "$License" \
664
         known_licenses | grep -qxF "$License" \
567
          || die "unknown license (use -L to get list): $License"
665
          || die "unknown license (use -L to get list): $License"
666
+        MkLicense=true
568
     fi
667
     fi
569
     if $MkCommits; then
668
     if $MkCommits; then
570
         mkcommit_backup || die "failed creating backup commit"
669
         mkcommit_backup || die "failed creating backup commit"
571
         Force=true
670
         Force=true
572
     fi
671
     fi
573
     confirm            || return 1
672
     confirm            || return 1
574
-    deploy mkit.ini
673
+    deploy "$MKIT_INI"
575
     deploy src/"$PackageName".skel
674
     deploy src/"$PackageName".skel
576
-    $MkMakefile        && deploy Makefile
577
-    $MkReadme          && deploy README.md
578
-    test -n "$License" && deploy LICENSE.md
579
-    $AutoClean         && deploy .mkit/autoclean
580
-    $MkPackaging       && deploy_packaging
675
+    $MkMakefile     && deploy Makefile
676
+    $MkReadme       && deploy README.md
677
+    $MkLicense      && deploy LICENSE.md
678
+    $AutoClean      && deploy .mkit/autoclean
679
+    $MkPackaging    && deploy_packaging
581
     if $MkCommits; then
680
     if $MkCommits; then
582
         mkcommit_mkit_code || die "failed creating post-commit"
681
         mkcommit_mkit_code || die "failed creating post-commit"
583
         mkcommit_mkit_conf || die "failed creating post-commit"
682
         mkcommit_mkit_conf || die "failed creating post-commit"
584
     fi
683
     fi
585
-    deploy MKIT_NEWSTUB_README.md
684
+    deploy MKIT_STUB_README.md
586
     warn "Configuration stub built, follow instructions in"
685
     warn "Configuration stub built, follow instructions in"
587
-    warn "MKIT_NEWSTUB_README.md to finish configuration."
686
+    warn "MKIT_STUB_README.md to finish configuration."
588
     return 0
687
     return 0
589
 }
688
 }
590
 
689