[0170229] | 1 | #!/bin/bash
|
---|
[12a5707] | 2 | # $Id$
|
---|
[0170229] | 3 | set -e
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | #>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
|
---|
| 7 | #-----------------------#
|
---|
| 8 | simple_error() { # Basic error trap.... JUST DIE
|
---|
| 9 | #-----------------------#
|
---|
| 10 | # If +e then disable text output
|
---|
| 11 | if [[ "$-" =~ "e" ]]; then
|
---|
| 12 | echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
|
---|
| 13 | fi
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | see_ya() {
|
---|
[d95b8f2] | 17 | echo -e "\n\t${BOLD}Goodbye and thank you for choosing ${L_arrow}JHALFS-X${R_arrow}\n"
|
---|
[0170229] | 18 | }
|
---|
| 19 | ##### Simple error TRAPS
|
---|
| 20 | # ctrl-c SIGINT
|
---|
| 21 | # ctrl-y
|
---|
| 22 | # ctrl-z SIGTSTP
|
---|
| 23 | # SIGHUP 1 HANGUP
|
---|
| 24 | # SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
|
---|
| 25 | # SIGQUIT 3
|
---|
| 26 | # SIGKILL 9 KILL
|
---|
| 27 | # SIGTERM 15 TERMINATION
|
---|
| 28 | # SIGSTOP 17,18,23 STOP THE PROCESS
|
---|
| 29 | #####
|
---|
| 30 | set -e
|
---|
| 31 | trap see_ya 0
|
---|
| 32 | trap simple_error ERR
|
---|
| 33 | trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
|
---|
| 34 | #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | if [ ! -L $0 ] ; then
|
---|
| 38 | echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
|
---|
| 39 | exit 1
|
---|
| 40 | fi
|
---|
| 41 |
|
---|
[12a5707] | 42 | PROGNAME=$(basename $0)
|
---|
| 43 | VERSION="0.0.1"
|
---|
| 44 | COMMON_DIR="common"
|
---|
| 45 | PACKAGE_DIR=$(echo $PROGNAME | tr [a-z] [A-Z])
|
---|
| 46 | MODULE=$PACKAGE_DIR/master.sh
|
---|
| 47 | MODULE_CONFIG=$PACKAGE_DIR/config
|
---|
| 48 |
|
---|
| 49 | echo -n "Loading common-functions module..."
|
---|
| 50 | source $COMMON_DIR/common-functions
|
---|
| 51 | [[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
|
---|
| 52 | echo "OK"
|
---|
| 53 | #
|
---|
| 54 |
|
---|
| 55 | echo -n "Loading masterscript conf..."
|
---|
| 56 | source $COMMON_DIR/config
|
---|
[13e816f] | 57 | [[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
|
---|
[0170229] | 58 | echo "OK"
|
---|
| 59 | #
|
---|
| 60 | echo -n "Loading config module <$MODULE_CONFIG>..."
|
---|
| 61 | source $MODULE_CONFIG
|
---|
| 62 | [[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
|
---|
| 63 | echo "OK"
|
---|
| 64 | #
|
---|
| 65 | echo -n "Loading code module <$MODULE>..."
|
---|
| 66 | source $MODULE
|
---|
[12a5707] | 67 | [[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
|
---|
[0170229] | 68 | echo "OK"
|
---|
| 69 | #
|
---|
| 70 | echo "---------------${nl_}"
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | #===========================================================
|
---|
| 74 | # If the var BOOK contains something then, maybe, it points
|
---|
| 75 | # to a working doc.. set WC=1, else 'null'
|
---|
| 76 | #===========================================================
|
---|
| 77 | WC=${BOOK:+1}
|
---|
| 78 | #===========================================================
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | #*******************************************************************#
|
---|
[12a5707] | 82 | echo -n "Loading function <func_check_version.sh>..."
|
---|
| 83 | source $COMMON_DIR/func_check_version.sh
|
---|
| 84 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
| 85 | echo "OK"
|
---|
[0170229] | 86 |
|
---|
[12a5707] | 87 | echo -n "Loading function <func_validate_configs.sh>..."
|
---|
| 88 | source $COMMON_DIR/func_validate_configs.sh
|
---|
| 89 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
| 90 | echo "OK"
|
---|
| 91 | echo "---------------${nl_}"
|
---|
[0170229] | 92 |
|
---|
| 93 |
|
---|
| 94 | ###################################
|
---|
| 95 | ### MAIN ###
|
---|
| 96 | ###################################
|
---|
| 97 |
|
---|
| 98 | # Evaluate any command line switches
|
---|
| 99 |
|
---|
| 100 | while test $# -gt 0 ; do
|
---|
| 101 | case $1 in
|
---|
| 102 | --version | -V )
|
---|
| 103 | clear
|
---|
| 104 | echo "$version"
|
---|
| 105 | exit 0
|
---|
| 106 | ;;
|
---|
| 107 |
|
---|
| 108 | --help | -h )
|
---|
| 109 | if [[ "$PROGNAME" = "blfs" ]]; then
|
---|
| 110 | blfs_usage
|
---|
| 111 | else
|
---|
| 112 | usage
|
---|
| 113 | fi
|
---|
| 114 | ;;
|
---|
| 115 |
|
---|
| 116 | --LFS-version | -L )
|
---|
| 117 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 118 | shift
|
---|
| 119 | case $1 in
|
---|
| 120 | dev* | SVN | trunk )
|
---|
| 121 | LFSVRS=development
|
---|
| 122 | ;;
|
---|
[d95b8f2] | 123 | *) if [[ "$PROGNAME" = "lfs" ]]; then
|
---|
| 124 | case $1 in
|
---|
| 125 | 6.1.1 )
|
---|
| 126 | echo "For stable 6.1.1 book, please use jhalfs-0.2."
|
---|
| 127 | exit 0
|
---|
| 128 | ;;
|
---|
| 129 | alpha*) LFSVRS=alphabetical ;;
|
---|
| 130 | udev*) LFSVRS=udev_update ;;
|
---|
| 131 | * ) echo "$1 is an unsupported version at this time." ;;
|
---|
| 132 | esac
|
---|
| 133 | else
|
---|
| 134 | echo "This requested version, ${L_arrow} ${BOLD}$1${OFF} ${R_arrow}, is an unsupported in the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} series."
|
---|
| 135 | exit 0
|
---|
| 136 | fi
|
---|
[0170229] | 137 | ;;
|
---|
| 138 | esac
|
---|
| 139 | ;;
|
---|
| 140 |
|
---|
| 141 | --directory | -d )
|
---|
| 142 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 143 | shift
|
---|
| 144 | BUILDDIR=$1
|
---|
| 145 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
| 146 | LOGDIR=$JHALFSDIR/logs
|
---|
| 147 | MKFILE=$JHALFSDIR/${PROGNAME}-Makefile
|
---|
| 148 | ;;
|
---|
| 149 |
|
---|
[d95b8f2] | 150 |
|
---|
[0170229] | 151 | --download-client | -D )
|
---|
| 152 | echo "The download feature is temporarily disable.."
|
---|
| 153 | exit
|
---|
| 154 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 155 | shift
|
---|
| 156 | DL=$1
|
---|
| 157 | ;;
|
---|
| 158 |
|
---|
| 159 | --working-copy | -W )
|
---|
| 160 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 161 | shift
|
---|
| 162 | if [ -f $1/patches.ent ] ; then
|
---|
[d95b8f2] | 163 | WC=1
|
---|
| 164 | BOOK=$1
|
---|
[0170229] | 165 | else
|
---|
| 166 | echo -e "\nLook like $1 isn't a supported working copy."
|
---|
| 167 | echo -e "Verify your selection and the command line.\n"
|
---|
| 168 | exit 1
|
---|
| 169 | fi
|
---|
| 170 | ;;
|
---|
| 171 |
|
---|
[8ab950f] | 172 | --testsuites | -T )
|
---|
| 173 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 174 | shift
|
---|
| 175 | case $1 in
|
---|
| 176 | 0 | 1 | 2 | 3 )
|
---|
| 177 | TEST=$1
|
---|
| 178 | ;;
|
---|
| 179 | * )
|
---|
| 180 | echo -e "\n$1 isn't a valid testsuites level value."
|
---|
| 181 | echo -e "You must to use 0, 1, 2, or 3.\n"
|
---|
| 182 | exit 1
|
---|
| 183 | ;;
|
---|
| 184 | esac
|
---|
| 185 | ;;
|
---|
| 186 |
|
---|
[d95b8f2] | 187 | --get-packages | -P ) HPKG=1 ;;
|
---|
| 188 | --run-make | -M ) RUNMAKE=1 ;;
|
---|
| 189 | --no-strip ) STRIP=0 ;;
|
---|
| 190 | --no-vim-lang ) VIMLANG=0 ;;
|
---|
| 191 | --rebuild ) CLEAN=1 ;;
|
---|
[0170229] | 192 |
|
---|
| 193 | --page_size )
|
---|
| 194 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 195 | shift
|
---|
| 196 | case $1 in
|
---|
| 197 | letter | A4 )
|
---|
| 198 | PAGE=$1
|
---|
| 199 | ;;
|
---|
| 200 | * )
|
---|
| 201 | echo "$1 isn't a supported page size."
|
---|
| 202 | exit 1
|
---|
| 203 | ;;
|
---|
| 204 | esac
|
---|
| 205 | ;;
|
---|
| 206 |
|
---|
| 207 | --timezone )
|
---|
| 208 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 209 | shift
|
---|
| 210 | if [ -f /usr/share/zoneinfo/$1 ] ; then
|
---|
| 211 | TIMEZONE=$1
|
---|
| 212 | else
|
---|
| 213 | echo -e "\nLooks like $1 isn't a valid timezone description."
|
---|
| 214 | echo -e "Verify your selection and the command line.\n"
|
---|
| 215 | exit 1
|
---|
| 216 | fi
|
---|
| 217 | ;;
|
---|
| 218 |
|
---|
| 219 | --fstab )
|
---|
| 220 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 221 | shift
|
---|
| 222 | if [ -f $1 ] ; then
|
---|
| 223 | FSTAB=$1
|
---|
| 224 | else
|
---|
| 225 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
| 226 | exit 1
|
---|
| 227 | fi
|
---|
| 228 | ;;
|
---|
| 229 |
|
---|
| 230 | --kernel-config | -C )
|
---|
| 231 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 232 | shift
|
---|
| 233 | if [ -f $1 ] ; then
|
---|
| 234 | CONFIG=$1
|
---|
| 235 | else
|
---|
| 236 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
| 237 | exit 1
|
---|
| 238 | fi
|
---|
| 239 | ;;
|
---|
| 240 |
|
---|
| 241 | * )
|
---|
| 242 | if [[ "$PROGNAME" = "blfs" ]]; then
|
---|
| 243 | blfs_usage
|
---|
| 244 | else
|
---|
| 245 | usage
|
---|
| 246 | fi
|
---|
| 247 | ;;
|
---|
| 248 | esac
|
---|
| 249 | shift
|
---|
| 250 | done
|
---|
| 251 |
|
---|
| 252 | # Find the download client to use, if not already specified.
|
---|
| 253 |
|
---|
| 254 | if [ -z $DL ] ; then
|
---|
| 255 | if [ `type -p wget` ] ; then
|
---|
| 256 | DL=wget
|
---|
| 257 | elif [ `type -p curl` ] ; then
|
---|
| 258 | DL=curl
|
---|
| 259 | else
|
---|
| 260 | eval "$no_dl_client"
|
---|
| 261 | fi
|
---|
| 262 | fi
|
---|
| 263 |
|
---|
| 264 | #===================================================
|
---|
| 265 | # Set the document location...
|
---|
[13e816f] | 266 | # BOOK is either defined in
|
---|
[0170229] | 267 | # xxx.config
|
---|
| 268 | # comand line
|
---|
[13e816f] | 269 | # default
|
---|
[d95b8f2] | 270 | # If set by conf file or cmd line leave it
|
---|
[0170229] | 271 | # alone otherwise load the default version
|
---|
| 272 | #===================================================
|
---|
| 273 | BOOK=${BOOK:=$PROGNAME-$LFSVRS}
|
---|
| 274 | #===================================================
|
---|
| 275 |
|
---|
[13e816f] | 276 |
|
---|
| 277 | # Check for minumum gcc and kernel versions
|
---|
| 278 | #check_requirements 1 # 0/1 0-do not display values.
|
---|
| 279 | check_version "2.6.2" "`uname -r`" "KERNEL"
|
---|
| 280 | check_version "3.0" "$BASH_VERSION" "BASH"
|
---|
| 281 | check_version "3.0" "`gcc -dumpversion`" "GCC"
|
---|
[e1edff3] | 282 | tarVer=`tar --version`
|
---|
| 283 | check_version "1.15.0" "${tarVer##* }" "TAR"
|
---|
[13e816f] | 284 | echo "---------------${nl_}"
|
---|
| 285 |
|
---|
| 286 | validate_config 1 # 0/1 0-do not display values
|
---|
| 287 | echo "---------------${nl_}"
|
---|
| 288 |
|
---|
[164afa2] | 289 | echo -n "Are you happy with that settings? yes/no (no): "
|
---|
[13e816f] | 290 | read ANSWER
|
---|
| 291 | if [ x$ANSWER != "xyes" ] ; then
|
---|
| 292 | echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
|
---|
| 293 | exit 1
|
---|
| 294 | fi
|
---|
| 295 |
|
---|
| 296 | # Prevents setting "-d /" by mistake.
|
---|
| 297 |
|
---|
| 298 | if [ $BUILDDIR = / ] ; then
|
---|
| 299 | echo -ne "\nThe root directory can't be used to build LFS.\n\n"
|
---|
| 300 | exit 1
|
---|
| 301 | fi
|
---|
| 302 |
|
---|
| 303 | # If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
|
---|
| 304 | # and notify the user about that.
|
---|
| 305 |
|
---|
| 306 | if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
|
---|
| 307 | eval "$no_empty_builddir"
|
---|
| 308 | fi
|
---|
| 309 |
|
---|
| 310 | # If requested, clean the build directory
|
---|
| 311 | clean_builddir
|
---|
| 312 |
|
---|
[0170229] | 313 | if [[ ! -d $JHALFSDIR ]]; then
|
---|
| 314 | mkdir -pv $JHALFSDIR
|
---|
| 315 | fi
|
---|
| 316 |
|
---|
[13e816f] | 317 | if [[ "$PWD" != "$JHALFSDIR" ]]; then
|
---|
[12a5707] | 318 | cp -v $COMMON_DIR/makefile-functions $JHALFSDIR/
|
---|
[0170229] | 319 | if [[ -n "$FILES" ]]; then
|
---|
[9c90294] | 320 | # pushd/popd necessary to deal with mulitiple files
|
---|
| 321 | pushd $PACKAGE_DIR
|
---|
| 322 | cp -v $FILES $JHALFSDIR/
|
---|
| 323 | popd
|
---|
[0170229] | 324 | fi
|
---|
[12a5707] | 325 | sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
|
---|
[0170229] | 326 | export XSL=$JHALFSDIR/${XSL}
|
---|
| 327 | fi
|
---|
| 328 |
|
---|
| 329 | if [[ ! -d $LOGDIR ]]; then
|
---|
| 330 | mkdir -v $LOGDIR
|
---|
| 331 | fi
|
---|
| 332 | >$LOGDIR/$LOG
|
---|
| 333 | echo "---------------${nl_}"
|
---|
| 334 |
|
---|
| 335 | get_book
|
---|
| 336 | echo "---------------${nl_}"
|
---|
[12a5707] | 337 |
|
---|
[0170229] | 338 | build_Makefile
|
---|
| 339 | echo "---------------${nl_}"
|
---|
[12a5707] | 340 |
|
---|
[386bc75] | 341 | run_make
|
---|
[0170229] | 342 |
|
---|