-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure
executable file
·1785 lines (1669 loc) · 61.3 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# ------------------------------------------------------------------------
# Copyright (c) 2015 Simon Arjuna Erat (sea)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For the license of this script, please see:
# <http://www.gnu.org/licenses/gpl.txt>
# ------------------------------------------------------------------------
#
# Idea & Author: Simon Arjuna Erat (sea), Switzerland
# Created: 2015.02.27
# Transformed: 2016.01.15
# Changed: 2016.02.25
script_name="configure"
script_version="2.0.0-alpha-rc1"
script_bugtracker="https://github.com/sri-arjuna/yassi/issues"
#
# Yet Another Simple Script Installer
# -----------------------------------
# YASSI is a bash based installer for projects,
# that simply need to place files on a new system.
#
# However, it allows to 'source' a file to get
# the destinations its absolute paths.
# In addition, as a gimmick, it provides some extra tweaking features,
# which are (but not limited to): texi2any, yassi-dep handler.
# It also aims for portability so you have less to worry about
# wether the installer will work or not.
#
# This script automaticly generates, according to passed options,
# the following files, named to go along with GNU Automake terminology.
# * make
# * make-install
# * make-install-all
# * make-uninstall
# * make-check
# * make-clean
# * make-distclean
# * make-doc-{info,html,dvi,pdf,ps}
# * make-check
# * make-installdirs
# * make-mostlyclean
# * make-maintainer-clean
# * Makefile
#
# Also it will install TUI (Text User Interface, framework for scripts),
# if 'doTUI=true', as I wrote YASSI to distribute TUI,
# and all my projects using TUI.
# I do hope it is as helpfull for you, as it is for me.
#
# If you want to use YASSI to distribute & package your project
# for rpm/apt-get/aur, you must handle the TUI dependency by itself.
#
# This is a one-file-project, therefor its license is remote only,
# as otherwise this script would be double in size.
#
# If you need help to adjust the installation for your system,
# please read: ./configure --help
#
# If you want to apply/use this to your project,
# please read: ./configure --manpage
#
# To report bugs or suggestions about YASSI (configure),
# * please raise an issue on: https://github.com/sri-arjuna/yassi/issues
# * or leave a comment on my blog: http://linux-scripter.blogspot.ch
#
# ------------------------------------------------------------------------
# Topic: Around line:
# --------------------------------------------
# - Preps
# Shebang 1
# License 2-18
# Description 19-76
# This index 77-106
# Apps & Loglevel 107-171
# Messages 172-234
# Traps 235-238
# Functions basic 239-404
# Output (echo/printf) 405-421
# Common variable preps 422-433
# Clear variables used by CFG 434-446
# Sanity check 447-456
# Declare default values 457-478
# Load config 479-484
# - Functions - Docs
# Show Help & Version 505-610
# Show Manpage 610-828
# Show Samples 828-1002
# - Functions - Work - TODO below here
# Tasks 1002-1329
# Set FHS standards 1329-1387
# Write files 1387-1596
# - Action
# Get options 1596-1657
# Prepare Environment 1661-1654
# Download prj & Prepare scripts 1654-1664
# Clean & Quit 1665
# ------------------------------------------------------------------------
#
# Set command-tools help output to english and bypass alias'
# These are just the initial default settings
# In case it should not find a certain command,
# it can be passed manually as a last resort.
#
export LC_ALL=C
declare -r PWD_ORG="${PWD:-$(pwd)}"
# String commands
declare AWK=${AWK:-\gawk} \
GREP=${GREP:-\grep} \
SED=${SED:-\sed} \
WC=${WC:-\wc}
# File commands
declare CAT=${CAT:-\cat} \
CP=${CP:-\cp} \
FIND=${FIND:-\find} \
INSTALL=${INSTALL:-\install} \
LN=${LN:-\ln} \
LS=${LS:-\ls} \
MAN=${MAN:-\man} \
MKDIR=${MKDIR:-\mkdir} \
MV=${MV:-\mv} \
RM=${RM:-\rm} \
RMDIR=${RMDIR:-\rmdir} \
TAR=${TAR:-\tar} \
TOUCH=${TOUCH:-\touch} \
WHICH=${WHICH:-\which}
# Internet commands
declare CURL=${CURL:-\curl} \
GIT=${GIT:-\git} \
PING=${PING:-\ping} \
SVN=${SVN:-\svn} \
WGET=${WGET:-\wget}
# Command lists
declare cmd_index="awk cat cp find grep install ln ls mkdir mv rm rmdir sed tar touch which wc"
declare cmd_index_optional="man ping curl wget git svn"
# Documention commands
declare TEXI=${TEXI:-\texi2any}
# Set working files
declare CFG="${CFG:-./configure.yassi}" \
LOG="${LOG:-./configure.log}" \
MANPAGE="${MANPAGE:-/tmp/yassi.1}" \
TPL="${TPL:-/tmp/yassi-headers-$$}}.tpl"
# The logfile is large enough already
# Clear it for each run
>"$LOG"
# Message verbosity level
case "${V:-0}" in
0) # Mute (too less info for bug reports)
beVerbose=false
DEBUG=false
;;
1) # Verbose (default)
beVerbose=true
DEBUG=false
;;
2) # Debug (annoying)
beVerbose=true
DEBUG=true
;;
3) # Debug (annoying)
beVerbose=true
DEBUG=false # To not disable the overall verbosity
set -xv
;;
*) cat <<-EO_SCREEN
Invalid value for: V=$V
Must be numeric: 0 / 1 / 2 / 3
EO_SCREEN
exit 1
;;
esac
#
# Message Strings
# This is a script, so docs are english
# However, there is room to support more languages to present error messages
# This is a one file project, so we cannot fallback to gettext
#
# List supported 'error message' languages here:
YASSI_LANGS=" " # TODO
# Parse for any supported language, or fallback to 'en_GB'
for lng in $YASSI_LANGS en_GB
do # If lng is not default, check if LANG and lng are the same lang, even if not country.
[ ! $lng = en_GB ] && L="${LANG##\.*}" && { [ "${L/_*}" = "${lng/_*}" ] || continue ; }
# Now check the checked variable
case "${lng:-en_GB}" in
en_*) # General issues
MSG_NO_CONFIG="Configuration file ($CFG) not found!"
MSG_NO_CONTENT="Is there any content you provide?"
MSG_NO_DL_APP="Could not find: curl/wget!"
# MSG_NO_REQS="Did not find the following required commands:"
# Check functions
MSG_CHECK_SANITY_FAIL="YASSI could not find a tool to verify the existence of the required binaries."
MSG_CHECK_SANITY_OPT="Install optional:"
MSG_CHECK_SANITY_OPTS="It is recomended to have either one of these commands installed:"
MSG_CHECK_NO_INTERNET="No active/working internet connection found."
MSG_CHECK_DL_NO_CODE="Remote source is provided, but this command is missing:"
MSG_CHECK_NO_DISPLAY_CMD="Could not find any display commands (echo/printf)"
MSG_CHECK_DISPLAY_CMD="Found output command:"
MSG_CHECK_CMD_BAD="Unavailable:"
MSG_CHECK_CMD_GOOD="Found:"
MSG_CHECK_DOCS_NO_APP="Found texinfo files, but texi2any is missing"
MSG_CHECK_NO_TEXI="The command 'texi2any' was not found, which is required to create the requested manual:"
# Yassi internal messages
MSG_YASSI_RUN_INSTALLED="Running installed"
MSG_YASSI_RUN_PROVIDED="Running provided"
MSG_YASSI_CODE_ERROR="If you experience any bugs or errors when executing './configure', 'make' or any other 'make-*' script, please raise an issue on: <$script_bugtracker>"
MSG_YASSI_MKDIR_ERROR="The directory you provided, could not be created!"
# Messages related to the user configure.yassi file
MSG_CFG_NO_NAME="Missing APP_NAME=appname..."
MSG_CANNOT_EXE_DIR='Cannot execute a directory: $1!'
MSG_CFG_LOADED="Loaded project:"
MSG_CFG_=""
# Download tasks
MSG_DOWNLOAD_NO_CODE="Fatal error, could not retrieve project (${APP_NAME^^}) code!"
# Tarball
MSG_TARBALL_GOOD="Successfully created tarball"
MSG_TARBALL_BAD="There was an error building the tarball"
# Requirement checks
MSG_MISSING_CMDS="Please provide these commands before configuring $APP_NAME!"
MSG_REQS_ONE="Please install at least one of these commands:"
MSG_REQS_OPTS="You might like to install one of these too:"
MSG_RERUN_CFG="Please rerun ./configure with your settings."
#MSG_=""
break
;;
# TODO) MSG_NO_CONFIG=""
# MSG_CFG_NAME_MISSING=""
# MSG_CHECK_SANITY_FAIL=""
# ...
# ;;
esac
job.info "$MSG_YASSI_LOADED_LANG $"
done
#
# Traps
#
trap "log \"Exit with $?\" >> $LOG;cd $PWD_ORG; [ -f $TPL ] && $RM $TPL ; trap -- 0 1" 0 1
#
# With the apps set to default values, or to the values passed
# we shall now define all the functions, before we do a sanity check if one of them
#
check.command.exist() { # COMMAND
# Check if the current expanded variable for
# its according GNU coreutils command is found and working
if "$1" --version >/dev/null 2>&1
then job.info "${MSG_CHECK_CMD_GOOD,} $1"
return 0
else # Exception
[ $? -eq 2 ] && [ "$1" = "ping" ] && \
job.info "${MSG_CHECK_CMD_GOOD,} $1" && \
return 0
# Regular
job.info "${MSG_CHECK_CMD_BAD,} $1"
return 1
fi
}
check.command.which() { $WHICH "$1" 2>/dev/null >&2 && return 0 || [ 0 -eq $(type "$1" 2>/dev/null >&2;msg $?) ] && return 0 || return 1;}
check.env.fail() { msg "$MSG_CHECK_SANITY_FAIL ($1)" ; exit 1;}
check.env.config() { # FILE
# Parse the file configure.yassi (default)
#
#echo $FUNCNAME
this="$1"
GQ="$GREP -q"
source "$this"
quit=true
# First things first, the most basic requirements
[ -z "${APP_NAME/APP*NAME}" ] && \
log.msg "$MSG_NO_NAME" && \
return 1
[ -z "${BINDIR}${DATAROOTDIR}${DATADIR}${DOCDIR}${INFODIR}" ] && \
log.msg "$MSG_NO_CONTENT" && \
return 1
# Doc handling
if $GQ DOCS "$this"
then # is the app installed & a texi file provided?
result=$($FIND | $GREP tex[i]$ | $GREP -v _version | $WC -l)
if [ ${result:-0} -ge 1 ]
then [ -z "$TEXI" ] && \
job.info "$MSG_CHECK_DOCS_NO_APP" && \
return 1
fi
fi
# Check the beta stuff...
# Auto downloader / installer
code_miss=""
code_found=""
dl_miss=""
dl_found=""
quit=false
base_val=10
if $GQ DOWNLOAD_IF_MISSING= "$this"
then # Check for sources
quit=true
for item in app_git app_svn download
do tmp=${item^^}
if [ -z "${!tmp}" ]
then job.info "$MSG_CHECK_DL_NO_SOURCE $tmp \"${!tmp}\""
quit=true
else quit=false
job.info "$MSG_CHECK_DL_NO_CODE ${item/download/curl\/wget}"
case "${item/*_}" in
app_git)
[ -z "$GIT" ] && base_val=$(( $base_val - 1 )) || base_val=$(( $base_val + 1 ))
;;
app_svn)
[ -z "$SVN" ] && base_val=$(( $base_val - 1 )) || base_val=$(( $base_val + 1 ))
;;
download)
[ -z "$CURL" ] && base_val=$(( $base_val - 1 )) || base_val=$(( $base_val + 1 ))
[ -z "$WGET" ] && base_val=$(( $base_val - 1 )) || base_val=$(( $base_val + 1 ))
;;
esac
fi
done
( [ ! -e "$DOWNLOAD_IF_MISSING" ] && ! check.env.internet ) && { job.info "$MSG_CHECK_NO_INTERNET" ; return 1;}
fi
# For the source available, is the proper download tool available?
! $quit && [ $base_val -gt 10 ] && quit=false
# Continue accordingly
#job.info "$msg"
$quit && return 1
return 0
}
check.env.internet() { $PING -c1 8.8.8.8 2>/dev/null >&2; return $?;}
check.env.sanity() { #
# Check the sanity of system environment like variables
# commands, paths and files
# 'which' is required for the later command fallback retrievals
! check.command.which $WHICH && check.env.fail "which"
# Is YASSI installed, or provided, and which version?
if [ "${0}" = "${BASE/$PWD/\.}/configure" ]
then str="$MSG_YASSI_RUN_INSTALLED"
YASSI="$0"
else str="$MSG_YASSI_RUN_PROVIDED"
YASSI="$BASE/${0##*/}"
fi
job.info "${str,} $YASSI ($script_version)"
# Fail with error if these commands are not found
for cmd in $cmd_index
do # Make it capital before expanding
c="${cmd^^}"
count=0
while ! check.command.exist "${!c}"
do # The command was not found, try dynamic
case "$count" in
0) eval msg "$c=$($WHICH $cmd 2>/dev/null)" ;;
1) for p in ${PATH/:/\ }
do # Got a better idea?
[ -f "$p/$cmd" ] && eval echo "$c=$p/$cmd" && break
done
;;
2) # Could not verify the current command checked
check.env.fail "$cmd"
;;
esac
count=$(($count +1))
done
done
# These are optional, but should be verified as well
for cmd in $cmd_index_optional
do # Make it capital before expanding
c="${cmd^^}"
count=0
while ! check.command.exist "${!c}"
do # The command was not found, try dynamic
case "$count" in
0) eval "$c=$($WHICH $cmd 2>/dev/null)" ;;
1) for p in ${PATH/:/\ }
do # Got a better idea?
[ -f "$p/$cmd" ] && eval "$c=$p/$cmd" && break
done
;;
2) # Could not verify the current command checked
# Setting the variable empty
check.command.which "$c" || eval "$c=''"
;;
esac
count=$(($count +1))
[ 3 -ge $count ] && break
done
done
# Report missing optionals, but continue anyway
[ -z "$CURL$WGET" ] && job.info "$MSG_CHECK_SANITY_OPTS curl wget"
[ -z "$GIT" ] && job.info "$MSG_CHECK_SANITY_OPT git"
[ -z "$SVN" ] && job.info "$MSG_CHECK_SANITY_OPT svn"
return 0
}
dir.change() { cd "$(dirname $1)" ; }
dir.make() { # /FULL/DIR
DONE=""
LB=$(msg "${1:1}" | $SED s,"/","\n",g)
echo "$LB" | while read current
do DONE+="/$current"
[ ! -d "$DONE" ] && $MKDIR "$DONE"
done
}
# Prints MSG to user
msg() { $ECHO "$1";}
msg.online() { $PRINT "$1";}
# LOG and print+log
log() { [ -f "$LOG" ] || ( touch "$LOG" && >"$LOG") ; msg "YASSI $1" >> "$LOG" ;}
log.msg() { msg "$1";log "$1";}
job.info() { ${beVerbose:-false} && log.msg "$1" || log "$1";}
liner() { msg ""; msg "-------------------------------------";msg "";}
#
# Special treatement
# Core display utilities
#
if check.command.which printf
then ECHO='printf %s\n '
PRINT='printf \r%s '
job.info "${MSG_CHECK_DISPLAY_CMD,} printf"
elif check.command.which echo
then ECHO="echo"
PRINT="echo -n"
job.info "${MSG_CHECK_DISPLAY_CMD,} echo"
else cat<<-EO_SCREEN
$MSG_CHECK_NO_DISPLAY_CMD
EO_SCREEN
exit 1
fi
job.info "\$ECHO = $ECHO"
job.info "\$PRINT = $PRINT"
#
# Make sure we have the variables we expect
# They are also used for and within the sanity check
#
$DEBUG && set -xv
USER="${USER:-$(whoami)}"
HOME="$(eval ${ECHO} ~$USER)"
# Workaround if printf was used to get HOME
[ "printf" = "${ECHO:0:6}" ] && HOME="${HOME:0:${#HOME}-1}"
LANG="${LANG:-en_GB.UTF-8}"
TERM="${TERM:-VT}"
BASE="${PWD:-$(pwd)}"
PATH="${PATH:-/bin:/usr/bin:/usr/local/bin:/os/bin}"
$DEBUG && set +xv
#
# Clear data of previous / other runs
# Be sure the data is clear before we load 'this' config
#
unset CHROOT DESTDIR
unset ${!APP_*} ${!AUTHOR_*} ${!MAINTAINER_*} ${!MAILLIST_*} BUGTRACKER
unset DOWNLOAD_IF_MISSING DOWNLOAD APP_GIT APP_SVN
unset MAKE UNINSTALL CLEAN DISTCLEAN CHECK INSTALLDIRS MOSTLYCLEAN MAINTAINER_CLEAN
unset REQS DOCS PRIOR POST IGNORE DEPS
unset doMakefile doGNU doTUI doRef
# Clear possible user variables
for d in ${!DIR_*};do unset ${d/DIR_}_DIR;done
unset ${!DIR_*}
#
# Sanity checks
#
# Make sure we are in the right directory for the sanity check
dir.change "$CFG"
check.env.sanity
if [ -f "$CFG" ]
then check.env.config "$CFG" || exit 1
else job.info "$MSG_NO_CONFIG"
fi
# Append debug info to log file, show if verbose
show.debug() {
liner
# Show default variables expected by YASSI
for item in DEBUG USER HOME LANG TERM BASE PATH;do msg "$item: ${!item}";done
# These might give clues upon an error
msg ""
msg "Machine: $(uname -a)"
msg "Default shell: $SHELL"
msg "Arguments ($#): ${@}"
liner
# Contact info about the project in concern
msg "This project: $APP_NAME"
msg "This homepage: $APP_HOMEPAGE"
msg "This download: $DOWNLOAD"
msg "This bugtracker: $BUGTRACKER"
for item in ${!AUTHOR_*} ${!MAINTAINER_*} APP_GIT APP_SVN;do
val="${!item}"
[ ! -z "$val" ] && msg "${item}: $val"
done
# Show regular environment
liner;env;liner;
}
job.info "$(show.debug "${@}")"
msg >> "$LOG"
#
# Prepare cleared arrays and variables
#
# Arrays
declare -A FHS # Use the varname to get its associated path
unset DOCS
declare -A DOCS # Use info,html,pdf,ps,dvi to create the assigned list of texi files
# REQS is unset about 20 lines above, on line 442, next line is 464.
unset REQS
declare -A REQS # Use req,make,opt to cancel installation or inform the user for benefits
declare -a MAKE PRIOR POST UNINSTALL CLEAN IGNORE CHECK INSTALLDIRS
# Variables
declare REF APP_NAME="APPNAME" APP_VER APP_LIC \
APP_TITLE APP_PRJ APP_HOMEPAGE \
APP_DIR="${PREFIX:-/usr/local}" \
declare AUTHOR_NAME AUTHOR_EMAIL AUTHOR_HOMEPAGE
declare MAINTAINER_NAME MAINTAINER_EMAIL MAINTAINER_HOMEPAGE
declare BUGTRACKER DOWNLOAD_IF_MISSING DOWNLOAD APP_GIT APP_SVN DEPS
# Dirs
declare mandirs="mandir $( msg man{1..9}dir)"
declare list_index="prefix bindir sbindir sysconfdir datarootdir appdir icondir datadir docdir htmldir infodir $mandirs dvidir pdfdir psdir compldir sharedstatedir localstatedir rootdir bootdir efidir grubdir"
declare list_variables="";for i in $list_index;do list_variables+=" ${i^^}";done
# Bools
declare doMakefile=false doGNU=false doTUI=false doRef=false
declare beVerbose=${VERBOSE:-${beVerbose:-false}} DEBUG=${DEBUG:-false}
#
# Load 'this' config defaults
#
[ -f "$CFG" ] && \
source "$CFG" && \
job.info "$MSG_CFG_LOADED \"${APP_TITLE:-$APP_NAME}\""
#
# Version, Help, Docs & templates
#
show.type() { LC_ALL=C type $1 | $GREP -v "is a function";}
show.version() {
# Prints the version of the script
# and exits
cat <<-EO_SCREEN
./configure, Version $script_version
Copyright (C) 2015 by Simon Arjuna Erat, Switzerland
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Report bugs of ./configure to: <https://github.com/sri-arjuna/yassi/issues>
EO_SCREEN
exit 0
}
show.paragraph() { # NODE "CONTENT"
# Prints a helptext block
# that is usable as manpage
printf "\n%s\n" "${1^^}" ; shift
for a in "${@}";do printf "\t%s\n" "$a";done
}
show.help() {
# Prints the helpscreen and exit with 0
#
# If the APP_NAME provides a license (APP_LIC), prepare its display string
[ -n "$APP_LIC" ] && \
scr_lic="$(show.paragraph license "${APP_LIC}" " ")" || \
src_lic=""
# Likewise for the APP_VER
[ -n "$APP_VER" ] && \
app_ver=" (${APP_VER})" || \
app_ver=""
# Actually print it to the user
cat <<-EO_SCREEN
SYNOPSIS
./$script_name [options]
DESCRIPTION
Routine to configure the installation of "${APP_TITLE:-${APP_NAME:-APPNAME}}$app_ver"
$scr_lic
BASIC
-h|--help Shows this screen and exits
--version Shows the version of YASSI (./configure) and exits
--verbose Prints all the action of the make* commands on the screen (V=0|1|2|3 ./configure [opts])
--debug Like --verbose but also internal action how those files are created (V=2 ./configure [opts])
--prefix DIR Sets the prefix to DIR (default: PREFIX=${APP_DIR})
DIRECTORIES
--bindir DIR user executeables (\$PREFIX/bin)
--sysconfdir DIR read-only single-machine data (\$PREFIX/etc)
--datadir DIR read-only architecture-independent data (\$DATAROOTDIR/${APP_NAME:-APPNAME})
--compldir DIR Bash completion (\$DATAROOTDIR/bash-completion/completions)
--datarootdir DIR read-only arch.-independent data root (\$PREFIX/share)
--localedir DIR locale-dependent data (\$DATAROOTDIR/locale)
--localstatedir DIR modifiable single-machine data (\$PREFIX/var)
--sbindir DIR admin executeables (\$PREFIX/sbin)
--sharedstatedir DIR modifiable architecture-independent (\$PREFIX/com)
DOCUMENTION
--docdir DIR Project documentation root (\$DATAROOTDIR/doc/${APP_NAME:-APPNAME})
--infodir DIR Info documentation (\$DATAROOTDIR/info)
--mandir DIR Basedir for manpages (\$DATAROOTDIR/man)
--man[1-9]dir DIR Specific manpage dirs (\$MANDIR/man/man[1-9])
--htmldir DIR Project documentation root (\$DOCDIR)
--dvidir DIR Project documentation root (\$DOCDIR)
--pdfdir DIR Project documentation root (\$DOCDIR)
--psdir DIR Project documentation root (\$DOCDIR)
GUI
--appdir DIR *.desktop files (\$DATAROOTDIR/applications)
--icondir DIR Icons for the desktop files (\$DATAROOTDIR/icons)
REDISTRIBUTION
--chroot DIR Sets the CHROOT to DIR (for 'builddirs' or before chrooting into a partition)
--tarball Equivalent of: "./configure [opts] && (./make-tarball || make dist)"
--makefile Writes a dynamic Makefile according to created scripts
DEVELOPERS
--sample [mini,full,clean,home]
Prints a basic sample, unless one of those arguments is passed
--manpage Prints an advanced help screen for developers and packagers
NOTES
Common Prefix Locations
Common places that are used as --prefix=DIR:
* / or /usr
* /usr/local (default) or /opt
* \$HOME or \$HOME/usr
* \$HOME/local or \$HOME/.local
EO_SCREEN
# Print messages according to passed configuration file
[ -n "$AUTHOR_NAME" ] && msg "The project \"${APP_NAME^^}\" was written by \"$AUTHOR_NAME\" <$AUTHOR_EMAIL> ($AUTHOR_HOMEPAGE)"
[ -n "$APP_HOMEPAGE" ] && msg "To learn more about \"${APP_TITLE:-$APP_NAME}\" visit: <$APP_HOMEPAGE>"
[ -n "$MAINTAINER_NAME" ] && msg "This package of \"${APP_TITLE:-$APP_NAME}\" is maintained by \"$MAINTAINER_NAME\" <$MAINTAINER_EMAIL> ($MAINTAINER_HOMEPAGE)"
[ -n "$MAILLIST_NEWS" ] && msg "To stay informed about \"${APP_NAME^^}\", subscribe to: <$MAILLIST_NEWS>"
[ -n "$MAILLIST_BUGS" ] && msg "To report bugs about \"${APP_NAME^^}\", please send a descriptive email to <$MAILLIST_BUGS>"
[ -n "$BUGTRACKER" ] && msg "If you experience any bugs or errors using \"${APP_NAME^^}\", please raise an issue on <$BUGTRACKER>"
printf "\n%s\n" "$MSG_YASSI_CODE_ERROR
"
exit 0
}
show.manpage() { #
# Prints the developer manpage
# -> basic text prepared for txt2man where available
cat <<-EO_SCREEN
DESCRIPTION
This manpage shall explain how to write/modify a YASSI configuration file.
This part of the manual is still in progress and also describes functionality that is still in developement or not yet stable.
Further it handles the topcis like the full sample from top to down.
SYNTAX
VARNAME=file Assign this file to be installed to VARNAME
VARNAME=dir1 Assign only content of this dir to be install to VARNAME
VARNAME=./dir2 Assign this dir and all its content to be installed to VARNAME
VARNAME=dir3/[RI]*.md Assign all files starting with capital 'R' and 'I' and ending with '.md' to be installed to VARNAME
VARNAME="file dir ./dir dir2/[RI*.md]" All above syntax can be combined within a list
TASK_LIST[0]="entry" Depending on the kind of the TASK_LIST[@]:
* Dirs/Files either get executed or removed
* Non found entries either gets removed or printed 'as is'
Exceptions are: REQS[<TYPE>] and DEPS, please see details below.
PROJECT INFO
This section explains most of the variables visible to the enduser by looking at --help.
APP_NAME The unix shortname of the project.
This name is also used for installation path
APP_VER Set the project version, this is also used in/on:
* the --help screen
* the tarball will contain version number
* Can be used to keep $DOWNLOAD up-to-date (see: Advanced: Mini Installer)
APP_LIC Set the license of your project
APP_TITLE Someimtes a title is more that just one word
APP_PRJ Is this project part of another project? What is its name?
APP_HOMEPAGE Where to get the latest information about the project?
APP_DIR Set another default path for ./configure (default /usr/local)
AUTHOR AND MAINTAINER INFO
{AUTHOR,MAINTAINER}_NAME Name of Author / Maintainer
{AUTHOR,MAINTAINER}_EMAIL Email of Author / Maintainer
{AUTHOR,MAINTAINER}_HOMEPAGE Homepage of Author / Maintainer
PROJECT CONTACT
MAILLIST_NEWS Newsletter for \$APP_NAME
MAILLIST_BUGS Email to send bugs to
BUGTRACKER Website to report bugs or raise issues
BOOLEANS
Syntax: doBOOLNAME=true
There are a few optional bool'ish helpers, by default they are set to false:
doMakefile It is quite obvious what doMakefile does if it is set to true.
doGNU If not provided by the author of the project, it adds some targets to the Makefile
doRef installs the reference file of the used paths to /etc/appname.conf,
if enabled, the file is also uninstalled automaticly.
If you need to apply the systems absolute paths into your scripts, use the \$REF for your TASK's in your $CFG.
doVer Some projects require to have the version in their path name 'doVer' does that.
doTUI As I wrote YASSI for myself, this doTUI toogle will install the Text User Interface,
framework for scripts before the the actual install.
REQS
Syntax: REQS[<TYPE>]="list of required commands"
REQS[app] Your project requires these commands and cannot run without them
REQS[make] This command is required to prepare the/your project files
REQS[opt] This command can improve usablity for your project but is not essential
Why this destinction?
In regards of the 'app' it is quite obvious, configure will exit with failure (1) if any of these commands is missing.
The same behaviour is for 'make', as that should contain a list of commands that are required to 'make' preparations for your projct before it gets installed.
'opt' on the other hand will only print a messsage to the user and let him know that it might be cool to install the missing commands of this list.
DIRECTORIES
This is where the actual magic happens...
Basicly all files and directories assigned to any of the *DIR variables according to above provided SYNTAX,
will get installed to the directory represented by the VARNAME*DIR (eg: BINDIR).
Please see: ./configure --help for a list of supported dirnames, note that the variables must be in CAPITAL letters.
DOCS
Is a nice handler to create texi documents.
Each of the following assignments will create a specific: make-doc-<TYPE> file.
Supported TYPE's are: info, html, pdf, dvi and ps.
DOCS[\$TYPE]=docs/texi/\$APP_NAME.texi The created script will create the info document.
DOCS[info]="docs/texi\$APP_NAME.texi docs/texi/other-node.texi" Also multiple entries are supported.
There is no need to handle the 'texi2any' requirement, using DOCS[TYPE] will inform the user if it is missing.
Also, it will not allow the user to delete (./make-clean) these docs if 'texi2any' is not available.
While this only takes care of creating these docs, you still need to place them for the installation:
INFODIR=docs/tex/*.info
HTMLDIR=docs/tex/*.html
Upon ./configure, ./make-doc-<TYPE> will be created.
Upon ./make-doc-<TYPE>, it will check if 'texi2any' is avilable or not.
Upon ./make-install-all, all available ./make-doc-* are executed before the actual ./make-install script.
ADVANCED
REDISTRIBUTION
--chroot=DIR Install \$APP_NAME to DIR/\${PREFIX}
This setting can be overwritten by passing DESTIDR=DIR to make.
--tarball Packages a tarball of the project dir from parent dir
--makefile If a Makefile should be required or desired
ADVANCED
MINI INSTALLER
These tools are nice if you want to share your application with a very low storage requirement.
DOWNLOAD_IF_MISSING Only if this DIR or FILE is not found, it triggers the other download preferences.
This DIR or FILE should NOT be created by ./make but exist and be required anyway.
APP_GIT Set the GIT URL to clone from (prefered)
APP_SVN Set the SVN URL to checkout from (2nd)
DOWNLOAD Download this tarball
DOWNLOAD_DIR Only required if the extracted tarball has another dirname than:
* \$APP_NAME
* \$APP_NAME-master
* \$APP_NAME-\$APP_VER
For GIT and SVN downloads, a directory named "\$APP_NAME.src" will be created.
The TARBALL will be downloaded and exracted and the path checked.
Afterwards YASSI changes its PWD to the new directory and continue installation.
ADVANCED
TARBALL
A tarball is usally not required, unless you create them manual for upstream, now this can be partialy automated!
TARBALL Set alternate output file (default: ../\$APP_NAME[-\APP_VER].tar.gz)
TARBALL_DIR Set custom output path, but let YASSI decide the filename
IGNORE Ignore these entries when creating the tarball
A tarball can be created by either:
./configure --tarball
./configure --makefile ; make dist
ADVANCED
VARIABLES PRESETS
These variables may be placed in front of ./configure and will influence the behavior of YASSI.
CFG=file This is the same as "./configure --conf file"
DESTDIR This is the same as ./configure --chroot=dir,
but it can also overwrite the previous set CHROOT by
passing "DESTDIR=dir make install"
TARBALL By default the created tarball will reside in the top dir, use this to change the location
ADVANCED
CUSTOM DIRECTORIES
You may define and use custom paths, be aware that you probably have to handle them your own.
To define a new TARGET DIR, use:
DIR_DEMO='$DATADIR/demo'
Then to assing the installer to install files there:
DEMO_DIR=demo/my*files
NOTE: This is a hardcore example of what could have been:
DATADIR=./demo
ADVANCED
TASKS
If you need to generate some files, for example a file containing the absolute paths of the system it is installed to,
you can do that by adding one or multiple MAKE array entries:
MAKE[0]="cat scripts/template.sh > bin/myapp"
You could also let ./make execute other scripts:
MAKE[1]=scripts/prepare.sh
Or print a message to the user:
MAKE[2]='echo "Hello $USER"'
Likewise for PRIOR[0] and POST[0], but those will be executed before and after the actual installation of the TARGETs.
The obvious exceptions are: UNINSTALL[0], CLEAN[0], DISTCLEAN[0], and IGNORE[0].
IGNORE is used for --tarball (make dist), the others obvious for their make-<COMMAND>s.
ADVANCED
DEPS
Syntax: DEPS="deps/first.yassi deps/second.yassi"
BETA IN PLAN
This will install each of the passed dependencies before the actual install.
YASSI will change its PWD to each of the DEP files and the call its default routines to install this passed configuration.
AUTHOR
YASSI was started in early Feb 2015 by Simon Arjuna Erat from Switzerland.
EO_SCREEN
}
show.sample() { # [TYPE]
# Prints a basic example config
#
case "$1" in
"") cat <<-EO_SCREEN
#!/usr/bin/env bash
# This configure.yassi was generated on $(date +'%F') using YASSI ($script_version)
#
# Project Info
#
APP_NAME=myapp # Install name of the application, \$PREFIX/share/\$APP_NAME
# APP_VER=0.5b # Optional, Show Versionnumber
# APP_LIC=GPLv3+ # Optional, Show License
# APP_HOMEPAGE="mywebsite.web" # Optional, homepage of project
# AUTHOR_HOMEPAGE="mywebsite.web" # Optional, your personal homepage
# AUTHOR_NAME="My Name" # Optional, Name of author
# AUTHOR_EMAIL="some@mail.web" # Optional, Email of author
#
# Default target dirs
#
BINDIR=bin # All files in folder 'bin' will be installed to \$PREFIX/bin
SYSCONFDIR=myapp.conf # Installs myapp.conf to \$PREFIX/etc
DATADIR="./lists ./templates" # Copies both directories to \$PREFIX/share/myapp/{lists,templates}
EO_SCREEN
;;
full) cat <<-EO_SCREEN
#!/usr/bin/env bash
# This configure.yassi was generated on $(date +'%F') using YASSI ($script_version)
# Copyright (c) $(date +'%F') by ${USER_NAME:-$USER} <${USER_EMAIL:-$USER@$HOSTNAME}>
# All rights reserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
#
# Project Info
# -- This info is shown on the default ./configure --help screen.
#
APP_NAME=appname # Install name of the application, \$PREFIX/share/\$APP_NAME
# APP_VER= # Optional, Show Versionnumber
# APP_LIC=GPLv3+ # Optional, Show License
# APP_TITLE="" # Optional, Show long title
# APP_PRJ="" # Optional, Name the parent project
# APP_HOMEPAGE="" # Optional, Website of the project
# APP_DIR=/usr/local # Optional, Used as default PREFIX if none is passed
#
# Author & Package Maintainer Info
# -- This info is shown on the default ./configure --help screen.
#
# AUTHOR_NAME="" # Optional, Name of author
# AUTHOR_EMAIL="" # Optional, Email of author
# AUTHOR_HOMEPAGE="" # Optional, Website of author
# MAINTAINER_NAME="" # Optional, Name of author
# MAINTAINER_EMAIL="" # Optional, Email of author
# MAINTAINER_HOMEPAGE="" # Optional, Website of author
# MAILLIST_NEWS="" # Optional, address of maillist to get news
# MAILLIST_BUGS="" # Optional, address of maillist to send bugs to...
# BUGTRACKER="" # Optional, adress to visit if no maillist is available but a bugtracker system
#
# YASSI Booleans
#
# doMakefile=false # Optional, Write a Makefile according to created scripts
# doGNU=false # Optional, like doMakefile, but write additional TARGETs to the Makefile,
# # if the according scripts are not created by the $CFG
# doTUI=false # Optional, Install TUI (BETA TODO)
# doRef=false # Optional, Install \${APP_NAME}_dirs.conf to \$SYSCONFDIR/\$APP_NAME.conf
# doVer=false # Optional, Use \$APP_VER for the DATADIR (\$DATAROOTDIR/\$APP_NAME-\$APP_VER)
#
# Requirements
#
#
# Requirements
#
# REQS[app]="bash which" # Detailed checks, MODE ('app') may be: app, make or opt.
# REQS_ONE[0]="curl wget" # For each entry at least one of the commands must be found
# DEPS="" # Install these *.yassi configure files before anything else, see more in ./configure --manpage
#
# Create documentions
#
# DOCS[info]= # Optional, Add *.texi files to the list and texi2any will convert them with ./make-doc-info
# DOCS[html]= # See more in ./configure --manpage
# DOCS[pdf]= # But also for: dvi and ps
#
# Default target dirs
#
# Basic
BINDIR=myscript # This still install all files into \$PREFIX/bin
# SBINDIR= # Optional, see --help for its default path
SYSCONFDIR="cfg/{a,b}.cfg" # This will install a.cfg and b.cfg to \$PREFIX/etc
# DATAROOTDIR= # Optional, see --help for its default path
DATADIR="./dir1 dir2 file1" # Copy ./dir1, content of 'dir2' and file1 to \$PREFIX/share/\$APP_NAME
# COMPLDIR=
# LOCALEDIR=
# LOCALSTATEDIR=
# SHAREDSTATEDIR=
# GUI # --> See "./configure --help" for their default paths
# APPDIR= # Optional, Install *.desktop files
# ICONDIR= # These dirs have subfolders, which you must provide as well
# # Docs
DOCDIR="[RCI]* docs" # Installs all files with capital starting letters R, C or I,
# and all content of 'docs' to \$PREFIX/share/doc/\$APP_NAME
# INFODIR= # Either precompiled (recomeded!) or/and as DOCS[info]=file.texi generated.
# HTMLDIR= # Like INFODIR, as well for pdfdir, dvidir, psdir.
# PDFDIR=
# DVIDIR=
# PSDIR=
MANDIR=./man1 # The offical target directory, contains subfolders per section
# MAN1DIR=mans/*.1 # These numbered variables grant direct access to their respective manpage dir.
# MAN8DIR=
#
# Advanced: Mini Installer
#
# DOWNLOAD_IF_MISSING="bin/script.sh" # If this file or dir is missing, try the provided download options
# APP_GIT="" # First choice to retrieve code from git to ./\$APP_NAME.src
# APP_SVN="" # Some still use this, goes also to ./\$APP_NAME.src
# DOWNLOAD="" # Last resort to download a tarball, prefer curl over wget
# DOWNLOAD_DIR="" # What is the name of the folder of the extracted tarball. (\$APP_NAME-{master,\$APP_VER} are automaticly reckognized)
#
# Advanced: Tarball (--tarball ; make dist)
#
# TARBALL="\${HOME}/\${APP_NAME}.tar.gz" # Where to save the tarball? Default: ../\$APP_NAME.tar.gz -- ../\${APP_NAME}-\${APP_VER}.tar.gz
# TARBALL_DIR="\$HOME" # Let YASSI create the filename, but save it here
# IGNORE[0]=".git" # Besides Makefile + make*, which files should be ignored for tarball?
#
# Advanced Tweakings
#
# MAKE_CREATES= # Optional, If this file is missing, make install wont start
# MAKE[0]="python ./scripts/script.py" # Optional, Tasks to be done by ./make
# PRIOR[0]="" # Optional, Tasks prior to installation (./make-install)
# POST[0]="" # Optional, Tasks post to installation (./make-install)
# UNINSTALL[0]="" # Optional, additional tasks to be done by ./make-uninstall, required to undo possible PRIOR or POST operations
# CLEAN[0]="to-delete.file" # Optional, Tasks to be done by ./make-clean