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.

86 lines
3.0 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #!/bin/bash
  2. #-----------------------------------------------------------------------------
  3. # Title: cleanup.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 removes changes made to the host system and
  24. # also removes the build tool chain chapter 5 packages as they are no
  25. # longer needed. It will also unmount the /mnt/lfs filesystem
  26. #-----------------------------------------------------------------------------
  27. set -o errexit # exit if error...insurance ;)
  28. set -o nounset # exit if variable not initalized
  29. set +h # disable hashall
  30. #-----------------------------------------------------------------------------
  31. PRGNAME=${0##*/} # script name minus the path
  32. LFS=/mnt/lfs # build area
  33. TOOLCHAIN="${LFS}/tools" # tool chain directory
  34. LINK=/tools # tool chain symlink
  35. USER=lfs # build user
  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_line "Checking to see if running as root: "
  75. [ "$EUID" -ne 0 ] && die "You need be running as root for this script"
  76. msg_success
  77. msg_line "Remove chapter 5 tool chain: "
  78. [ -d "${TOOLCHAIN}" ] && rm -rf "${TOOLCHAIN}"
  79. [ -h "${LINK}" ] && rm ${LINK}
  80. msg_success
  81. msg_line "Removing lfs user: "
  82. getent passwd ${USER} > /dev/null 2>&1 && userdel -r ${USER} > /dev/null 2>&1
  83. msg_success
  84. end_run