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.

190 lines
6.2 KiB

1 year ago
6 months ago
1 year ago
6 months ago
1 year ago
6 months ago
1 year ago
6 months ago
1 year ago
6 months ago
1 year ago
1 year ago
6 months ago
1 year ago
  1. #!/bin/bash
  2. #-----------------------------------------------------------------------------
  3. # Title: setup.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. # Common variables
  28. PRGNAME=${0##*/} # Script name minus the path
  29. TOPDIR=${PWD} # This directory
  30. LFS=/mnt/lfs # Where LFS will be installed to
  31. PARENT=/usr/src/LFS-RPM # Where build system wil live
  32. SWAP_FILE_SIZE=1024 # Size of swap file in MB
  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 - ${PRGNAME}"
  70. return
  71. }
  72. #-----------------------------------------------------------------------------
  73. # Local functions
  74. function _sanity {
  75. local size=""
  76. msg_line " Checking to see if running as root: "
  77. [ "$EUID" -ne 0 ] && die "You need be running as root for this script"
  78. msg_success
  79. msg_line " Checking if LFS variable is set: "
  80. [ -v LFS ] || die "LFS environment variable missing/not set"
  81. msg_success
  82. msg_line " Checking if ${LFS} is mounted: "
  83. mountpoint -q ${LFS} || die "${LFS} is not mounted"
  84. msg_success
  85. # check for swap space and add some in there is no swap
  86. size=$(free | grep 'Swap:' | tr -d ' ' | cut -d ':' -f2)
  87. case ${size} in
  88. "000")
  89. msg " Creating swap file: ${LFS}/swapfile: "
  90. dd if=/dev/zero of=${LFS}/swapfile status=progress bs=1M count=${SWAP_FILE_SIZE}
  91. chmod 600 ${LFS}/swapfile
  92. mkswap ${LFS}/swapfile
  93. swapon -v ${LFS}/swapfile
  94. msg_success ;;
  95. *) ;;
  96. esac
  97. return
  98. }
  99. function _chapter_3 {
  100. # 3. Packages and Patches
  101. # Introduction
  102. # All Packages
  103. # Needed Patches
  104. local i=""
  105. local list=""
  106. if [ ${PWD} != ${LFS}${PARENT} ]; then
  107. msg_line " Install build system: "
  108. [ -d ${LFS}/${PARENT} ] || install -dm 755 ${LFS}${PARENT}
  109. cp -ar ${TOPDIR}/BOOK ${LFS}${PARENT}
  110. cp -ar ${TOPDIR}/SOURCES ${LFS}${PARENT}
  111. cp -ar ${TOPDIR}/SPECS ${LFS}${PARENT}
  112. cp -a ${TOPDIR}/README ${LFS}${PARENT}
  113. cp -a ${TOPDIR}/*.sh ${LFS}${PARENT}
  114. chmod +x ${LFS}${PARENT}/*.sh
  115. msg_success
  116. fi
  117. # Create download list
  118. while IFS= read -r i; do
  119. list+="${i} "
  120. done < "${TOPDIR}/BOOK/wget-list"
  121. list+="ftp://anduin.linuxfromscratch.org/BLFS/popt/popt-1.16.tar.gz "
  122. list+="http://ftp.rpm.org/releases/rpm-4.15.x/rpm-4.15.1.tar.bz2 "
  123. list+="https://download.oracle.com/berkeley-db/db-5.3.28.tar.gz "
  124. list+="https://ftp.gnu.org/gnu/cpio/cpio-2.13.tar.bz2 "
  125. list+="https://ftp.gnu.org/gnu/wget/wget-1.20.3.tar.gz "
  126. for i in ${list}; do
  127. msg_line " Fetching: ${i}: "
  128. wget --quiet --no-clobber --no-check-certificate --continue --directory-prefix=${LFS}${PARENT}/SOURCES ${i} || die "${PRGNAME}: Error: ${i}: Fetching tarball"
  129. msg_success
  130. done
  131. # Create md5sum list
  132. while read i;do
  133. pushd ${LFS}${PARENT}/SOURCES > /dev/null 2>&1
  134. printf "%s\n" "${i}" > md5sums
  135. msg_line " Verifying: ${i#*' '}: "
  136. md5sum --status -c md5sums && msg_success || msg_failure
  137. popd > /dev/null 2>&1
  138. done < "${TOPDIR}/BOOK/md5sums"
  139. return
  140. }
  141. function _chapter_4 {
  142. # 4. Final Preparations
  143. # Introduction
  144. # Creating the $LFS/tools Directory
  145. # Adding the LFS User
  146. # Setting Up the Environment
  147. # About SBUs
  148. # About the Test Suites
  149. local target=""
  150. # Creating the $LFS/tools Directory
  151. msg_line " Checking for ${LFS}/tools directory: "
  152. [ -d ${LFS}/tools ] || install -dm 755 ${LFS}/tools
  153. msg_success
  154. msg_line " Checking for /tools symlink: "
  155. [ -h /tools ] || ln -s ${LFS}/tools /
  156. msg_success
  157. msg_line " Creating lfs user: "
  158. getent group lfs > /dev/null 2>&1 || groupadd lfs > /dev/null 2>&1
  159. getent passwd lfs > /dev/null 2>&1 || useradd -c 'LFS user' -g lfs -m -k /dev/null -s /bin/bash lfs > /dev/null 2>&1
  160. getent passwd lfs > /dev/null 2>&1 && passwd --delete lfs > /dev/null 2>&1
  161. msg_success
  162. msg_line " Setting Up the Environment: "
  163. [ -d /home/lfs ] || install -dm 755 /home/lfs
  164. cat > /home/lfs/.bash_profile <<- EOF
  165. exec env -i HOME=/home/lfs TERM=${TERM} PS1='\u:\w\$ ' /bin/bash
  166. EOF
  167. cat > /home/lfs/.bashrc <<- EOF
  168. set +h
  169. umask 022
  170. LFS=/mnt/lfs
  171. LC_ALL=POSIX
  172. LFS_TGT=$(uname -m)-lfs-${OSTYPE}
  173. PATH=/tools/bin:/bin:/usr/bin
  174. export LFS LC_ALL LFS_TGT PATH
  175. EOF
  176. chown -R lfs:lfs /home/lfs || die "${PRGNAME}: ${FUNCNAME}: FAILURE"
  177. chown -R lfs:lfs ${LFS} || die "${PRGNAME}: ${FUNCNAME}: FAILURE"
  178. msg_success
  179. return
  180. }
  181. #-----------------------------------------------------------------------------
  182. # Main line
  183. LIST=""
  184. LIST+="_sanity " # Sanity checks
  185. LIST+="_chapter_3 " # Chapter 3 Packages and Patches
  186. LIST+="_chapter_4 " # Chapter 4 Final Preparations
  187. for i in ${LIST};do ${i};done
  188. end_run