This repo contains software to build linux from scratch and package it into rpm files.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.3 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #!/bin/bash
  2. #-----------------------------------------------------------------------------
  3. # Title: lfs.sh
  4. # Date: 2020-05-31
  5. # Version: 2.0
  6. # Author: chris@cromer.cl
  7. # Options:
  8. #-----------------------------------------------------------------------------
  9. # Copyright 2020 Chris Cromer
  10. # Copyright 2019 Baho Utot
  11. #-----------------------------------------------------------------------------
  12. # This program is free software: you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation, either version 3 of the License, or
  15. # (at your option) any later version.
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. #-----------------------------------------------------------------------------
  23. set -o errexit # exit if error...insurance ;)
  24. set -o nounset # exit if variable not initalized
  25. set +h # disable hashall
  26. #-----------------------------------------------------------------------------
  27. # Master variables
  28. PRGNAME=${0##*/} # script name minus the path
  29. TOPDIR=${PWD} # parent directory
  30. PARENT=/usr/src/LFS-RPM # rpm build directory
  31. USER=lfs # build user
  32. LFS=/mnt/lfs # build area
  33. #-----------------------------------------------------------------------------
  34. # Common support functions
  35. function die {
  36. local _red="\\033[1;31m"
  37. local _normal="\\033[0;39m"
  38. [ -n "$*" ] && printf "${_red}$*${_normal}\n"
  39. false
  40. exit 1
  41. }
  42. function msg {
  43. printf "%s\n" "${1}"
  44. return
  45. }
  46. function msg_line {
  47. printf "%s" "${1}"
  48. return
  49. }
  50. function msg_failure {
  51. local _red="\\033[1;31m"
  52. local _normal="\\033[0;39m"
  53. printf "${_red}%s${_normal}\n" "FAILURE"
  54. exit 2
  55. }
  56. function msg_success {
  57. local _green="\\033[1;32m"
  58. local _normal="\\033[0;39m"
  59. printf "${_green}%s${_normal}\n" "SUCCESS"
  60. return
  61. }
  62. function msg_log {
  63. printf "\n%s\n\n" "${1}" >> ${_logfile} 2>&1
  64. return
  65. }
  66. function end_run {
  67. local _green="\\033[1;32m"
  68. local _normal="\\033[0;39m"
  69. printf "${_green}%s${_normal}\n" "Run Complete"
  70. return
  71. }
  72. #-----------------------------------------------------------------------------
  73. # sanity check
  74. [ -v LFS ] || die "LFS environment variable missing/not set"
  75. [ -d ${LFS}/${PARENT} ] || die "${LFS}${PARENT} directory missing"
  76. cd ${LFS}${PARENT}
  77. su --login ${USER} <<- "EOF"
  78. source ~/.bashrc
  79. cd /mnt/lfs/usr/src/LFS-RPM
  80. ./tools.sh
  81. EOF
  82. msg_line " Unmounting Virtual Kernel File Systems: "
  83. mountpoint -q ${LFS}/run && umount ${LFS}/run
  84. mountpoint -q ${LFS}/sys && umount ${LFS}/sys
  85. mountpoint -q ${LFS}/proc && umount ${LFS}/proc
  86. mountpoint -q ${LFS}/dev/pts && umount ${LFS}/dev/pts
  87. mountpoint -q ${LFS}/dev && umount ${LFS}/dev
  88. msg_success
  89. msg_line " Changing file ownership: "
  90. chown -R root:root ${LFS}
  91. msg_success
  92. msg_line " Preparing Virtual Kernel File Systems: "
  93. [ -d ${LFS}/dev ] || mkdir -p ${LFS}/dev
  94. [ -d ${LFS}/proc ] || mkdir -p ${LFS}/proc
  95. [ -d ${LFS}/sys ] || mkdir -p ${LFS}/sys
  96. [ -d ${LFS}/run ] || mkdir -p ${LFS}/run
  97. [ -e ${LFS}/dev/console ] || mknod -m 600 ${LFS}/dev/console c 5 1
  98. [ -e ${LFS}/dev/null ] || mknod -m 666 ${LFS}/dev/null c 1 3
  99. msg_success
  100. msg_line " Mounting Virtual Kernel File Systems: "
  101. mountpoint -q ${LFS}/dev || mount --bind /dev ${LFS}/dev
  102. mountpoint -q ${LFS}/dev/pts || mount -t devpts devpts ${LFS}/dev/pts -o gid=5,mode=620
  103. mountpoint -q ${LFS}/proc || mount -t proc proc ${LFS}/proc
  104. mountpoint -q ${LFS}/sys || mount -t sysfs sysfs ${LFS}/sys
  105. mountpoint -q ${LFS}/run || mount -t tmpfs tmpfs ${LFS}/run
  106. [ -h ${LFS}/dev/shm ] && mkdir -p ${LFS}/$(readlink ${LFS}/dev/shm)
  107. msg_success
  108. chroot "$LFS" /tools/bin/env -i \
  109. HOME=/root \
  110. TERM="$TERM" \
  111. PS1='(lfs chroot) \u:\w\$ ' \
  112. PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
  113. /tools/bin/bash --login +h -c "cd ${PARENT};./base.sh"
  114. msg_line " Unmounting Virtual Kernel File Systems: "
  115. mountpoint -q ${LFS}/run && umount ${LFS}/run
  116. mountpoint -q ${LFS}/sys && umount ${LFS}/sys
  117. mountpoint -q ${LFS}/proc && umount ${LFS}/proc
  118. mountpoint -q ${LFS}/dev/pts && umount ${LFS}/dev/pts
  119. mountpoint -q ${LFS}/dev && umount ${LFS}/dev
  120. msg_success
  121. end_run