source: jhalfs@ 45f0437

new_features
Last change on this file since 45f0437 was df42c7c, checked in by Pierre Labastie <pierre@…>, 8 years ago

Porg style package management:

  • Add new variable WRAP_INSTALL in COnfig.in and jhalfs
  • Generates the install commands inside a wrapper function
  • Add files packInstall.sh.porg and packageManager.xml.porg
  • TODO: update README.PACKAGE...
  • TODO: make new templates in pkgmngt and document them
  • Property mode set to 100755
File size: 14.1 KB
RevLine 
[4da2512]1#!/bin/bash
2# $Id$
3set -e
[bbcdeab]4# Pass trap handlers to functions
5set -E
[4da2512]6
7# VT100 colors
8declare -r BLACK=$'\e[1;30m'
9declare -r DK_GRAY=$'\e[0;30m'
10
11declare -r RED=$'\e[31m'
12declare -r GREEN=$'\e[32m'
13declare -r YELLOW=$'\e[33m'
14declare -r BLUE=$'\e[34m'
15declare -r MAGENTA=$'\e[35m'
16declare -r CYAN=$'\e[36m'
17declare -r WHITE=$'\e[37m'
18
19declare -r OFF=$'\e[0m'
20declare -r BOLD=$'\e[1m'
21declare -r REVERSE=$'\e[7m'
22declare -r HIDDEN=$'\e[8m'
23
24declare -r tab_=$'\t'
25declare -r nl_=$'\n'
26
27declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
28declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
29declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
30
31# bold yellow > < pair
32declare -r R_arrow=$'\e[1;33m>\e[0m'
33declare -r L_arrow=$'\e[1;33m<\e[0m'
34
35
36#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
37#-----------------------#
38simple_error() { # Basic error trap.... JUST DIE
39#-----------------------#
40 # If +e then disable text output
[a96109a]41 if [[ "$-" =~ e ]]; then
[bbcdeab]42 LASTLINE="$1"
43 LASTERR="$2"
44 LASTFUNC="$3"
45 LASTSOURCE="$4"
46# echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
47 echo -e "\n${RED}ERROR:${GREEN} Error $LASTERR at $LASTSOURCE line ${LASTLINE}!${OFF}\n" >&2
[4da2512]48 fi
[bbcdeab]49 exit $LASTERR
[4da2512]50}
51
52see_ya() {
[401aac8]53 echo -e "\n${L_arrow}${BOLD}jhalfs-trunk${R_arrow} exit${OFF}\n"
[4da2512]54}
55##### Simple error TRAPS
56# ctrl-c SIGINT
57# ctrl-y
58# ctrl-z SIGTSTP
59# SIGHUP 1 HANGUP
60# SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
61# SIGQUIT 3
62# SIGKILL 9 KILL
63# SIGTERM 15 TERMINATION
64# SIGSTOP 17,18,23 STOP THE PROCESS
65#####
66set -e
67trap see_ya 0
[bbcdeab]68trap 'simple_error "${LINENO}" "$?" "${FUNCNAME}" "${BASH_SOURCE}"' ERR
[4da2512]69trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
70#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
71
72version="
[401aac8]73${BOLD} \"jhalfs-trunk\"${OFF} builder tool (development) \$Rev$
[4da2512]74 \$Date$
75
76 Written by George Boudreau and Manuel Canales Esparcia,
77 plus several contributions.
78
79 Based on an idea from Jeremy Huntwork
80
81 This set of files are published under the
82 ${BOLD}Gnu General Public License, Version 2.${OFF}
83"
84
85case $1 in
86 -v ) echo "$version" && exit 1 ;;
87 run ) : ;;
88 * )
89 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
90 exit 1
91 ;;
92esac
93
[65c998b]94# If the user has not saved his configuration file, let's ask
95# if he or she really wants to run this stuff
96if [ $(ls -l --time-style='+%Y%m%d%H%M%S' configuration.old | cut -d' ' -f 6) \
97 -ge $(ls -l --time-style='+%Y%m%d%H%M%S' configuration | cut -d' ' -f 6) ]
98 then echo -n "Do you want to run jhalfs? yes/no (yes): "
99 read ANSWER
100 if [ x${ANSWER:0:1} = "xn" -o x${ANSWER:0:1} = "xN" ] ; then
101 echo "${nl_}Exiting gracefully.${nl_}"
102 exit
103 fi
104fi
105
106# Change this to 0 to suppress almost all messages
[4da2512]107VERBOSITY=1
108
109[[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
110source configuration
[7072e1f]111[[ $? > 0 ]] && echo "file: configuration did not load.." && exit 1
[4da2512]112[[ $VERBOSITY > 0 ]] && echo "OK"
113
114# These are boolean vars generated from Config.in.
[7072e1f]115# ISSUE: If a boolean parameter is not set to y(es) there
116# is no variable defined by the menu app. This can
117# cause a headache if you are not aware.
118# The following variables MUST exist. If they don't, the
119# default value is n(o).
[4da2512]120RUNMAKE=${RUNMAKE:-n}
121GETPKG=${GETPKG:-n}
122COMPARE=${COMPARE:-n}
123RUN_FARCE=${RUN_FARCE:-n}
124RUN_ICA=${RUN_ICA:-n}
[7072e1f]125PKGMNGT=${PKGMNGT:-n}
[df42c7c]126WRAP_INSTALL=${WRAP_INSTALL:-n}
[4da2512]127BOMB_TEST=${BOMB_TEST:-n}
128STRIP=${STRIP:=n}
129REPORT=${REPORT:=n}
130VIMLANG=${VIMLANG:-n}
[b339c94]131FULL_LOCALE=${FULL_LOCALE:-n}
[4da2512]132GRSECURITY_HOST=${GRSECURITY_HOST:-n}
[9a536f7]133CUSTOM_TOOLS=${CUSTOM_TOOLS:-n}
[a16f769]134REBUILD_MAKEFILE=${REBUILD_MAKEFILE:-n}
[93346ee]135INSTALL_LOG=${INSTALL_LOG:-n}
[486e9a7]136CLEAN=${CLEAN:=n}
[d035526]137SET_SSP=${SET_SSP:=n}
138SET_ASLR=${SET_ASLR:=n}
139SET_PAX=${SET_PAX:=n}
140SET_HARDENED_TMP=${SET_HARDENED_TMP:=n}
141SET_WARNINGS=${SET_WARNINGS:=n}
142SET_MISC=${SET_MISC:=n}
143SET_BLOWFISH=${SET_BLOWFISH:=n}
[77fa8ba]144UNICODE=${UNICODE:=n}
[4da2512]145
[75d6d1c]146if [[ "${NO_PROGRESS_BAR}" = "y" ]] ; then
147 NO_PROGRESS="#"
148fi
149
150
[38ae01f]151# Sanity check on the location of $BUILDDIR / $JHALFSDIR
152CWD=$(cd `dirname $0` && pwd)
153if [[ $JHALFSDIR == $CWD ]]; then
154 echo " The jhalfs source directory conflicts with the jhalfs build directory."
155 echo " Please move the source directory or change the build directory."
156 exit 2
157fi
158
[0873ccc]159# Book sources envars
[4965fa8]160BRANCH_ID=${BRANCH_ID:=development}
161
162case $BRANCH_ID in
163 development )
164 case $PROGNAME in
[92b7cb8]165 clfs* ) TREE="" ;;
[c4ad7bf]166 * ) TREE=trunk/BOOK ;;
[4965fa8]167 esac
168 LFSVRS=development
169 ;;
170 *EDIT* ) echo " You forgot to set the branch or stable book version."
171 echo " Please rerun make and fix the configuration."
172 exit 2 ;;
173 branch-* )
[c4ad7bf]174 case $PROGNAME in
175 lfs )
176 LFSVRS=${BRANCH_ID}
[bb2862d]177 TREE=branches/${BRANCH_ID#branch-}
178 if [ ${BRANCH_ID#branch-} = 6 ]; then
179 TREE=${TREE}/BOOK
180 fi
[c4ad7bf]181 ;;
182 clfs* )
183 LFSVRS=${BRANCH_ID}
184 TREE=${BRANCH_ID#branch-}
185 ;;
186 esac
[4965fa8]187 ;;
188 * )
189 case $PROGNAME in
[e650dc7]190 lfs )
191 LFSVRS=${BRANCH_ID}
192 TREE=tags/${BRANCH_ID}
193 if (( ${BRANCH_ID:0:1} < 7 )) ; then
194 TREE=${TREE}/BOOK
195 fi
196 ;;
197 hlfs )
[4965fa8]198 LFSVRS=${BRANCH_ID}
199 TREE=tags/${BRANCH_ID}/BOOK
200 ;;
[92b7cb8]201 clfs* )
[4965fa8]202 LFSVRS=${BRANCH_ID}
[34d1b6a]203 TREE=clfs-${BRANCH_ID}
[4965fa8]204 ;;
[92b7cb8]205 * )
[4965fa8]206 esac
207 ;;
208esac
209
[4da2512]210# Set the document location...
[1cf621b]211BOOK=${BOOK:=$JHALFSDIR/$PROGNAME-$LFSVRS}
[4da2512]212
[4965fa8]213
[728955b]214#--- Envars not sourced from configuration
215case $PROGNAME in
[4195a40]216 clfs ) declare -r GIT="git://git.clfs.org/cross-lfs" ;;
217 clfs2 ) declare -r GIT="git://git.clfs.org/clfs-sysroot" ;;
218 clfs3 ) declare -r GIT="git://git.clfs.org/clfs-embedded" ;;
[92b7cb8]219 *) declare -r SVN="svn://svn.linuxfromscratch.org" ;;
[728955b]220esac
221declare -r LOG=000-masterscript.log
[7072e1f]222 # Needed for fetching BLFS book sources when building CLFS
[728955b]223declare -r SVN_2="svn://svn.linuxfromscratch.org"
224
[4da2512]225# Set true internal variables
226COMMON_DIR="common"
[52b0d10]227PACKAGE_DIR=$(echo $PROGNAME | tr '[a-z]' '[A-Z]')
[4da2512]228MODULE=$PACKAGE_DIR/master.sh
[7072e1f]229PKGMNGTDIR="pkgmngt"
230# The name packageManager.xml is hardcoded in *.xsl, so no variable.
[4da2512]231
232[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
233source $COMMON_DIR/common-functions
234[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
235[[ $VERBOSITY > 0 ]] && echo "OK"
236[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
237source $MODULE
238[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
239[[ $VERBOSITY > 0 ]] && echo "OK"
240#
241[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
242
243
244#*******************************************************************#
245[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
[d517356]246source $COMMON_DIR/libs/func_check_version.sh
[4da2512]247[[ $? > 0 ]] && echo " function module did not load.." && exit 2
248[[ $VERBOSITY > 0 ]] && echo "OK"
249
250[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
[d517356]251source $COMMON_DIR/libs/func_validate_configs.sh
[4da2512]252[[ $? > 0 ]] && echo " function module did not load.." && exit 2
253[[ $VERBOSITY > 0 ]] && echo "OK"
[9a536f7]254
[fe30c61]255[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_custom_pkgs>..."
256source $COMMON_DIR/libs/func_custom_pkgs
[9a536f7]257[[ $? > 0 ]] && echo " function module did not load.." && exit 2
258[[ $VERBOSITY > 0 ]] && echo "OK"
259
260
[6ed3dd7]261[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
262
263[[ $VERBOSITY > 0 ]] && echo Checking tools required for jhalfs
264check_alfs_tools
265
[4da2512]266[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
267
[e576789]268# blfs-tool envars
269BLFS_TOOL=${BLFS_TOOL:-n}
270if [[ "${BLFS_TOOL}" = "y" ]] ; then
[6ed3dd7]271 [[ $VERBOSITY > 0 ]] && echo Checking supplementary tools for installing BLFS
272 check_blfs_tools
273 [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
[854854e]274 BLFS_SVN=${BLFS_SVN:-n}
275 BLFS_WORKING_COPY=${BLFS_WORKING_COPY:-n}
276 BLFS_BRANCH=${BLFS_BRANCH:-n}
277 if [[ "${BLFS_SVN}" = "y" ]]; then
278 BLFS_BRANCH_ID=development
279 BLFS_TREE=trunk/BOOK
280 elif [[ "${BLFS_WORKING_COPY}" = "y" ]]; then
281 [[ -d "$BLFS_WC_LOCATION" ]] &&
282 [[ -d "$BLFS_WC_LOCATION/postlfs" ]] || {
283 echo " BLFS tools: This is not a working copy: $BLFS_WC_LOCATION."
284 echo " Please rerun make and fix the configuration."
285 exit 2
286 }
[2c4be7f]287 BLFS_TREE=$(cd $BLFS_WC_LOCATION; svn info | grep '^URL' | sed 's@.*BLFS/@@')
[854854e]288 BLFS_BRANCH_ID=$(echo $BLFS_TREE | sed -e 's@trunk/BOOK@development@' \
289 -e 's@branches/@branch-@' \
290 -e 's@tags/@@' \
291 -e 's@/BOOK@@')
[0ba80be]292 elif [[ "${BLFS_BRANCH}" = "y" ]] ; then
[854854e]293 case $BLFS_BRANCH_ID in
294 *EDIT* ) echo " You forgot to set the BLFS branch or stable book version."
295 echo " Please rerun make and fix the configuration."
296 exit 2 ;;
297 branch-systemd ) BLFS_TREE=branches/systemd ;;
298 branch-* ) BLFS_TREE=branches/${BLFS_BRANCH_ID#branch-}/BOOK ;;
[6c97d02]299 6.2* | 7.* ) BLFS_TREE=tags/${BLFS_BRANCH_ID} ;;
[854854e]300 * ) BLFS_TREE=tags/${BLFS_BRANCH_ID}/BOOK ;;
301 esac
302 fi
[e576789]303 [[ $VERBOSITY > 0 ]] && echo -n "Loading blfs tools installation function..."
304 source $COMMON_DIR/libs/func_install_blfs
305 [[ $? > 0 ]] && echo "function module did not load.." && exit 1
306 [[ $VERBOSITY > 0 ]] && echo "OK"
307fi
[4da2512]308
309###################################
310### MAIN ###
311###################################
312
313
314validate_config
315echo "${SD_BORDER}${nl_}"
316echo -n "Are you happy with these settings? yes/no (no): "
317read ANSWER
318if [ x$ANSWER != "xyes" ] ; then
[881c96f]319 echo "${nl_}Rerun make to fix the configuration options.${nl_}"
[d023a35]320 exit
[4da2512]321fi
322echo "${nl_}${SD_BORDER}${nl_}"
323
324# Load additional modules or configuration files based on global settings
325# compare module
326if [[ "$COMPARE" = "y" ]]; then
327 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
[d517356]328 source $COMMON_DIR/libs/func_compare.sh
329 [[ $? > 0 ]] && echo "$COMMON_DIR/libs/func_compare.sh did not load.." && exit
[4da2512]330 [[ $VERBOSITY > 0 ]] && echo "OK"
331fi
332#
333# optimize module
334if [[ "$OPTIMIZE" != "0" ]]; then
335 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
336 source optimize/optimize_functions
337 [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
338 [[ $VERBOSITY > 0 ]] && echo "OK"
339 #
340 # optimize configurations
341 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
342 source optimize/opt_config
343 [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
344 [[ $VERBOSITY > 0 ]] && echo "OK"
[854854e]345 # The number of parallel jobs is taken from configuration now
346 MAKEFLAGS="-j${N_PARALLEL}"
[4da2512]347 # Validate optimize settings, if required
348 validate_opt_settings
349fi
350#
351
[a16f769]352if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then
[4da2512]353
[7b6ecc5]354 # If requested, clean the build directory
355 clean_builddir
[4da2512]356
[7b6ecc5]357 if [[ ! -d $JHALFSDIR ]]; then
358 mkdir -p $JHALFSDIR
359 fi
[3e7ceed]360
[7b6ecc5]361 # Create $BUILDDIR/sources even though it could be created by get_sources()
362 if [[ ! -d $BUILDDIR/sources ]]; then
363 mkdir -p $BUILDDIR/sources
364 fi
365 #
366 # Create the log directory
367 if [[ ! -d $LOGDIR ]]; then
368 mkdir $LOGDIR
369 fi
370 >$LOGDIR/$LOG
371 #
[3e7ceed]372 # Copy common helper files
[d68eb1b]373 cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
374 # Copy needed stylesheets
375 cp $COMMON_DIR/{packages.xsl,chroot.xsl} $JHALFSDIR/
[7b6ecc5]376 #
[3e7ceed]377 # Fix the XSL book parser
[92b7cb8]378 case $PROGNAME in
379 clfs* ) sed 's,FAKEDIR,'${BOOK}/BOOK',' ${PACKAGE_DIR}/${XSL} > $JHALFSDIR/${XSL} ;;
380 lfs | hlfs ) sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL} ;;
381 * ) ;;
382 esac
[3e7ceed]383 export XSL=$JHALFSDIR/${XSL}
[7b6ecc5]384 #
385
[7072e1f]386 # Copy packageManager.xml, if needed
387 [[ "$PKGMNGT" = "y" ]] && [[ "$PROGNAME" = "lfs" ]] &&
388 cp $PKGMNGTDIR/packageManager.xml $JHALFSDIR/ &&
389 cp $PKGMNGTDIR/packInstall.sh $JHALFSDIR/
390 #
[3e7ceed]391 # Copy urls.xsl, if needed
392 [[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
[7b6ecc5]393 #
[3e7ceed]394 # Create the test-log directory, if needed
395 [[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
396 #
[93346ee]397 # Create the installed-files directory, if needed
398 [[ "$INSTALL_LOG" = "y" ]] && [[ ! -d $FILELOGDIR ]] && install -d -m 1777 $FILELOGDIR
399 #
[3e7ceed]400 # Prepare report creation, if needed
[7b6ecc5]401 if [[ "$REPORT" = "y" ]]; then
402 cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
[7072e1f]403 # After making sure that all looks sane, dump the settings to a file
[7b6ecc5]404 # This file will be used to create the REPORT header
405 validate_config > $JHALFSDIR/jhalfs.config
406 fi
407 #
[3e7ceed]408 # Copy optimize files, if needed
409 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
[7b6ecc5]410 #
[3e7ceed]411 # Copy compare files, if needed
412 if [[ "$COMPARE" = "y" ]]; then
413 mkdir -p $JHALFSDIR/extras
414 cp extras/* $JHALFSDIR/extras
415 fi
[7b6ecc5]416 #
[3e7ceed]417 # Copy custom tools config files, if requested
418 if [[ "${CUSTOM_TOOLS}" = "y" ]]; then
419 echo "Copying custom tool scripts to $JHALFSDIR"
420 mkdir -p $JHALFSDIR/custom-commands
421 cp -f custom/config/* $JHALFSDIR/custom-commands
422 fi
423 #
[7b6ecc5]424 # Install blfs-tool, if requested.
425 if [[ "${BLFS_TOOL}" = "y" ]] ; then
[6ed3dd7]426 echo Installing BLFS book and tools
[e576789]427 install_blfs_tools 2>&1 | tee -a $LOGDIR/$LOG
[bbcdeab]428 [[ ${PIPESTATUS[0]} != 0 ]] && exit 1
[7b6ecc5]429 fi
[3e7ceed]430 #
[7b6ecc5]431
[1cf621b]432# Download or updates the book source
[7b6ecc5]433 get_book
[1cf621b]434 extract_commands
[4965fa8]435 echo "${SD_BORDER}${nl_}"
[7b6ecc5]436
[4965fa8]437fi
438
[e576789]439# When regenerating the Makefile, we need to know also the
440# canonical book version
[a16f769]441if [[ "$REBUILD_MAKEFILE" = "y" ]] ; then
442 case $PROGNAME in
[92b7cb8]443 clfs* )
[a16f769]444 VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
[7bd0866]445 lfs)
446 if [[ "$INITSYS" = "sysv" ]] ; then
447 VERSION=$(grep 'ENTITY version ' $JHALFSDIR/$BOOK/general.ent| cut -d\" -f2)
448 else
449 VERSION=$(grep 'ENTITY versiond' $JHALFSDIR/$BOOK/general.ent| cut -d\" -f2)
450 fi
451 ;;
[a16f769]452 *)
[7bd0866]453 VERSION=$(xmllint --noent $JHALFSDIR/$BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
[a16f769]454 esac
455fi
456
[4da2512]457build_Makefile
[3e7ceed]458
[4da2512]459echo "${SD_BORDER}${nl_}"
460
[1cf621b]461# Check for build prerequisites.
462 echo
463 cd $CWD
464 check_prerequisites
465 echo "${SD_BORDER}${nl_}"
466# All is well, run the build (if requested)
[4da2512]467run_make
Note: See TracBrowser for help on using the repository browser.