[fe30c61] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | # $Id$
|
---|
| 4 |
|
---|
| 5 | #=== MAKEFILE HEADER ===
|
---|
| 6 |
|
---|
[195ed9f] | 7 | #----------------------------------#
|
---|
| 8 | wrt_Makefile_header() { #
|
---|
| 9 | #----------------------------------#
|
---|
| 10 | (
|
---|
| 11 | cat << EOF
|
---|
| 12 | # This file is automatically generated by jhalfs
|
---|
[fe30c61] | 13 | # DO NOT EDIT THIS FILE MANUALLY
|
---|
| 14 | #
|
---|
[195ed9f] | 15 | # Generated on `date "+%F %X %Z"`
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | SRC = /sources
|
---|
| 19 | MOUNT_PT = $BUILDDIR
|
---|
| 20 | PKG_LST = $PKG_LST
|
---|
| 21 | LUSER = $LUSER
|
---|
| 22 | LGROUP = $LGROUP
|
---|
| 23 | SCRIPT_ROOT = $SCRIPT_ROOT
|
---|
| 24 | ADD_BLFS_TOOLS = $BLFS_TOOL
|
---|
| 25 |
|
---|
| 26 | BASEDIR = \$(MOUNT_PT)
|
---|
| 27 | SRCSDIR = \$(BASEDIR)/sources
|
---|
| 28 | CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
| 29 | LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/logs
|
---|
| 30 | TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/test-logs
|
---|
| 31 |
|
---|
| 32 | crCMDSDIR = /\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
| 33 | crLOGDIR = /\$(SCRIPT_ROOT)/logs
|
---|
| 34 | crTESTLOGDIR = /\$(SCRIPT_ROOT)/test-logs
|
---|
| 35 |
|
---|
| 36 | SU_LUSER = su - \$(LUSER) -c
|
---|
| 37 | LUSER_HOME = /home/\$(LUSER)
|
---|
| 38 | PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found \$(MOUNT_PT) \`\n"
|
---|
| 39 | PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) --exclude=lost+found / \`\n"
|
---|
| 40 |
|
---|
| 41 | export PATH := \${PATH}:/usr/sbin
|
---|
| 42 |
|
---|
| 43 | include makefile-functions
|
---|
| 44 |
|
---|
| 45 | EOF
|
---|
| 46 | ) > $MKFILE
|
---|
| 47 | }
|
---|
[fe30c61] | 48 |
|
---|
| 49 | #=======================
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | #==== PACKAGES NAMES ===
|
---|
| 53 |
|
---|
| 54 | #----------------------------------#
|
---|
| 55 | get_package_tarball_name() { #
|
---|
| 56 | #----------------------------------#
|
---|
| 57 | local script_name=`echo ${1} | sed -e 's@[0-9]\{1\}-@@'`
|
---|
| 58 |
|
---|
| 59 | # The use of 'head' is necessary to limit the return value to the FIRST match..
|
---|
| 60 | # hopefully this will not cause problems.
|
---|
| 61 | #
|
---|
| 62 | case $script_name in
|
---|
| 63 | tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 64 | ;;
|
---|
| 65 | linux-headers)
|
---|
| 66 | if [ "${PROGNAME}" = "lfs" ]; then
|
---|
| 67 | # Uses kernel headers directly
|
---|
| 68 | echo $(grep "^linux-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 69 | else
|
---|
| 70 | # CLFS/HLFS use massaged headers package
|
---|
| 71 | echo $(grep "^linux-headers-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 72 | fi
|
---|
| 73 | ;;
|
---|
| 74 | *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
|
---|
| 75 | ;;
|
---|
| 76 | esac
|
---|
| 77 |
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | #=======================
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | #==== TARGET HEADER ====
|
---|
| 84 |
|
---|
| 85 | #----------------------------------#
|
---|
| 86 | LUSER_wrt_target() { # Create target and initialize log file
|
---|
| 87 | #----------------------------------#
|
---|
| 88 | local i=$1
|
---|
| 89 | local PREV=$2
|
---|
| 90 | (
|
---|
| 91 | cat << EOF
|
---|
| 92 |
|
---|
| 93 | $i: $PREV
|
---|
| 94 | @\$(call echo_message, Building)
|
---|
| 95 | @./progress_bar.sh \$@ \$\$PPID &
|
---|
| 96 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/\$@
|
---|
| 97 | @\$(PRT_DU) >>logs/\$@
|
---|
| 98 | EOF
|
---|
| 99 | ) >> $MKFILE.tmp
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | #----------------------------------#
|
---|
| 103 | CHROOT_wrt_target() { # Create target and initialize log file
|
---|
| 104 | #----------------------------------#
|
---|
| 105 | local i=$1
|
---|
| 106 | local PREV=$2
|
---|
| 107 | case $i in
|
---|
| 108 | iteration* ) local LOGFILE="${this_script}.log" ;;
|
---|
| 109 | * ) local LOGFILE="\$@" ;;
|
---|
| 110 | esac
|
---|
| 111 | (
|
---|
| 112 | cat << EOF
|
---|
| 113 |
|
---|
| 114 | $i: $PREV
|
---|
| 115 | @\$(call echo_message, Building)
|
---|
| 116 | @./progress_bar.sh \$@ \$\$PPID &
|
---|
| 117 | @echo "\$(nl_)\`date\`\$(nl_)" >logs/$LOGFILE
|
---|
| 118 | @\$(PRT_DU_CR) >>logs/$LOGFILE
|
---|
| 119 | EOF
|
---|
| 120 | ) >> $MKFILE.tmp
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | #=======================
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | #======== UNPACK =======
|
---|
| 127 |
|
---|
| 128 | #----------------------------------#
|
---|
| 129 | LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
|
---|
| 130 | #----------------------------------#
|
---|
| 131 | local FILE=$1
|
---|
| 132 | local optSAVE_PREVIOUS=$2
|
---|
| 133 |
|
---|
| 134 | if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
|
---|
| 135 | (
|
---|
| 136 | cat << EOF
|
---|
| 137 | @\$(call remove_existing_dirs,$FILE)
|
---|
| 138 | EOF
|
---|
| 139 | ) >> $MKFILE.tmp
|
---|
| 140 | fi
|
---|
| 141 |
|
---|
| 142 | (
|
---|
| 143 | cat << EOF
|
---|
| 144 | @\$(call unpack,$FILE)
|
---|
| 145 | @\$(call get_pkg_root_LUSER)
|
---|
| 146 | EOF
|
---|
| 147 | ) >> $MKFILE.tmp
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | #----------------------------------#
|
---|
| 151 | CHROOT_Unpack() { #
|
---|
| 152 | #----------------------------------#
|
---|
| 153 | local FILE=$1
|
---|
| 154 | local optSAVE_PREVIOUS=$2
|
---|
| 155 |
|
---|
| 156 | if [ "${optSAVE_PREVIOUS}" != "1" ]; then
|
---|
| 157 | (
|
---|
| 158 | cat << EOF
|
---|
| 159 | @\$(call remove_existing_dirs2,$FILE)
|
---|
| 160 | EOF
|
---|
| 161 | ) >> $MKFILE.tmp
|
---|
| 162 | fi
|
---|
| 163 | (
|
---|
| 164 | cat << EOF
|
---|
| 165 | @\$(call unpack3,$FILE)
|
---|
| 166 | @\$(call get_pkg_root2)
|
---|
| 167 | EOF
|
---|
| 168 | ) >> $MKFILE.tmp
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | #=======================
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | #===== TESTS LOGS ======
|
---|
| 175 |
|
---|
| 176 | #----------------------------------#
|
---|
| 177 | LUSER_wrt_test_log() { # Initialize testsuite log file
|
---|
| 178 | #----------------------------------#
|
---|
| 179 | local TESTLOGFILE=$1
|
---|
| 180 | (
|
---|
| 181 | cat << EOF
|
---|
| 182 | @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
|
---|
| 183 | echo '\$(nl_)\`date\`\$(nl_)' >$TESTLOGDIR/$TESTLOGFILE
|
---|
| 184 | EOF
|
---|
| 185 | ) >> $MKFILE.tmp
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | #----------------------------------#
|
---|
| 189 | CHROOT_wrt_test_log() { #
|
---|
| 190 | #----------------------------------#
|
---|
| 191 | local TESTLOGFILE=$1
|
---|
| 192 | (
|
---|
| 193 | cat << EOF
|
---|
[8f2c086] | 194 | @echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
|
---|
[fe30c61] | 195 | echo "\$(nl_)\`date\`\$(nl_)" >test-logs/$TESTLOGFILE
|
---|
| 196 | EOF
|
---|
| 197 | ) >> $MKFILE.tmp
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | #=======================
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 | #======== RUN AS =======
|
---|
| 204 |
|
---|
| 205 | #----------------------------------#
|
---|
| 206 | wrt_RunAsRoot() { # Some scripts must be run as root..
|
---|
| 207 | #----------------------------------#
|
---|
| 208 | local MOUNT_ENV
|
---|
[8f2c086] | 209 | local file=$1
|
---|
[fe30c61] | 210 |
|
---|
| 211 | case ${PROGNAME} in
|
---|
| 212 | lfs ) MOUNT_ENV="LFS" ;;
|
---|
| 213 | clfs ) MOUNT_ENV="CLFS" ;;
|
---|
| 214 | clfs2 ) MOUNT_ENV="CLFS" ;;
|
---|
| 215 | clfs3 ) MOUNT_ENV="CLFS" ;;
|
---|
| 216 | hlfs ) MOUNT_ENV="HLFS" ;;
|
---|
| 217 | *) echo "undefined progname $PROGNAME"; exit 1 ;;
|
---|
| 218 | esac
|
---|
| 219 |
|
---|
| 220 | (
|
---|
| 221 | cat << EOF
|
---|
| 222 | @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
|
---|
| 223 | \$(PRT_DU) >>logs/\$@
|
---|
| 224 | EOF
|
---|
| 225 | ) >> $MKFILE.tmp
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | #----------------------------------#
|
---|
| 229 | LUSER_wrt_RunAsUser() { # Execute script inside time { }, footer to log file
|
---|
| 230 | #----------------------------------#
|
---|
| 231 | local file=$1
|
---|
| 232 |
|
---|
| 233 | (
|
---|
| 234 | cat << EOF
|
---|
| 235 | @( time { source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
|
---|
| 236 | \$(PRT_DU) >> logs/\$@
|
---|
| 237 | EOF
|
---|
| 238 | ) >> $MKFILE.tmp
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | #----------------------------------#
|
---|
| 242 | CHROOT_wrt_RunAsRoot() { #
|
---|
| 243 | #----------------------------------#
|
---|
| 244 | local file=$1
|
---|
| 245 | (
|
---|
| 246 | cat << EOF
|
---|
[8f2c086] | 247 | @( time { source envars && \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
|
---|
[fe30c61] | 248 | \$(PRT_DU_CR) >>logs/\$@
|
---|
| 249 | EOF
|
---|
| 250 | ) >> $MKFILE.tmp
|
---|
| 251 |
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | #=======================
|
---|
| 255 |
|
---|
| 256 |
|
---|
| 257 | #====== COPY FSTAB =====
|
---|
| 258 |
|
---|
| 259 | #----------------------------------#
|
---|
| 260 | LUSER_wrt_CopyFstab() { #
|
---|
| 261 | #----------------------------------#
|
---|
| 262 | (
|
---|
| 263 | cat << EOF
|
---|
| 264 | @( time { cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
|
---|
| 265 | EOF
|
---|
| 266 | ) >> $MKFILE.tmp
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | #----------------------------------#
|
---|
| 270 | CHROOT_wrt_CopyFstab() { #
|
---|
| 271 | #----------------------------------#
|
---|
| 272 | (
|
---|
| 273 | cat << EOF
|
---|
| 274 | @( time { cp -v /sources/fstab /etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
|
---|
| 275 | EOF
|
---|
| 276 | ) >> $MKFILE.tmp
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | #=======================
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 | #==== RM BUILD DIRS ====
|
---|
| 283 |
|
---|
| 284 | #----------------------------------#
|
---|
| 285 | LUSER_RemoveBuildDirs() { #
|
---|
| 286 | #----------------------------------#
|
---|
| 287 | local name=$1
|
---|
| 288 | (
|
---|
| 289 | cat << EOF
|
---|
| 290 | @\$(call remove_build_dirs,$name)
|
---|
| 291 | EOF
|
---|
| 292 | ) >> $MKFILE.tmp
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | #----------------------------------#
|
---|
| 296 | CHROOT_wrt_RemoveBuildDirs() { #
|
---|
| 297 | #----------------------------------#
|
---|
| 298 | local name=$1
|
---|
| 299 | (
|
---|
| 300 | cat << EOF
|
---|
| 301 | @\$(call remove_build_dirs2,$name)
|
---|
| 302 | EOF
|
---|
| 303 | ) >> $MKFILE.tmp
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | #=======================
|
---|
| 307 |
|
---|
| 308 |
|
---|
| 309 | #======== TOUCH ========
|
---|
| 310 |
|
---|
| 311 | #----------------------------------#
|
---|
| 312 | wrt_touch() { #
|
---|
| 313 | #----------------------------------#
|
---|
| 314 | (
|
---|
| 315 | cat << EOF
|
---|
| 316 | @\$(call housekeeping)
|
---|
| 317 | EOF
|
---|
| 318 | ) >> $MKFILE.tmp
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | #=======================
|
---|