2016-11-20 00:47:30 -05:00
#!/bin/bash
2016-12-17 01:07:50 -05:00
# needed so we override whatever's set in python
# alternatively, we can just mkdir -p $GNUPGHOME
2016-12-20 16:57:31 -05:00
#export GNUPGHOME=/root/.gnupg
unset GNUPGHOME
mkdir -p /var/empty/.gnupg
# set up a shell env
source /etc/profile
2016-12-01 23:42:27 -05:00
2016-11-20 01:46:01 -05:00
# Import settings.
2016-12-01 12:47:23 -05:00
source /root/VARS.txt
2016-11-20 01:46:01 -05:00
2016-11-20 00:47:30 -05:00
# Logging!
exec 3>& 1 4>& 2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/var/log/chroot_install.log 2>& 1
2016-12-03 06:07:41 -05:00
# we need this fix before anything.
2016-12-22 14:05:07 -05:00
dirmngr </dev/null
2016-12-26 13:34:34 -05:00
gpg --batch --yes --import /root/pubkey.gpg
# This is unnecessary as we have no private key
#gpg --batch --yes --lsign-key 0x${SIGKEY}
exec 17<>/root/pubkey.gpg
2016-12-03 06:07:41 -05:00
2016-11-20 00:47:30 -05:00
cleanPacorigs( )
{
for x in $( find /etc/ -type f -iname "*.pacorig" ) ;
do
mv -f ${ x } ${ x %%.pacorig }
done
}
2016-12-03 06:07:41 -05:00
getPkgList( )
{
if [ -f " ${ 1 } " ] ;
then
pkgfile = $( cat ${ 1 } )
echo " ${ pkgfile } " | \
sed -r -e '/^[[:space:]]*(#|$)/d' \
-e 's/[[:space:]]*#.*$//g' | \
tr '\n' ' ' | \
sed -re 's/([+\_])/\\\1/g'
fi
}
2016-11-20 00:47:30 -05:00
# NetworkManager is a scourge upon the earth that must be purged and cleansed.
ln -s /dev/null /etc/systemd/system/NetworkManager.service
ln -s /dev/null /etc/systemd/system/NetworkManager-dispatcher.service
# Build the keys
pacman-key --init
pacman-key --populate archlinux
pacman-key -r 93481F6B
# Update the mirror cache
pacman -Syy
# Just in case.
cleanPacorigs
# Install some prereqs
2016-12-09 12:41:17 -05:00
pacman -S --noconfirm --needed sed
2016-12-22 14:05:07 -05:00
pacman -S --noconfirm --needed grep
2016-12-13 23:43:53 -05:00
sed -i.bak -e 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf
pacman -S --noconfirm --needed filesystem
2016-12-22 14:05:07 -05:00
pacman -S --noconfirm --needed core
2016-12-13 23:43:53 -05:00
mv /etc/pacman.conf.bak /etc/pacman.conf
2016-12-04 02:43:49 -05:00
pacman -S --noconfirm --needed base syslinux wget rsync unzip jshon sudo abs xmlto bc docbook-xsl git
locale-gen
2016-11-20 00:47:30 -05:00
# And get rid of files it wants to replace
cleanPacorigs
# Force update all currently installed packages in case the tarball's out of date
2016-12-01 09:35:06 -05:00
pacman -Su --force --noconfirm
2016-11-20 00:47:30 -05:00
# And in case the keys updated...
pacman-key --refresh-keys
cleanPacorigs
# We'll need these.
pacman -S --noconfirm --needed base-devel
cleanPacorigs
# Install apacman
pacman --noconfirm -U /root/apacman*.tar.xz && \
mkdir /var/tmp/apacman && chmod 0750 /var/tmp/apacman && \
chown root:aurbuild /var/tmp/apacman
2016-12-20 16:57:31 -05:00
chown aurbuild:aurbuild /var/empty/.gnupg
2016-12-22 14:05:07 -05:00
chmod 700 /var/empty/.gnupg
2016-11-20 00:47:30 -05:00
cleanPacorigs
2016-12-01 09:35:06 -05:00
apacman -Syy
2016-12-26 13:34:34 -05:00
for p in apacman apacman-deps apacman-utils expac;
do
apacman -S --noconfirm --noedit --skipinteg --needed -S " ${ p } "
done
2016-11-20 00:47:30 -05:00
apacman --gendb
cleanPacorigs
# Install multilib-devel if we're in an x86_64 chroot.
if $( egrep -q '^\[multilib' /etc/pacman.conf) ;
then
2016-12-09 12:41:17 -05:00
yes 'y' | pacman -S --needed gcc-multilib lib32-fakeroot lib32-libltdl
2016-11-20 00:47:30 -05:00
pacman --noconfirm -S --needed multilib-devel
2016-11-20 01:46:01 -05:00
cleanPacorigs
2016-11-20 00:47:30 -05:00
TGT_ARCH = 'x86_64'
else
TGT_ARCH = 'i686'
fi
# Install some stuff we need for the ISO.
2016-12-03 06:07:41 -05:00
#PKGLIST=$(sed -re '/^[[:space:]]*(#|$)/d' /root/iso.pkgs.both | tr '\n' ' ')
PKGLIST = $( getPkgList /root/iso.pkgs.both)
2016-11-20 01:46:01 -05:00
if [ [ -n " ${ PKGLIST } " ] ] ;
then
apacman --noconfirm --noedit --skipinteg -S --needed ${ PKGLIST }
apacman --gendb
cleanPacorigs
fi
# And install arch-specific packages for the ISO, if there are any.
2016-12-03 06:07:41 -05:00
#PKGLIST=$(sed -re '/^[[:space:]]*(#|$)/d' /root/iso.pkgs.arch | tr '\n' ' ')
PKGLIST = $( getPkgList /root/iso.pkgs.arch)
2016-11-20 01:46:01 -05:00
if [ [ -n " ${ PKGLIST } " ] ] ;
then
apacman --noconfirm --noedit --skipinteg -S --needed ${ PKGLIST }
apacman --gendb
cleanPacorigs
fi
2016-11-20 02:23:18 -05:00
# Do some post tasks before continuing
apacman --noconfirm --noedit -S --needed customizepkg-scripting
ln -s /usr/lib/libdialog.so.1.2 /usr/lib/libdialog.so
cleanPacorigs
apacman --noconfirm --noedit --skipinteg -S --needed linux
apacman --gendb
cleanPacorigs
2016-11-20 01:46:01 -05:00
# And install EXTRA functionality packages, if there are any.
2016-12-03 06:07:41 -05:00
#PKGLIST=$(sed -re '/^[[:space:]]*(#|$)/d' /root/packages.both | tr '\n' ' ')
PKGLIST = $( getPkgList /root/packages.both)
2016-11-20 01:46:01 -05:00
if [ [ -n " ${ PKGLIST } " ] ] ;
then
2016-12-03 06:07:41 -05:00
echo "Now installing your extra packages. This will take a while and might appear to hang."
#yes 1 | apacman --noconfirm --noedit --skipinteg -S --needed ${PKGLIST}
for p in ${ PKGLIST } ;
do
apacman --noconfirm --noedit --skipinteg -S --needed ${ p }
done
2016-11-20 01:46:01 -05:00
apacman --gendb
cleanPacorigs
fi
2016-11-20 02:23:18 -05:00
# Add the regular user
2016-12-26 13:34:34 -05:00
useradd -m -s /bin/bash -c " ${ USERCOMMENT } " ${ REGUSR }
2018-01-03 12:44:46 -05:00
usermod -aG users,games,video,audio ${ REGUSR } # TODO: remove this in lieu of $REGUSR_GRPS? these are all kind of required, though, for regular users anyways
for g in $( echo ${ REGUSR_GRPS } | sed 's/,[[:space:]]*/ /g' ) ;
do
getent group ${ g } > /dev/null 2>& 1 || groupadd ${ g }
usermod -aG ${ g } ${ REGUSR }
done
2016-11-20 02:23:18 -05:00
passwd -d ${ REGUSR }
# Add them to sudoers
mkdir -p /etc/sudoers.d
chmod 750 /etc/sudoers.d
printf " Defaults: ${ REGUSR } \041lecture\n ${ REGUSR } ALL=(ALL) ALL\n " >> /etc/sudoers.d/${ REGUSR }
# Set the password, if we need to.
if [ [ -n " ${ REGUSR_PASS } " && " ${ REGUSR_PASS } " != 'BLANK' ] ] ;
then
sed -i -e " s|^ ${ REGUSR } ::| ${ REGUSR } : ${ REGUSR_PASS } :|g " /etc/shadow
elif [ [ " ${ REGUSR_PASS } " = = '{[BLANK]}' ] ] ;
then
passwd -d ${ REGUSR }
else
usermod -L ${ REGUSR }
fi
# Set the root password, if we need to.
if [ [ -n " ${ ROOT_PASS } " && " ${ ROOT_PASS } " != 'BLANK' ] ] ;
then
sed -i -e " s|^root::|root: ${ ROOT_PASS } :|g " /etc/shadow
elif [ [ " ${ ROOT_PASS } " = = 'BLANK' ] ] ;
then
passwd -d root
else
usermod -L root
fi
cleanPacorigs
# And install arch-specific extra packages, if there are any.
2016-12-03 06:07:41 -05:00
#PKGLIST=$(sed -re '/^[[:space:]]*(#|$)/d' /root/packages.arch | tr '\n' ' ')
PKGLIST = $( getPkgList /root/packages.arch)
2016-11-20 02:23:18 -05:00
if [ [ -n " ${ PKGLIST } " ] ] ;
then
2016-12-03 06:07:41 -05:00
#apacman --noconfirm --noedit --skipinteg -S --needed ${PKGLIST}
for p in ${ PKGLIST } ;
do
apacman --noconfirm --noedit --skipinteg -S --needed ${ PKGLIST }
done
2016-11-20 02:23:18 -05:00
apacman --gendb
cleanPacorigs
fi
2016-12-03 06:07:41 -05:00
# Run any arch-specific tasks here.
if [ -f '/root/pre-build.arch.sh' ] ;
then
cnt = $( sed -re '/^[[:space:]]*(#|$)/d' /root/pre-build.arch.sh | wc -l)
if [ [ " ${ cnt } " -ge 1 ] ] ;
then
/root/pre-build.arch.sh
fi
rm -f /root/pre-build.arch.sh
fi
2016-11-28 02:56:15 -05:00
# Cleanup
2016-12-01 09:35:06 -05:00
# TODO: look into https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks#Removing_unused_packages_.28orphans.29
2016-12-19 01:16:09 -05:00
mkinitcpio -p linux
2016-12-01 09:35:06 -05:00
paccache -rk0
2016-12-03 06:07:41 -05:00
localepurge-config
localepurge
2016-12-04 02:43:49 -05:00
localepurge-config
localepurge
2016-11-28 02:56:15 -05:00
rm -f /root/.bash_history
rm -f /root/.viminfo
2016-12-01 07:13:24 -05:00
rm -f /root/apacman-*.pkg.tar.xz
rm -f /root/pre-build.sh
2016-12-01 09:35:06 -05:00
pkill -9 dirmngr
2016-12-01 12:47:23 -05:00
pkill -9 gpg-agent