diff options
Diffstat (limited to 'core/scripts')
-rw-r--r-- | core/scripts/act-chroot.sh | 35 | ||||
-rw-r--r-- | core/scripts/backup-system.sh | 122 | ||||
-rwxr-xr-x | core/scripts/setup-install.sh | 192 | ||||
-rw-r--r-- | core/scripts/setup-virtual.sh | 76 |
4 files changed, 314 insertions, 111 deletions
diff --git a/core/scripts/act-chroot.sh b/core/scripts/act-chroot.sh index 5411bc5..317b5b7 100644 --- a/core/scripts/act-chroot.sh +++ b/core/scripts/act-chroot.sh @@ -1,26 +1,25 @@ #!/bin/bash -DEV=$1 CHROOT="/mnt" -##read BLK_EFI -BLK_EFI="${DEV}2" -##read BLK_BOOT -BLK_BOOT="${DEV}3" -##read BLK_ROOT -BLK_ROOT="${DEV}4" -##read BLK_VAR -BLK_VAR="${DEV}5" -##read BLK_USR -BLK_USR="${DEV}6" -##read BLK_SWP -BLK_SWP="${DEV}7" -##read BLK_HOME -BLK_HOME="${DEV}8" - -#read CHROOT -CHROOT="/mnt" +#DEV=$1 +# +###read BLK_EFI +#BLK_EFI="${DEV}2" +###read BLK_BOOT +#BLK_BOOT="${DEV}3" +###read BLK_ROOT +#BLK_ROOT="${DEV}4" +###read BLK_VAR +#BLK_VAR="${DEV}5" +###read BLK_USR +#BLK_USR="${DEV}6" +###read BLK_SWP +#BLK_SWP="${DEV}7" +###read BLK_HOME +#BLK_HOME="${DEV}8" +# #mount $BLK_ROOT $CHROOT # #mount $BLK_BOOT $CHROOT/boot diff --git a/core/scripts/backup-system.sh b/core/scripts/backup-system.sh index 379e449..2bced8a 100644 --- a/core/scripts/backup-system.sh +++ b/core/scripts/backup-system.sh @@ -1,55 +1,125 @@ #!/bin/sh -echo -n "root directory you want backup (/mnt/): " -read ROOT_DIR +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 ..." +} -echo -n "where you want to save (/home/user): " -read DEST_DIR +mkbk_metadata() { + + # must be using gwak instead of sed, xargs and echo + prt-get listinst -v | sed -s s/" "/#/g | xargs -i echo {}.pkg.tar.gz > ${DEST_DIR}/installed.pkg + + # make list and copy installed core packages + prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/core" | cut -d " " -f 3 > ${DEST_DIR}/core.pkg + + prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/opt" | cut -d " " -f 3 > $DEST_DIR/opt.pkg + + prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/contrib" | cut -d " " -f 3 > $DEST_DIR/contrib.pkg -bk_coll() { + prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/xorg" | cut -d " " -f 3 > $DEST_DIR/xorg.pkg + + prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep -v "yes /usr/ports/core" | grep -v "yes /usr/ports/opt" | grep -v "yes /usr/ports/contrib" | grep -v "yes /usr/ports/xorg" | grep "yes " | cut -d " " -f 3 > $DEST_DIR/other.pkg + +} + +mkbk_coll_pkg() { col=$1 # make copy of packages - mkdir ${BKDIR}/${col} + mkdir ${PORT_PKG}/${col} while read line; do if [ ! -f /usr/ports/packages/${line} ]; then echo "Building package: ${line};\n" name=$(echo ${line} | cut -d "#" -f 1) - sudo prt-get update -fr ${name} + #$sudo prt-get update -fr ${name} fi if [ -f /usr/ports/packages/${line} ]; then echo "Backing up package: ${line}" - echo ${line} >> ${BKDIR}/backup.pkg - cp /usr/ports/packages/${line} ${BKDIR}/${col}/ + echo ${line} >> ${DEST_DIR}/backup.pkg + cp /usr/ports/packages/${line} ${PORT_PKG}/${col}/ else echo "Package not found: ${line}" - echo ${line} >> ${BKDIR}/${col}-notfound.pkg + echo ${line} >> ${DEST_DIR}/${col}-notfound.pkg fi - done < $BKDIR/${col}.pkg + done < $DEST_DIR/${col}.pkg } -# Temporary directory -BKDIR=$(pwd)/bkdir -mkdir -p ${BKDIR} +mkbk_coll_ports() { + col=$1 -# must be using gwak instead of sed, xargs and echo -prt-get listinst -v | sed -s s/" "/#/g | xargs -i echo {}.pkg.tar.gz > ${BKDIR}/installed.pkg +# tar --xattrs -zcpf $PORT_PRT/${col}-`date '+%Y-%j-%H-%M-%S'`.tar.gz \ +# --directory=$ROOT_DIR/usr/ports/${col} \ +# . + tar --xattrs -zcpf $PORT_PRT/${col}.tar.gz \ + --directory=$ROOT_DIR/usr/ports/${col} \ + --exclude=.git/ \ + . + +} + +mkbk_data_conf() { + + tar --xattrs -zcpf $DATA_CNF/etc.tar.gz \ + --directory=$ROOT_DIR/etc \ + . + + tar --xattrs -zcpf $DATA_CNF/usr_etc.tar.gz \ + --directory=$ROOT_DIR/usr/etc \ + . +} + + +echo -n "root directory you want backup (/mnt/): " +#read ROOT_DIR +ROOT_DIR=$1 + +echo -n "where you want to save (/home/user): " +DEST_DIR=$2 + +# Temporary directory +PORT_PKG="${DEST_DIR}/crux" +PORT_PRT="${DEST_DIR}/ports" +DATA_CNF="${DEST_DIR}/conf" -# make list and copy installed core packages -prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/core" | cut -d " " -f 3 > ${BKDIR}/core.pkg -bk_coll "core" +echo "ROOT_DIR=${ROOT_DIR}" +echo "DEST_DIR=${DEST_DIR}" +echo "PORT_PKG=${PORT_PKG}" +echo "PORT_PRT=${PORT_PRT}" +echo "DATA_CNF=${DATA_CNF}" +ConfirmOrExit -prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/opt" | cut -d " " -f 3 > $BKDIR/opt.pkg -bk_coll "opt" +mkdir -p ${PORT_PKG} +mkdir -p ${PORT_PRT} +mkdir -p ${DATA_CNF} -prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/contrib" | cut -d " " -f 3 > $BKDIR/contrib.pkg -bk_coll "contrib" +mkbk_metadata +mkbk_data_conf -prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/xorg" | cut -d " " -f 3 > $BKDIR/xorg.pkg -bk_coll "xorg" +mkbk_coll_ports "core" +mkbk_coll_pkg "core" +mkbk_coll_ports "opt" +mkbk_coll_pkg "opt" +mkbk_coll_ports "contrib" +mkbk_coll_pkg "contrib" +mkbk_coll_ports "xorg" +mkbk_coll_pkg "xorg" -prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep -v "yes /usr/ports/core" | grep -v "yes /usr/ports/opt" | grep -v "yes /usr/ports/contrib" | grep -v "yes /usr/ports/xorg" | grep "yes " | cut -d " " -f 3 > $BKDIR/other.pkg +mkbk_coll_pkg "other" #echo $DES_DIR #echo $ROOT_DIR diff --git a/core/scripts/setup-install.sh b/core/scripts/setup-install.sh index c1d2765..aca0115 100755 --- a/core/scripts/setup-install.sh +++ b/core/scripts/setup-install.sh @@ -1,29 +1,34 @@ #!/bin/bash -# Set Global Vars -ADMIN_USER=c9admin -DEV=$1 -CHROOT=$2 - # 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, +# 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=$(dirname "$SCRIPTPATH"); +DIR_SCRIPT=$(dirname "$SCRIPTPATH"); # Absolute path to local data, # e.g /home/user/local -DIR_LOCAL="$(dirname $(dirname ${DIR}))/local"; - - -DIR_CONF="${DIR}/conf" -DIR_PRT="${DIR}/ports"; -ISO_FILE="${DIR_LOCAL}/crux-3.3.iso" +DIR_LOCAL="$(dirname $(dirname ${DIR_SCRIPT}))/local"; -ConfirmOrExit () +# 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 @@ -44,47 +49,110 @@ ConfirmOrExit () install_core() { - echo "1.1.4 Create core.lst and install pkgadd" - for p in ${CHROOT}mnt/media/crux/core/*; do echo $p >> ${CHROOT}core.lst; done + mkdir -p ${CHROOT}/usr/ports/packages + mkdir -p ${CHROOT}/var/lib/pkg + touch ${CHROOT}/var/lib/pkg/db + + CORE_LS="${DATA_DIR}/core.pkg" - tar xf "${CHROOT}mnt/media/crux/core/pkgutils#5.40-1.pkg.tar.xz" usr/bin/pkgadd -O > ${CHROOT}pkgadd + 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 - chmod +x ${CHROOT}pkgadd + tar xf "${PORT_PKG}/core/pkgutils#5.40-1.pkg.tar.xz" usr/bin/pkgadd -O > ${CHROOT}/pkgadd - echo "1.1.4 File core.lst complete, review list of packages before continue..." + chmod +x ${CHROOT}/pkgadd + + echo "1.1.4 File core.pkg complete, review list of packages before continue..." read PAUSE - vim ${CHROOT}core.lst + vim ${CORE_LS} echo "1.1.4 Starting install" - touch ${CHROOT}/var/lib/pkg/db - cd $CHROOT + #cd $CHROOT while read line; do - echo "Installing $line;\n" - ${CHROOT}pkgadd -u -f -r ${CHROOT} ${line} - done < ${CHROOT}core.lst + pkg=${PORT_PKG}/core/${line} + echo "Installing ${pkg};\n" + ${CHROOT}/pkgadd -f -r ${CHROOT} ${pkg} + done < ${CORE_LS} - rm ${CHROOT}pkgadd - rm ${CHROOT}core.lst + rm ${CHROOT}/pkgadd - mkdir ${CHROOT}usr/ports/packages - cp ${CHROOT}media/crux/core/* ${CHROOT}usr/ports/packages + 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" - cp /etc/resolv.conf $CHROOT/etc + vim /etc/resolv.conf echo "1.1.8. Install Handbook\n" - cp $CHROOT/media/crux/handbook.txt $CHROOT/root/ echo "1.1.9. Install Skeletons\n" - cp -r $DIR_CONF/skel $CHROOT/etc/ echo "1.2.1. Set hostname and hosts;" - cp $DIR_CONF/hosts $CHROOT/etc/ vim $CHROOT/etc/hosts echo "1.2.2. Set timezone;" @@ -103,16 +171,19 @@ setup_core() { 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" - cp $DIR_CONF/sudoers $CHROOT/etc/ echo "1.2.5. File system table;" - cp $DIR_CONF/fstab $CHROOT/etc/ + 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;" - cp $DIR_CONF/rc.d/* $CHROOT/etc/rc.d/ - cp $DIR_CONF/rc.conf $CHROOT/etc/ vim $CHROOT/etc/rc.conf echo "1.3.1. Build as unprivileged user;" @@ -130,7 +201,7 @@ setup_core() { 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 root:pkgmk /usr/ports" + /bin/bash -c "chown -R pkgmk:pkgmk /usr/ports" chroot $CHROOT /usr/bin/env -i \ HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ @@ -148,30 +219,16 @@ setup_core() { chroot --userspec=pkgmk:pkgmk $CHROOT /bin/bash -c "mkdir /usr/ports/pkgbuild" chroot --userspec=pkgmk:pkgmk $CHROOT /bin/bash -c "mkdir /usr/ports/distfiles" - chroot $CHROOT /usr/bin/env -i \ - HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ - PATH=/bin:/usr/bin:/sbin:/usr/sbin \ - /bin/bash -c "id pkgmk >> /etc/fstab" - - echo "pkgmk /usr/ports/work tmpfs size=30G,gid=102,uid=101,defaults,mode=0750 0 0" >> $CHROOT/etc/fstab - - vim $CHROOT/etc/fstab - echo "1.3.3 Configure pkgmk;" - cp $DIR_CONF/pkgmk.conf $CHROOT/etc/ #vim $CHROOT/etc/pkgmk.conf echo "1.3.4 Configure prt-get;" mv $CHROOT/etc/ports/contrib.rsync.inactive $CHROOT/etc/ports/contrib.rsync - cp $DIR_CONF/prt-get.conf $CHROOT/etc/ #vim $CHROOT/etc/prt-get.conf } -install_packages() { - echo "1.1.5. Install extra packages;" - cp $CHROOT/media/crux/opt/* $CHROOT/usr/ports/packages - cp $CHROOT/media/crux/xorg/* $CHROOT/usr/ports/packages +install_packages() { echo "Installing $CHROOT/usr/ports/packages/fakeroot" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/fakeroot#* @@ -212,27 +269,28 @@ install_packages() { echo "Installing $CHROOT/usr/ports/packages/dosfstools" $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/usr/ports/packages/dosfstools#* - echo "1.1.6. Install extra ports;\n" +} + - mkdir $CHROOT/usr/ports/c9-ports - cp -r $DIR_PRT/* $CHROOT/usr/ports/c9-ports/ +DATA_CNF="${DATA_DIR}/conf" +PORT_PRT="${DATA_DIR}/ports"; -} -echo "SCRIPT=$SCRIPT"; +#echo "SCRIPT=$SCRIPT"; echo "SCRIPTPATH=$SCRIPTPATH"; -echo "ADMIN_USER="$ADMIN_USER"\n" +echo "ADMIN_USER=${ADMIN_USER}" echo "CHROOT=$CHROOT"; -echo "DIR=$DIR"; -echo "DIR_CONF=$DIR_CONF"; -echo "DIR_PRT=$DIR_PRT"; -echo "ISO_FILE=$ISO_FILE"; +echo "DATA_DIR=$DATA_DIR"; +echo "DATA_CNF=$DATA_CNF"; +echo "PORT_PKG=${PORT_PKG}"; +echo "PORT_PRT=${PORT_PRT}"; + ConfirmOrExit -echo "press enter to continue" -read + install_core -#setup_core -#install_packages +install_ports +setup_core +install_packages echo "Ready to chroot $CHROOT /bin/bash \n" diff --git a/core/scripts/setup-virtual.sh b/core/scripts/setup-virtual.sh new file mode 100644 index 0000000..2b27a9f --- /dev/null +++ b/core/scripts/setup-virtual.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +# First we define the function +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 ..." +} + +DEV_NAME=${1} +CHROOT="/mnt" +DEV="/dev/${DEV_NAME}" + +echo "DEV_NAME=${DEV_NAME}" +echo "DEV=${DEV}" +echo "CHROOT=${CHROOT}" + +ConfirmOrExit + +parted --script ${DEV} \ + mklabel gpt \ + unit mib \ + mkpart primary 1 3 \ + set 1 bios_grub on \ + name 1 grub \ + mkpart ESP fat32 3 59 \ + set 2 boot on \ + name 2 efi \ + mkpart primary ext4 103 200 \ + name 3 boot \ + mkpart primary linux-swap 200 456 \ + name 4 swap \ + mkpart primary ext4 456 3700 \ + name 5 root \ + mkpart primary ext4 3700 4000 \ + name 6 var \ + mkpart primary ext4 4000 100% \ + name 7 home + +kpartx -a -s -l -u ${DEV} + +mkfs.fat -F 32 /dev/mapper/${DEV_NAME}p2 +mkfs.ext4 /dev/mapper/${DEV_NAME}p3 +mkswap /dev/mapper/${DEV_NAME}p4 +mkfs.ext4 /dev/mapper/${DEV_NAME}p5 +mkfs.ext4 /dev/mapper/${DEV_NAME}p6 +mkfs.ext4 /dev/mapper/${DEV_NAME}p7 + +mount /dev/mapper/${DEV_NAME}p5 $CHROOT +mkdir -p $CHROOT/proc +mkdir -p $CHROOT/sys +mkdir -p $CHROOT/dev +mkdir -p $CHROOT/media + +mkdir -p $CHROOT/boot +mount /dev/mapper/${DEV_NAME}p3 $CHROOT/boot +mkdir -p $CHROOT/boot/efi +mount /dev/mapper/${DEV_NAME}p2 $CHROOT/boot/efi +mkdir -p $CHROOT/var +mount /dev/mapper/${DEV_NAME}p6 $CHROOT/var +mkdir -p $CHROOT/home +mount /dev/mapper/${DEV_NAME}p7 $CHROOT/home + + |