#!/bin/bash # Absolute path to this script, # e.g. /home/user/c9-doc/core/scripts/foo.sh SCRIPT=$(readlink -f "$0") # Absolute path this script is in, # e.g. /home/user/c9-doc/core/scripts SCRIPTPATH=$(dirname "$SCRIPT") # Absolute path to doc section, # e.g /home/user/c9-doc/core DIR_SCRIPT=$(dirname "$SCRIPTPATH"); # Absolute path to local data, # e.g /home/user/local DIR_LOCAL="$(dirname $(dirname ${DIR_SCRIPT}))/local"; # Set Global Vars ADMIN_USER=c9admin CHROOT=$1 # DATA_DIR directory with data to # to be installed, can be mounted # iso file or backup directory from # backup-system script # from iso monted; DATA_DIR=$(dirname "$SCRIPTPATH"); PORT_PKG="${CHROOT}/media/crux" # from backup; #DATA_DIR=$2 #PORT_PKG="${DATA_DIR}/crux" ConfirmOrExit() { while true do echo -n "Please confirm (y or n) :" read CONFIRM case $CONFIRM in y|Y|YES|yes|Yes) break ;; n|N|no|NO|No) echo "Aborting - you entered $CONFIRM" exit ;; *) echo "Please enter only y or n" esac done echo "You entered $CONFIRM. Continuing ..." } install_core() { mkdir -p ${CHROOT}/usr/ports/packages mkdir -p ${CHROOT}/var/lib/pkg touch ${CHROOT}/var/lib/pkg/db CORE_LS="${DATA_DIR}/core.pkg" if [ ! -f ${CORE_LS} ]; then CORE_LS=${CHROOT}/core.pkg echo "1.1.4 Create core.pkg and install pkgadd" for p in ${PORT_PKG}/core/*; do echo $(basename $p) >> ${CORE_LS}; done fi tar xf "${PORT_PKG}/core/pkgutils#5.40-1.pkg.tar.xz" usr/bin/pkgadd -O > ${CHROOT}/pkgadd chmod +x ${CHROOT}/pkgadd echo "1.1.4 File core.pkg complete, review list of packages before continue..." read PAUSE vim ${CORE_LS} echo "1.1.4 Starting install" #cd $CHROOT while read line; do pkg=${PORT_PKG}/core/${line} echo "Installing ${pkg};\n" ${CHROOT}/pkgadd -f -r ${CHROOT} ${pkg} done < ${CORE_LS} rm ${CHROOT}/pkgadd if [ -f ${CHROOT}/core.pkg ]; then rm ${CHROOT}/core.pkg; fi } install_ports() { echo "1.1.5. Install core packages and ports;" cp ${PORT_PKG}/core/* ${CHROOT}/usr/ports/packages if [ -f "${PORT_PRT}/core.tar.gz" ]; then mkdir -p ${CHROOT}/usr/ports/core tar --xattrs -xpvf $PORT_PRT/core.tar.gz --directory=$CHROOT/usr/ports/core fi echo "1.1.5. Install opt packages and ports;" cp ${PORT_PKG}/opt/* $CHROOT/usr/ports/packages if [ -f "${PORT_PRT}/opt.tar.gz" ]; then mkdir -p ${CHROOT}/usr/ports/opt tar --xattrs -xpvf $PORT_PRT/opt.tar.gz --directory=$CHROOT/usr/ports/opt fi echo "1.1.5. Install contrib packages and ports;" cp ${PORT_PKG}/contrib/* $CHROOT/usr/ports/packages if [ -f "${PORT_PRT}/contrib.tar.gz" ]; then mkdir -p ${CHROOT}/usr/ports/contrib tar --xattrs -xpvf $PORT_PRT/contrib.tar.gz --directory=$CHROOT/usr/ports/contrib fi echo "1.1.5. Install xorg packages and ports;" cp ${PORT_PKG}/xorg/* $CHROOT/usr/ports/packages if [ -f "${PORT_PRT}/xorg.tar.gz" ]; then mkdir -p ${CHROOT}/usr/ports/xorg tar --xattrs -xpvf $PORT_PRT/xorg.tar.gz --directory=$CHROOT/usr/ports/xorg fi echo "1.1.6. Install extra packages;" cp ${PORT_PKG}/other/* $CHROOT/usr/ports/packages } setup_core() { if [ -f "${DATA_CNF}/etc.tar.gz" ]; then echo "1.1. Extracting configuration data;\n" tar --xattrs -xpvf $DATA_CNF/etc.tar.gz --directory=$CHROOT/etc tar --xattrs -xpvf $DATA_CNF/usr_etc.tar.gz --directory=$CHROOT/usr/etc else echo "1.1. Copying configuration data;\n" cp -r $DATA_CNF/skel $CHROOT/etc/ cp ${PORT_PKG}/handbook.txt $CHROOT/root/ cp /etc/resolv.conf $CHROOT/etc cp $DATA_CNF/fstab $CHROOT/etc/ cp $DATA_CNF/prt-get.conf $CHROOT/etc/ cp $DATA_CNF/sudoers $CHROOT/etc/ cp $DATA_CNF/rc.d/* $CHROOT/etc/rc.d/ cp $DATA_CNF/rc.conf $CHROOT/etc/ cp $DATA_CNF/pkgmk.conf $CHROOT/etc/ cp $DATA_CNF/hosts $CHROOT/etc/ fi echo "1.1.7. dns resolver, copy resolv.conf;\n" vim /etc/resolv.conf echo "1.1.8. Install Handbook\n" echo "1.1.9. Install Skeletons\n" echo "1.2.1. Set hostname and hosts;" vim $CHROOT/etc/hosts echo "1.2.2. Set timezone;" chroot $CHROOT /bin/bash -c tzselect echo "1.2.3. Set locale;" chroot $CHROOT /bin/bash -c "localedef -i en_US -f UTF-8 en_US.UTF-8" echo "1.2.4.2. Create Administrator $ADMIN_USER;" chroot $CHROOT /usr/bin/env -i \ HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /bin/bash -c "useradd -U -m -k /etc/skel -s /bin/bash $ADMIN_USER" echo "1.2.4.3. Add Administrator $ADMIN_USER to wheel group;" chroot $CHROOT /bin/bash -c "usermod -a -G wheel $ADMIN_USER" echo "1.2.4.3. Uncomment to allow members of group wheel to execute any command\n # %wheel ALL=(ALL) ALL" echo "1.2.5. File system table;" chroot $CHROOT /bin/bash -c "mount >> /etc/fstab" chroot $CHROOT /usr/bin/env -i \ HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /bin/bash -c "pkgmk /usr/ports/work tmpfs size=30G,gid=$(id -g pkgmk),uid=$(id pkgmk),defaults,mode=0750 0 0 >> /etc/fstab" vim $CHROOT/etc/fstab echo "1.2.6. Initialization Scripts;" vim $CHROOT/etc/rc.conf echo "1.3.1. Build as unprivileged user;" chroot $CHROOT /usr/bin/env -i \ HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /bin/bash -c "useradd -U -M -d /usr/ports -s /bin/false pkgmk" chroot $CHROOT /usr/bin/env -i \ HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /bin/bash -c "usermod -a -G pkgmk $ADMIN_USER" chroot $CHROOT /usr/bin/env -i \ HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /bin/bash -c "chown -R pkgmk:pkgmk /usr/ports" chroot $CHROOT /usr/bin/env -i \ HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /bin/bash -c "chmod -R 774 /usr/ports" chroot $CHROOT /usr/bin/env -i \ HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /bin/bash -c "chmod 775 /usr/ports" echo "1.3.2. Ports Layout;" chroot --userspec=pkgmk:pkgmk $CHROOT /bin/bash -c "mkdir /usr/ports/work" chroot --userspec=pkgmk:pkgmk $CHROOT /bin/bash -c "mkdir /usr/ports/pkgbuild" chroot --userspec=pkgmk:pkgmk $CHROOT /bin/bash -c "mkdir /usr/ports/distfiles" echo "1.3.3 Configure pkgmk;" #vim $CHROOT/etc/pkgmk.conf echo "1.3.4 Configure prt-get;" mv $CHROOT/etc/ports/contrib.rsync.inactive $CHROOT/etc/ports/contrib.rsync #vim $CHROOT/etc/prt-get.conf } install_packages() { echo "Installing $CHROOT/usr/ports/packages/fakeroot" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/fakeroot#* echo "Installing $CHROOT/usr/ports/packages/dbus" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/dbus#* echo "Installing $CHROOT/usr/ports/packages/expat" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/expat#* echo "Installing $CHROOT/usr/ports/packages/libnl" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/libnl#* echo "Installing $CHROOT/usr/ports/packages/libpng" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/libpng#* echo "Installing $CHROOT/usr/ports/packages/freetype" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/freetype#* echo "Installing $CHROOT/usr/ports/packages/libffi" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/libffi#* echo "Installing $CHROOT/usr/ports/packages/sqlite3" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/sqlite3#* echo "Installing $CHROOT/usr/ports/packages/python" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/python#* echo "Installing $CHROOT/usr/ports/packages/glib" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/glib#* echo "Installing $CHROOT/usr/ports/packages/grub2" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/grub2#* echo "Installing $CHROOT/usr/ports/packages/grub2-efi" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/grub2-efi#* echo "Installing $CHROOT/usr/ports/packages/wireless-tools" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/wireless-tools#* echo "Installing $CHROOT/usr/ports/packages/wpa_supplicant" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/wpa_supplicant#* echo "Installing $CHROOT/usr/ports/packages/lvm2" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/lvm2#* echo "Installing $CHROOT/usr/ports/packages/mdadm" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/mdadm#* echo "Installing $CHROOT/usr/ports/packages/efivar" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/efivar#* echo "Installing $CHROOT/usr/ports/packages/efibootmgr" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/efibootmgr#* echo "Installing $CHROOT/usr/ports/packages/dosfstools" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/dosfstools#* } DATA_CNF="${DATA_DIR}/conf" PORT_PRT="${DATA_DIR}/ports"; #echo "SCRIPT=$SCRIPT"; echo "SCRIPTPATH=$SCRIPTPATH"; echo "ADMIN_USER=${ADMIN_USER}" echo "CHROOT=$CHROOT"; echo "DATA_DIR=$DATA_DIR"; echo "DATA_CNF=$DATA_CNF"; echo "PORT_PKG=${PORT_PKG}"; echo "PORT_PRT=${PORT_PRT}"; ConfirmOrExit install_core install_ports setup_core install_packages echo "Ready to chroot $CHROOT /bin/bash \n"