LFS-RPM/installer.sh

143 lines
4.5 KiB
Bash
Raw Normal View History

2019-05-24 08:27:40 -04:00
#!/bin/bash
#-----------------------------------------------------------------------------
# Title: installer.sh
2020-05-31 13:19:17 -04:00
# Date: 2020-05-31
# Version: 2.0
# Author: chris@cromer.cl
2019-05-24 08:27:40 -04:00
# Options:
#-----------------------------------------------------------------------------
2020-05-31 13:19:17 -04:00
# Copyright 2020 Chris Cromer
2019-05-24 08:27:40 -04:00
# Copyright 2019 Baho Utot
#-----------------------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#-----------------------------------------------------------------------------
# This script installs LFS base rpms to a partition mounted at /mnt
# the partition should be a new/clean partition as it will be overwritten
#-----------------------------------------------------------------------------
set -o errexit # exit if error...insurance ;)
set -o nounset # exit if variable not initalized
set +h # disable hashall
#-----------------------------------------------------------------------------
PRGNAME=${0##*/} # script name minus the path
REPOPATH="RPMS/x86_64" # path to the binary rpms
2020-05-31 13:19:17 -04:00
ROOTPATH="/mnt" # path to install filesystem
2019-05-24 08:27:40 -04:00
BASE="SPECS/base.spec" # filespec SPECS/base.spec
DBPATH="/var/lib/rpm" # path to the rpm database rel to ROOTPATH
2020-05-31 13:19:17 -04:00
LIST="" # list of packages to install
2019-05-24 08:27:40 -04:00
#-----------------------------------------------------------------------------
function _die() {
local _red="\\033[1;31m"
local _normal="\\033[0;39m"
[ -n "$*" ] && printf "${_red}$*${_normal}\n"
exit 1
}
function _msg {
printf "%s\n" "${1}"
return
}
function _msg_line {
printf "%s" "${1}"
return
}
function _msg_failure {
local _red="\\033[1;31m"
local _normal="\\033[0;39m"
printf "${_red}%s${_normal}\n" "FAILURE"
exit 2
}
function _msg_success {
local _green="\\033[1;32m"
local _normal="\\033[0;39m"
printf "${_green}%s${_normal}\n" "SUCCESS"
return
}
function _msg_log {
printf "\n%s\n\n" "${1}" >> ${_logfile} 2>&1
return
}
function _end_run {
local _green="\\033[1;32m"
local _normal="\\033[0;39m"
printf "${_green}%s${_normal}\n" "Run Complete"
return
}
#-----------------------------------------------------------------------------
_msg ""
_msg "${PRGNAME}:"
[ ${EUID} -eq 0 ] || _die
if [ ! /usr/bin/mountpoint ${ROOTPATH} > /dev/null 2>&1 ]; then _die "Hey ${ROOTPATH} is not mounted"; fi
_msg "Variable: PRGNAME: ${PRGNAME}"
_msg "Variable: REPOPATH: ${REPOPATH}"
_msg "Variable: ROOTPATH: ${ROOTPATH}"
_msg "Variable: BASE: ${BASE}"
_msg "Variable: DBPATH: ${DBPATH}"
install -vdm 755 "${ROOTPATH}${DBPATH}"
rpmdb --verbose --initdb --dbpath="${ROOTPATH}${DBPATH}"
# This reads all the rpm binary packages from SPECS/base.spec
while read i; do
i=$(echo ${i} | tr -d '[:cntrl:][:space:]')
case ${i} in
Requires:*)
j="${i##Requires:}"
case ${j} in
base*) ;;
filesystem*) ;;
*) LIST+="${j} " ;;
esac
;;
*) ;;
esac
done < "${BASE}"
LIST="filesystem ${LIST} "
LIST+="base"
for i in ${LIST}; do
j=$(echo ${REPOPATH}/${i}* | cut -d ' ' -f 1)
rpm --upgrade --verbose --hash --nodeps --noscripts --root ${ROOTPATH} --dbpath ${DBPATH} ${j}
done
# update ld cache, generate locales and set user/group files
# does not update texinfo files/ GNU help
cat > ${ROOTPATH}/tmp/script.sh <<- EOF
/sbin/ldconfig
/sbin/locale-gen
/usr/sbin/pwconv
/usr/sbin/grpconv
pushd /usr/share/info
rm -v dir
for f in *; do
2019-05-24 14:49:56 -04:00
install-info "${f}" dir 2>/dev/null
2019-05-24 08:27:40 -04:00
done
popd
pushd /boot
2020-05-31 13:19:17 -04:00
/usr/bin/touch initrd.img-5.5.3
/bin/rm initrd.img-5.5.3
/sbin/mkinitramfs 5.5.3
2019-05-24 08:27:40 -04:00
/usr/bin/vim /etc/sysconfig/clock
/usr/bin/vim /etc/passwd
/usr/bin/vim /etc/hosts
/usr/bin/vim /etc/hostname
/usr/bin/vim /etc/fstab
/usr/bin/vim /etc/sysconfig/ifconfig.eth0
/usr/bin/vim /etc/resolv.conf
/usr/bin/vim /etc/lsb-release
/usr/bin/vim /etc/sysconfig/rc.site
EOF
chmod +x ${ROOTPATH}/tmp/script.sh
chroot ${ROOTPATH} /usr/bin/env -i \
HOME=/root \
TERM="${TERM}" \
2019-05-24 14:51:00 -04:00
PS1='(installer) \u:\w:\$' \
2019-05-24 08:27:40 -04:00
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
/bin/bash --login -c 'cd /tmp;./script.sh'
_end_run