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.

142 lines
4.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #!/bin/bash
  2. #-----------------------------------------------------------------------------
  3. # Title: installer.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. # This script installs LFS base rpms to a partition mounted at /mnt
  24. # the partition should be a new/clean partition as it will be overwritten
  25. #-----------------------------------------------------------------------------
  26. set -o errexit # exit if error...insurance ;)
  27. set -o nounset # exit if variable not initalized
  28. set +h # disable hashall
  29. #-----------------------------------------------------------------------------
  30. PRGNAME=${0##*/} # script name minus the path
  31. REPOPATH="RPMS/x86_64" # path to the binary rpms
  32. ROOTPATH="/mnt" # path to install filesystem
  33. BASE="SPECS/base.spec" # filespec SPECS/base.spec
  34. DBPATH="/var/lib/rpm" # path to the rpm database rel to ROOTPATH
  35. LIST="" # list of packages to install
  36. #-----------------------------------------------------------------------------
  37. function _die() {
  38. local _red="\\033[1;31m"
  39. local _normal="\\033[0;39m"
  40. [ -n "$*" ] && printf "${_red}$*${_normal}\n"
  41. exit 1
  42. }
  43. function _msg {
  44. printf "%s\n" "${1}"
  45. return
  46. }
  47. function _msg_line {
  48. printf "%s" "${1}"
  49. return
  50. }
  51. function _msg_failure {
  52. local _red="\\033[1;31m"
  53. local _normal="\\033[0;39m"
  54. printf "${_red}%s${_normal}\n" "FAILURE"
  55. exit 2
  56. }
  57. function _msg_success {
  58. local _green="\\033[1;32m"
  59. local _normal="\\033[0;39m"
  60. printf "${_green}%s${_normal}\n" "SUCCESS"
  61. return
  62. }
  63. function _msg_log {
  64. printf "\n%s\n\n" "${1}" >> ${_logfile} 2>&1
  65. return
  66. }
  67. function _end_run {
  68. local _green="\\033[1;32m"
  69. local _normal="\\033[0;39m"
  70. printf "${_green}%s${_normal}\n" "Run Complete"
  71. return
  72. }
  73. #-----------------------------------------------------------------------------
  74. _msg ""
  75. _msg "${PRGNAME}:"
  76. [ ${EUID} -eq 0 ] || _die
  77. if [ ! /usr/bin/mountpoint ${ROOTPATH} > /dev/null 2>&1 ]; then _die "Hey ${ROOTPATH} is not mounted"; fi
  78. _msg "Variable: PRGNAME: ${PRGNAME}"
  79. _msg "Variable: REPOPATH: ${REPOPATH}"
  80. _msg "Variable: ROOTPATH: ${ROOTPATH}"
  81. _msg "Variable: BASE: ${BASE}"
  82. _msg "Variable: DBPATH: ${DBPATH}"
  83. install -vdm 755 "${ROOTPATH}${DBPATH}"
  84. rpmdb --verbose --initdb --dbpath="${ROOTPATH}${DBPATH}"
  85. # This reads all the rpm binary packages from SPECS/base.spec
  86. while read i; do
  87. i=$(echo ${i} | tr -d '[:cntrl:][:space:]')
  88. case ${i} in
  89. Requires:*)
  90. j="${i##Requires:}"
  91. case ${j} in
  92. base*) ;;
  93. filesystem*) ;;
  94. *) LIST+="${j} " ;;
  95. esac
  96. ;;
  97. *) ;;
  98. esac
  99. done < "${BASE}"
  100. LIST="filesystem ${LIST} "
  101. LIST+="base"
  102. for i in ${LIST}; do
  103. j=$(echo ${REPOPATH}/${i}* | cut -d ' ' -f 1)
  104. rpm --upgrade --verbose --hash --nodeps --noscripts --root ${ROOTPATH} --dbpath ${DBPATH} ${j}
  105. done
  106. # update ld cache, generate locales and set user/group files
  107. # does not update texinfo files/ GNU help
  108. cat > ${ROOTPATH}/tmp/script.sh <<- EOF
  109. /sbin/ldconfig
  110. /sbin/locale-gen
  111. /usr/sbin/pwconv
  112. /usr/sbin/grpconv
  113. pushd /usr/share/info
  114. rm -v dir
  115. for f in *; do
  116. install-info "${f}" dir 2>/dev/null
  117. done
  118. popd
  119. pushd /boot
  120. /usr/bin/touch initrd.img-5.5.3
  121. /bin/rm initrd.img-5.5.3
  122. /sbin/mkinitramfs 5.5.3
  123. /usr/bin/vim /etc/sysconfig/clock
  124. /usr/bin/vim /etc/passwd
  125. /usr/bin/vim /etc/hosts
  126. /usr/bin/vim /etc/hostname
  127. /usr/bin/vim /etc/fstab
  128. /usr/bin/vim /etc/sysconfig/ifconfig.eth0
  129. /usr/bin/vim /etc/resolv.conf
  130. /usr/bin/vim /etc/lsb-release
  131. /usr/bin/vim /etc/sysconfig/rc.site
  132. EOF
  133. chmod +x ${ROOTPATH}/tmp/script.sh
  134. chroot ${ROOTPATH} /usr/bin/env -i \
  135. HOME=/root \
  136. TERM="${TERM}" \
  137. PS1='(installer) \u:\w:\$' \
  138. PATH=/bin:/usr/bin:/sbin:/usr/sbin \
  139. /bin/bash --login -c 'cd /tmp;./script.sh'
  140. _end_run