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