diff options
Diffstat (limited to 'linux/scripts')
-rw-r--r-- | linux/scripts/act-chroot.sh | 15 | ||||
-rw-r--r-- | linux/scripts/backup-ports.sh | 136 | ||||
-rw-r--r-- | linux/scripts/backup-system.sh | 194 | ||||
-rw-r--r-- | linux/scripts/chroot.sh | 9 | ||||
-rw-r--r-- | linux/scripts/install-core.sh | 179 | ||||
-rw-r--r-- | linux/scripts/portspage.patch | 27 | ||||
-rw-r--r-- | linux/scripts/restore-ports.sh | 53 | ||||
-rw-r--r-- | linux/scripts/setup-core.sh | 154 | ||||
-rw-r--r-- | linux/scripts/setup-iso.sh | 144 | ||||
-rwxr-xr-x | linux/scripts/setup-target.sh | 224 | ||||
-rw-r--r-- | linux/scripts/setup-virtual.sh | 78 |
11 files changed, 1213 insertions, 0 deletions
diff --git a/linux/scripts/act-chroot.sh b/linux/scripts/act-chroot.sh new file mode 100644 index 0000000..29103b1 --- /dev/null +++ b/linux/scripts/act-chroot.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +CHROOT="/mnt" + +mkdir -p $CHROOT/boot/efi +mkdir -p $CHROOT/media + +mkdir -p $CHROOT/dev +mkdir -p $CHROOT/tmp +mkdir -p $CHROOT/proc +mkdir -p $CHROOT/sys + +mount -t proc proc $CHROOT/proc +mount -t sysfs sys $CHROOT/sys +mount --bind /dev $CHROOT/dev diff --git a/linux/scripts/backup-ports.sh b/linux/scripts/backup-ports.sh new file mode 100644 index 0000000..bac18e5 --- /dev/null +++ b/linux/scripts/backup-ports.sh @@ -0,0 +1,136 @@ +#!/bin/bash + +DEST_SYS=/usr/ports/releases/stable +DEST_ARC=/usr/ports/releases/archives + +#PACKAGES=/usr/ports/packages +PACKAGES=/usr/ports/archive/packages + +#PRT_GET_FLAGS="-fr -if -is" +PRT_GET_FLAGS="-fr" + +# Build Name = R1 (System number) D1 (Droid/Machine number) +BUILD_NAME="R1D9" +#echo "Give build NAME;" +#echo "${DEST_ARC}/NAME-0.0.0.targ.gz" +#read BUILD_NAME + +#internal +database=${DEST_SYS}/pkg-db.tar.gz +ports=${DEST_SYS}/etc-ports.tar.gz +metadata=${DEST_SYS}/metadata.tar.gz +build=${DEST_SYS}/metadata/build-version +portsver=${DEST_SYS}/metadata/ports-releases +all=${DEST_SYS}/metadata/all-installed +collinst=${DEST_SYS}/metadata/installed +notfound=${DEST_SYS}/metadata/not-found + +echo "Give build CRUX_RELEASE.VERSION (3.4.X);" +echo "${DEST_ARC}/${BUILD_NAME}-VERSION.tar.gz" +read BUILD_VERSION + +mkdir -p ${DEST_SYS} +mkdir -p ${DEST_ARC} +mkdir -p ${DEST_SYS}/metadata + +archive="${DEST_ARC}/${BUILD_NAME}-${BUILD_VERSION}.tar" +echo "Creating $archive ..." +if [ -f ${archive} ]; then + rm ${archive} +fi + +backup_collections() { + + # backup collection packages + while read COLL_VERSION; do + COLL_NAME=$(echo $COLL_VERSION | cut -d "-" -f 1) + COLL_RELEASE=$(echo $COLL_VERSION | cut -d "-" -f 2) + + if [ -f ${DEST_SYS}/${COLL_VERSION}.tar ]; then + rm ${DEST_SYS}/${COLL_VERSION}.tar + fi + + while read PORT_NAME; do + # get installed version not version on ports + PACKAGE=$(grep "^${PORT_NAME}#" ${all}) + + # check if binary package exist + if [ ! -f /usr/ports/packages/${PACKAGE} ]; then + echo "Building package: ${PACKAGE};" + sudo prt-get update ${PRT_GET_FLAGS} ${PORT_NAME} + fi + + if [ -f /usr/ports/packages/${PACKAGE} ]; then + echo ${PACKAGE} >> ${DEST_SYS}/metadata/${COLL_NAME}-backup + tar rvf ${DEST_SYS}/${COLL_VERSION}.tar --directory=${PACKAGES} ${PACKAGE} + else + echo "Package ${PACKAGE} from ${PORT_NAME} port not found." + echo ${PACKAGE} >> ${notfound}-${COLL_VERSION} + fi + done < ${collinst}-${COLL_NAME} + + tar rvf $archive --directory=${DEST_SYS} ${COLL_VERSION}.tar + + done < ${portsver} +} + +create_metadata() { + + echo "${BUILD_NAME}-${BUILD_VERSION}" > ${build} + + # archive pkgutils data + tar --xattrs -zcpf $database --directory=/var/lib/pkg/ db + tar rvf $archive --directory=${DEST_SYS} $(basename ${database}) + + # archive ports data + tar --xattrs -zcpf $ports --directory=/etc/ports . + tar rvf $archive --directory=${DEST_SYS} $(basename ${ports}) + + # must be using gwak instead of sed + prt-get listinst -v | sed 's/ /#/g' | sed 's/$/.pkg.tar.gz/g' > ${all} + + if [ -f ${portsver} ]; then + rm ${portsver} + fi + + for filename in /etc/ports/*.git; do + source $filename + + echo "${NAME} port collection release (exp; ${BUILD_VERSION}):" + + read RELEASE + echo ${NAME}-${RELEASE} >> ${portsver} + + # backup ports collection + echo "Backing up collection: ${NAME}" + tar --xattrs -zcpf ${DEST_SYS}/"ports"-${NAME}-${RELEASE}.tar.gz \ + --directory=/usr/ports/${NAME} \ + --exclude=.git \ + . + + tar rvf $archive --directory=${DEST_SYS} "ports"-${NAME}-${RELEASE}.tar.gz + + # create list of installed packages + prt-get printf "%i %p %n\n" | grep "yes /usr/ports/${NAME}" | cut -d " " -f 3 > ${collinst}-${NAME} + +done +} + +create_archive() { + tar --xattrs -zcpf ${metadata} --directory=${DEST_SYS} metadata/ + tar rvf $archive --directory=${DEST_SYS} $(basename ${metadata}) +} + +update_host() { + echo "Creating links to /usr/ports/installed" + rm -r /usr/ports/installed + pkg_installed + + echo "Creating ports page" + portspage --title=${BUILD_NAME}-${BUILD_VERSION} /usr/ports/installed > /usr/ports/installed/index.html +} + +create_metadata +backup_collections +create_archive +update_host diff --git a/linux/scripts/backup-system.sh b/linux/scripts/backup-system.sh new file mode 100644 index 0000000..22fe588 --- /dev/null +++ b/linux/scripts/backup-system.sh @@ -0,0 +1,194 @@ +#!/bin/bash + +ROOT_DIR= +DEST_DIR=/root/backup +DEST_SYS="${DEST_DIR}/system" +DATA_CNF="${DEST_DIR}/conf" +DATA_USR="${DEST_DIR}/user" +DATA_SRV="${DEST_DIR}/srv" + +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 ..." +} + +print_data () { + echo "ROOT_DIR=${ROOT_DIR}" + echo "DEST_DIR=${DEST_DIR}" + echo "DEST_SYS=${DEST_SYS}" + echo "DATA_CNF=${DATA_CNF}" + echo "DATA_USR=${DATA_USR}" + echo "DATA_SRV=${DATA_SRV}" +} + +print_help() { + echo "usage: backup-system [options]" + echo "options:" + echo " -r, --root root directory to backup, default /" + echo " -d, --destination save backup, default /root/backup" + echo " -h, --help print help and exit" +} + +while [ "$1" ]; do + case $1 in + -r|--root) + ROOT_DIR=$2 + if [ ${ROOT_DIR} == "/" ]; then + ROOT_DIR="" + fi + shift ;; + -d|--destination) + DEST_DIR=$2 + + # Destination directory + DEST_SYS="${DEST_DIR}/system" + DATA_CNF="${DEST_DIR}/conf" + DATA_USR="${DEST_DIR}/user" + DATA_SRV="${DEST_DIR}/srv" + + shift ;; + -h|--help) + print_help + exit 0 ;; + *) + echo "backup-system: invalid option $1" + print_help + exit 1 ;; + esac + shift +done + +print_data +ConfirmOrExit + +mkdir -p ${DATA_CNF} +mkdir -p ${DATA_USR} +mkdir -p ${DATA_SRV} + +# Backup system settings +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 \ + . + +bacup_home_metadata () { +# User Meta Data + + for dir in /home/*; do + if [ "${dir}" != "/home/lost+found" ]; then + user=$(basename $dir) + tar --xattrs -zcpf "${DATA_USR}/meta-${user}.tar.gz" \ + $dir/.bash_profile \ + $dir/.bashrc \ + $dir/.config \ + $dir/.gitconfig \ + $dir/.gnupg \ + $dir/.irssi \ + $dir/.lynxrc \ + $dir/.mutt \ + $dir/.netrc \ + $dir/.profile \ + $dir/.spectrwm.conf \ + $dir/.ssh \ + $dir/.tmux.conf \ + $dir/.vim \ + $dir/.vimrc \ + $dir/.xinitrc + + # encript data + #gpg --output "${DATA_USR}/meta-${user}.tar.gz.gpg" \ + # --encrypt --recipient user@host \ + # "${DATA_USR}/meta-${user}.tar.gz" + + tar --xattrs -zcpf "${DATA_USR}/gitolite-${user}.tar.gz" \ + $dir/gitolite-admin + fi + done +} + +backup_services () { + # backup web data first stop php and nginx + for pkg_www in ${ROOT_DIR}/srv/www/*; do + if [[ ! $(ls ${pkg_www} | grep -v "backup_deploy") = "" ]]; then + pkg_back="${DATA_SRV}/www" + if [ ! -d ${pkg_back} ]; then + mkdir -p ${pkg_back} + fi + bck_file="${pkg_back}/$(basename ${pkg_www}).tar.gz" + exc="${pkg_www}/backup_deploy" + tar --exclude ${exc} --xattrs -zcpf ${bck_file} ${pkg_www} + fi + done + + # backup database data first dump all databases + pkg_back="${DATA_SRV}/pgsql" + if [ ! -d ${pkg_back} ]; then + mkdir -p ${pkg_back} + fi + pg_dumpall -U postgres | gzip > ${pkg_back}/cluster_dump.gz + + tar --xattrs -zcpf "${pkg_back}/pgsql-conf.tar.gz" \ + ${ROOT_DIR}/srv/pgsql/data/pg_hba.conf \ + ${ROOT_DIR}/srv/pgsql/data/pg_ident.conf \ + ${ROOT_DIR}/srv/pgsql/data/postgresql.conf + + + # backup gitolite repositories + pkg_back="${DATA_SRV}/gitolite" + if [ ! -d ${pkg_back} ]; then + mkdir -p ${pkg_back} + fi + + tar --xattrs -zcpf "${pkg_back}/gitolite.tar.gz" \ + --directory=${ROOT_DIR}/srv/gitolite \ + . +} + +while true +do + echo "Backup User Metadata ?" + echo "Please confirm (y or n): " + read CONFIRM + case $CONFIRM in + n|N|no|NO|No) break ;; + y|Y|YES|yes|Yes) + echo "Accept - you entered $CONFIRM" + bacup_home_metadata + break + ;; + *) echo "Please enter only y or n" + esac +done + +# Server Data +while true +do + echo "Backup Server Data ?" + echo "Please confirm (y or n): " + read CONFIRM + case $CONFIRM in + n|N|no|NO|No) break ;; + y|Y|YES|yes|Yes) + echo "Accept - you entered $CONFIRM" + backup_services + break + ;; + *) echo "Please enter only y or n" + esac +done diff --git a/linux/scripts/chroot.sh b/linux/scripts/chroot.sh new file mode 100644 index 0000000..00fbd78 --- /dev/null +++ b/linux/scripts/chroot.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +CHROOT=/mnt + +chroot $CHROOT /usr/bin/env -i \ + HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + /bin/bash --login + diff --git a/linux/scripts/install-core.sh b/linux/scripts/install-core.sh new file mode 100644 index 0000000..078aa3b --- /dev/null +++ b/linux/scripts/install-core.sh @@ -0,0 +1,179 @@ +#!/bin/bash + +CHROOT="/mnt" +PORT_PKG="${CHROOT}/media/crux" +INSTALL_OPT=0 + +#echo "1.1.8. Install Handbook\n" +#cp ${PORT_PKG}/handbook.txt $CHROOT/root/ + +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}/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 + + # it is required a degree in astrophysics in order to figure out how to extract a file to a target folder + bsdtar -C ${CHROOT} -xf "${PORT_PKG}/core/pkgutils#5.40.7-1.pkg.tar.xz" usr/bin/pkgadd + mv ${CHROOT}/usr/bin/pkgadd ${CHROOT} + chmod +x ${CHROOT}/pkgadd + + echo "1.1.4 File core.pkg complete, review list of packages before continue... [PRESS ENTER]" + 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}" + #${CHROOT}/pkgadd -f -r ${CHROOT} ${pkg} + ${CHROOT}/pkgadd -f -r ${CHROOT} ${pkg} + done < ${CORE_LS} + + rm ${CHROOT}/pkgadd + + if [ -f ${CHROOT}/core.pkg ]; then + rm ${CHROOT}/core.pkg; + fi +} + +install_packages() { + echo "Installing ${PORT_PKG}/opt/fakeroot" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/fakeroot#* + echo "Installing ${PORT_PKG}/opt/dbus" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/dbus#* + echo "Installing ${PORT_PKG}/opt/expat" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/expat#* + echo "Installing ${PORT_PKG}/opt/libnl" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/libnl#* + echo "Installing ${PORT_PKG}/opt/libpng" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/libpng#* + echo "Installing ${PORT_PKG}/opt/freetype" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/freetype#* + echo "Installing ${PORT_PKG}/opt/libffi" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/libffi#* + echo "Installing ${PORT_PKG}/opt/sqlite3" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/sqlite3#* + echo "Installing ${PORT_PKG}/opt/python" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/python#* + echo "Installing ${PORT_PKG}/opt/glib" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/glib#* + echo "Installing ${PORT_PKG}/opt/grub2" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/grub2#* + echo "Installing ${PORT_PKG}/opt/grub2-efi" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/grub2-efi#* + echo "Installing ${PORT_PKG}/opt/wireless-tools" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/wireless-tools#* + echo "Installing ${PORT_PKG}/opt/wpa_supplicant" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/wpa_supplicant#* + echo "Installing ${PORT_PKG}/opt/lvm2" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/lvm2#* + echo "Installing ${PORT_PKG}/opt/mdadm" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/mdadm#* + echo "Installing ${PORT_PKG}/opt/efivar" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/efivar#* + echo "Installing ${PORT_PKG}/opt/efibootmgr" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/efibootmgr#* + echo "Installing ${PORT_PKG}/opt/dosfstools" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/dosfstools#* + echo "Installing ${PORT_PKG}/opt/parted" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/parted#* + echo "Installing ${PORT_PKG}/opt/libgcrypt" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/libgcrypt#* + echo "Installing ${PORT_PKG}/opt/cryptsetup" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/cryptsetup#* + echo "Installing ${PORT_PKG}/opt/popt" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/popt#* + echo "Installing ${PORT_PKG}/opt/libgpg-error" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/libgpg-error#* + echo "Installing ${PORT_PKG}/opt/libevent" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/libevent#* + echo "Installing ${PORT_PKG}/opt/libtirpc" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/libtirpc#* + echo "Installing ${PORT_PKG}/opt/git" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/git#* + echo "Installing ${PORT_PKG}/opt/tmux" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/tmux#* + echo "Installing ${PORT_PKG}/opt/prt-utils" + $CHROOT/usr/bin/pkgadd -f -r $CHROOT ${PORT_PKG}/opt/prt-utils#* +} + +print_data() { + echo "1.1.4 Paths to packages and target:" + echo "chroot: ${CHROOT}" + echo "packages dir: ${PORT_PKG}" + echo "install optional: ${INSTALL_OPT}" +} + +print_help() { + echo "usage: install-core [options]" + echo "options:" + echo " -r, --chroot default chroot is /mnt" + echo " -p, --packages packages directory /mnt/media/crux" + echo " -o, --optional install extra packages" + echo " -h, --help print help and exit" +} + +while [ "$1" ]; do + case $1 in + -r|--chroot) + CHROOT=$2 + shift ;; + -p|--packages) + PORT_PKG=$2 + shift ;; + -o|--optional) + INSTALL_OPT=1 + ;; + -h|--help) + print_help + exit 0 ;; + *) + echo "setup-iso: invalid option $1" + print_help + exit 1 ;; + esac + shift +done + +print_data +ConfirmOrExit +install_core +echo "=========[ core installed ]===========" + +if [[ $INSTALL_OPT -eq 1 ]]; +then + install_packages + echo "=========[ extra packages installed ]===========" +fi diff --git a/linux/scripts/portspage.patch b/linux/scripts/portspage.patch new file mode 100644 index 0000000..94e653a --- /dev/null +++ b/linux/scripts/portspage.patch @@ -0,0 +1,27 @@ +220c220 +< print " <h2>$options{title}</h2>\n"; +--- +> print " <h2><a href=\"https://tribu.semdestino.org/wiki/mirror\">Mirror</a> | <a href=\"https://tribu.semdestino.org/wiki/crux\">Crux</a> | <a href=\"https://tribu.semdestino.org/git/\">Git</a> | <a href=\"https://tribu.semdestino.org/mirror/bugs/\">Build errors</a> | <a href=\"https://tribu.semdestino.org/mirror/distfiles/\">Distfiles</a> | <a href=\"https://tribu.semdestino.org/mirror/releases/archives/$options{title}.tar.gz\">$options{title}.tar.gz</a> | <a href=\"https://tribu.semdestino.org/mirror/archive/\">Archive</a></h2>\n"; +233c233,238 +< print " <tr class=\"header\"><td><b>Port</b></td><td><b>Version</b></td><td><b>Description</b></td>"; +--- +> print " <tr class=\"header\"> +> <td><b>Project page</b></td> +> <td><b>Port</b></td> +> <td><b>Package</b></td> +> <td><b>Description</b></td>"; +> +244,248c249,255 +< print " <tr class=\"$odd\"><td>"; +< $db{$port}{URL} ? print "<a href=\"$db{$port}{URL}\">$port</a>" : print "$port"; +< print "</td><td><a href=\"$options{directory}/$port/\">$db{$port}{version}-$db{$port}{release}</a></td><td>"; +< print $db{$port}{Description} if $db{$port}{Description}; +< print "</td>"; +--- +> my $port_collection=`prt-get info $port | grep "Path:" | cut -d ":" -f 2 | xargs basename`; +> print " <tr class=\"$odd\">"; +> $db{$port}{URL} ? print "<td><a href=\"$db{$port}{URL}\">$port</a></td>" : print "<td>$port</td>"; +> #print "</td><td><a href=\"$options{directory}/$port/\">$db{$port}{version}-$db{$port}{release}</a></td><td>"; +> print "<td><a href=\"https://tribu.semdestino.org/git/$port_collection.git/tree/refs/heads/master\:/$port\">$db{$port}{version}-$db{$port}{release}</a></td>"; +> print "<td><a href=\"https://tribu.semdestino.org/mirror/packages/$port%23$db{$port}{version}-$db{$port}{release}.pkg.tar.gz\">$port#$db{$port}{version}-$db{$port}{release}.pkg.tar.gz</a></td>"; +> print "<td>$db{$port}{Description}</td>" if $db{$port}{Description}; diff --git a/linux/scripts/restore-ports.sh b/linux/scripts/restore-ports.sh new file mode 100644 index 0000000..cf886ab --- /dev/null +++ b/linux/scripts/restore-ports.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +BUILD_NAME=R1D9 +BUILD_VERSION=3.4.1 +WORK_DIR=/usr/ports/work/${BUILD_NAME}-${BUILD_VERSION} + +prepare_archive() { + mkdir -p ${WORK_DIR} + wget --directory-prefix=${WORK_DIR} https://tribu.semdestino.org/mirror/releases/archives/${BUILD_NAME}-${BUILD_VERSION}.tar.gz + echo "extracting ${WORK_DIR}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz..." + tar -C ${WORK_DIR} -xf ${WORK_DIR}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz + rm ${WORK_DIR}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz +} + +extract_archives() { + while read COLL_VERSION; do + COLL_NAME=$(echo $COLL_VERSION | cut -d "-" -f 1) + COLL_RELEASE=$(echo $COLL_VERSION | cut -d "-" -f 2) + echo "extracting ${COLL_VERSION}.tar to /usr/ports/packages" + tar -C /usr/ports/packages -xf ${WORK_DIR}/${COLL_VERSION}.tar + rm ${WORK_DIR}/${COLL_VERSION}.tar + done < ${WORK_DIR}/metadata/ports-releases +} + +update_system() { + mkdir -p ${WORK_DIR}/etc/ports + tar -C ${WORK_DIR}/etc/ports -xf ${WORK_DIR}/etc_ports.tar.gz + cp ${WORK_DIR}/etc/ports/*.git /etc/ports/ + + while read COLL_VERSION; do + COLL_NAME=$(echo $COLL_VERSION | cut -d "-" -f 1) + ports -u $COLL_NAME + done < ${WORK_DIR}/metadata/ports-releases + + # first update with prt-get + prt-get sysup + prt-get --pre-install --post-install update $(prt-get listinst) + prt-get depinst $(prt-get printf "%p %n\n" | grep "/usr/ports/core" | cut -d " " -f 2) + prt-get update $(revdep) + + rejmerge +} + +install_distro() { + while read PACKAGE; do + prt-get depinst $(echo $PACKAGE | cut -d "#" -f 1); + done < ${WORK_DIR}/all-installed.pkg +} + +prepare_archive +extract_archives +update_system +install_distro diff --git a/linux/scripts/setup-core.sh b/linux/scripts/setup-core.sh new file mode 100644 index 0000000..45bce87 --- /dev/null +++ b/linux/scripts/setup-core.sh @@ -0,0 +1,154 @@ +#!/bin/bash + +# Absolute path to this script, +# e.g. /home/user/doc/core/scripts/foo.sh +SCRIPT=$(readlink -f "$0") +# Absolute path this script is in, +# e.g. /home/user/doc/core/scripts +SCRIPTPATH=$(dirname "$SCRIPT") +# Absolute path to doc section, +# e.g /home/user/doc/core +DIR_DATA=$(dirname "$SCRIPTPATH"); + +CHROOT="/mnt" +DATA_CNF="${DIR_DATA}/conf" +ADMIN_USER="machine-admin" + +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 ..." +} + +setup_core() { + + echo "1.1. Copying configuration data;\n" + 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.7. dns resolver, copy resolv.conf;\n" + cp /etc/resolv.conf $CHROOT/etc + + echo "1.1.9. Install Skeletons\n" + cp -r $DATA_CNF/skel $CHROOT/etc/ + + cp $DATA_CNF/sudoers $CHROOT/etc/ + + echo "1.2.1. Set hostname and hosts;" + cp $DATA_CNF/hosts $CHROOT/etc/ + + echo "1.2.5. File system table;" + cp $DATA_CNF/fstab $CHROOT/etc/ + chroot $CHROOT /bin/bash -c "mount >> /etc/fstab" + + echo "1.2.6. Initialization Scripts;" + cp $DATA_CNF/rc.d/* $CHROOT/etc/rc.d/ + cp $DATA_CNF/rc.conf $CHROOT/etc/ + + echo "1.3 Install Ports;" + rm -fr $CHROOT/etc/ports + cp -r $DATA_CNF/ports $CHROOT/etc/ports + cp $DATA_CNF/ports.conf $CHROOT/etc/ports.conf + + echo "1.3.3 Configure pkgmk;" + cp $DATA_CNF/pkgmk.conf $CHROOT/etc/pkgmk.conf + cp $DATA_CNF/pkgmk.conf.harden $CHROOT/etc/pkgmk.conf.harden + + echo "1.3.4 Configure prt-get;" + cp $DATA_CNF/prt-get.conf $CHROOT/etc/ + + fi + + 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" +} + +setup_users(){ + 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.3.1. Ports Layout;" + + chroot --userspec=pkgmk:pkgmk $CHROOT /bin/bash -c "mkdir /usr/ports/{work,distfiles,packages,work,pkgbuild}" + + echo "1.3.2. 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 pkgmk /usr/ports/{distfiles,packages,work,pkgbuild}" + + chroot $CHROOT /usr/bin/env -i \ + HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + /bin/bash -c "chown pkgmk:pkgmk /usr/ports/pkgbuild" + + chroot $CHROOT /usr/bin/env -i \ + HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin \ + /bin/bash -c "chmod g+w /usr/ports/pkgbuild" + + PKGMK_WRK="pkgmk /usr/ports/work tmpfs size=30G,gid=$(id -g pkgmk),uid=$(id -u pkgmk),defaults,mode=0750 0 0 >> /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 "echo ${PKGMK_WRK} >> /etc/fstab" +} + +setup_config(){ + vim $CHROOT/etc/rc.conf + vim $CHROOT/etc/hosts + vim $CHROOT/etc/resolv.conf + vim $CHROOT/etc/fstab + + vim $CHROOT/etc/pkgmk.conf + vim $CHROOT/etc/prt-get.conf +} + +echo "ADMIN_USER=${ADMIN_USER}"; +echo "CHROOT=${CHROOT}"; +echo "DATA_CNF=${DATA_CNF}"; + +ConfirmOrExit + +setup_core +setup_users +setup_config diff --git a/linux/scripts/setup-iso.sh b/linux/scripts/setup-iso.sh new file mode 100644 index 0000000..458284d --- /dev/null +++ b/linux/scripts/setup-iso.sh @@ -0,0 +1,144 @@ +#!/bin/sh + +# location of iso and md5 file +ISO_DIR="/usr/ports/iso" +MOUNT_POINT="/mnt/media" + +ISO_FILE="${ISO_DIR}/crux-3.5.iso" +MD5_FILE="${ISO_DIR}/crux-3.5.md5" + +# iso and md5 remote location +#ISO_URL="https://serverop.de/crux/crux-3.5/iso/crux-3.5.iso" +ISO_URL="https://ftp.spline.inf.fu-berlin.de/pub/crux/crux-3.5/iso/crux-3.5.iso" +MD5_URL="https://serverop.de/crux/crux-3.5/iso/crux-3.5.md5" + +# 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 ..." +} + +download_iso() { + + mkdir -p ${ISO_DIR} + + if [ -f $ISO_FILE ]; + then + echo "File $ISO_FILE exists." + else + echo "File $ISO_FILE does not exist." + cd $ISO_DIR && { curl -k -O $ISO_URL ; cd -; } + fi + + if [ -f $MD5_FILE ]; + then + echo "File ${MD5_FILE} exists." + else + echo "File ${MD5_FILE} does not exist." + cd ${ISO_DIR} && { curl -k -O ${MD5_URL} ; cd -; } + fi + +} + +check_iso() { + if cd ${ISO_DIR} && md5sum -c ${MD5_FILE} ; + then + echo "Valid iso md5sum" + else + echo "Invalid iso md5sum" + fi +} + +mount_iso() { + + if [ ! -f $ISO_FILE ]; + then + echo "File $ISO_FILE does not exist." + exit 0 + fi + + modprobe isofs + modprobe loop + mount -o loop $ISO_FILE $MOUNT_POINT +} + +print_data() { + echo "1.1.1 Paths to iso and md5 files:" + echo "iso dir: ${ISO_DIR}" + echo "iso file: ${ISO_FILE}" + echo "md5 file: ${MD5_FILE}" + echo "iso url: ${ISO_URL}" + echo "md5 url: ${MD5_URL}" + echo "mount point: ${MOUNT_POINT}" +} + +print_help() { + echo "usage: setup-iso [options]" + echo "options:" + echo " -r, --root default dir is /usr/ports/iso" + echo " -d, --download download iso" + echo " -c, --check check iso md5sum" + echo " -m, --mount mount iso on /media " + echo " -h, --help print help and exit" +} + +while [ "$1" ]; do + case $1 in + -r|--root) + ISO_DIR=$2 + + ISO_FILE="${ISO_DIR}/crux-3.5.iso" + MD5_FILE="${ISO_DIR}/crux-3.5.md5" + + shift ;; + -d|--download) + echo "Download iso:" + echo "_____________________" + print_data + ConfirmOrExit + download_iso + exit 0 ;; + -c|--check) + echo "Check iso md5sum:" + echo "_____________________" + print_data + ConfirmOrExit + check_iso + exit 0 ;; + -m|--mount) + echo "Check iso md5sum:" + echo "_____________________" + if [ ! -z "$2" ]; + then + MOUNT_POINT=$2 + fi + print_data + ConfirmOrExit + mount_iso + exit 0 ;; + -h|--help) + print_help + exit 0 ;; + *) + echo "setup-iso: invalid option $1" + print_help + exit 1 ;; + esac + shift +done + +echo "setup-iso: no option provided" +print_help +exit 1 diff --git a/linux/scripts/setup-target.sh b/linux/scripts/setup-target.sh new file mode 100755 index 0000000..69b8640 --- /dev/null +++ b/linux/scripts/setup-target.sh @@ -0,0 +1,224 @@ +#!/bin/sh + +DEV=/dev/sda +VG=vg_system + +SETUP_TARGET="print" +CHROOT="/mnt" + +# Absolute path to this script, e.g. /home/user/bin/foo.sh +SCRIPT=$(readlink -f "$0") +# Absolute path this script is in, thus /home/user/bin +SCRIPTPATH=$(dirname "$SCRIPT") + +DIR=$(dirname "$SCRIPTPATH"); +DIR_LOCAL="$(dirname $(dirname ${DIR}))/local"; + +##read BLK_EFI +BLK_EFI="${DEV}2" +##read BLK_BOOT +BLK_BOOT="${DEV}3" +##read BLK_ROOT +BLK_CRYPT="${DEV}4" +BLK_ROOT="/dev/$VG/lv_root" +##read BLK_VAR +BLK_VAR="/dev/${VG}/lv_var" +##read BLK_USR +#BLK_USR="${DEV}6" +##read BLK_SWP +BLK_SWP="/dev/${VG}/lv_swap" +##read BLK_HOME +BLK_HOME="/dev/${VG}/lv_home" + + +# 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 ..." +} + + +partition_target () { + + parted --script $DEV \ + mklabel gpt \ + unit mib \ + mkpart primary 1 3 \ + name 1 grub \ + set 1 bios_grub on \ + mkpart ESP fat32 3 125 \ + name 2 efi \ + set 2 boot on \ + mkpart primary ext4 125 1128 \ + name 3 boot \ + mkpart primary 1128 100% \ + set 4 lvm on + + modprobe dm-crypt + cryptsetup luksFormat ${BLK_CRYPT} + cryptsetup luksOpen ${BLK_CRYPT} cryptlvm + + pvcreate /dev/mapper/cryptlvm + vgcreate ${VG} /dev/mapper/cryptlvm + + lvcreate -L 20G -n lv_root ${VG} + lvcreate -L 4G -n lv_var ${VG} + lvcreate -L 8G -n lv_swap ${VG} + lvcreate -L 120G -n lv_home ${VG} + +} + +mount_target () { + echo "1.1.2 Creating File System on $BLK_EFI with fat32:" + mkfs.fat -F 32 $BLK_EFI + echo "1.1.2 Creating File System on $BLK_BOOT with ext4:" + mkfs.ext4 $BLK_BOOT + echo "1.1.2 Creating File System on $BLK_ROOT with ext4:" + mkfs.ext4 $BLK_ROOT + echo "1.1.2 Creating File System on $BLK_VAR with ext4:" + mkfs.ext4 $BLK_VAR + #echo "1.1.2 Creating File System on $BLK_USR with ext4:" + #mkfs.ext4 $BLK_USR + echo "1.1.2 Creating Swap File System on $BLK_SWP:" + mkswap $BLK_SWP + echo "1.1.2 Creating File System on $BLK_HOME with ext4:" + mkfs.ext4 $BLK_HOME + + echo "1.1.3 mount point to chroot (/mnt):\n" + mount $BLK_ROOT $CHROOT + + mkdir -p $CHROOT/boot + mount $BLK_BOOT $CHROOT/boot + + mkdir -p $CHROOT/boot/efi + mount $BLK_EFI $CHROOT/boot/efi + + mkdir -p $CHROOT/var + mount $BLK_VAR $CHROOT/var + + #mkdir -p $CHROOT/usr + #mount $BLK_USR $CHROOT/usr + + mkdir -p $CHROOT/home + mount $BLK_HOME $CHROOT/home + + mkdir -p $CHROOT/var/lib/pkg + mkdir -p $CHROOT/usr/ports + + mkdir -p $CHROOT/media + + mkdir -p $CHROOT/dev + mkdir -p $CHROOT/tmp + mkdir -p $CHROOT/proc + mkdir -p $CHROOT/sys + +} + +directory_target () { + + mkdir -p $CHROOT/home + mkdir -p $CHROOT/boot/efi + mkdir -p $CHROOT/var/lib/pkg + mkdir -p $CHROOT/usr/ports + + mkdir -p $CHROOT/media + + mkdir -p $CHROOT/dev + mkdir -p $CHROOT/tmp + mkdir -p $CHROOT/proc + mkdir -p $CHROOT/sys + +} + + +enable_target () { + + mount --bind /dev $CHROOT/dev + mount -vt devpts devpts $CHROOT/dev/pts + mount -vt tmpfs shm $CHROOT/dev/shm + mount -vt proc proc $CHROOT/proc + mount -vt sysfs sysfs $CHROOT/sys + +} + +print_target() { + echo "Device: $DEV" + echo "CHROOT: $CHROOT" + echo "Option Selected: $SETUP_TARGET" + + echo "1.1.2 EFI block; ($BLK_EFI)" + echo "1.1.2 boot block; ($BLK_BOOT)" + echo "1.1.2 cryptlvm block; ($BLK_CRYPT)" + echo "1.1.2 root block; ($BLK_ROOT)" + echo "1.1.2 var block; ($BLK_VAR)" + echo "1.1.2 usr block; ($BLK_USR)" + echo "1.1.2 swap block; ($BLK_SWP)" + echo "1.1.2 home block; ($BLK_HOME)" + + +} + +print_help() { + echo "usage: setup_target [options]" + echo "options:" + echo " -p, --partition create partitions and file systems" + echo " -m, --mount mount partitions on chroot" + echo " -d, --directory keep temporary working directory" + echo " -e, --enable enable chroot (proc,dev, sys...)" + echo " -v, --view view environment vars and exit" + echo " -h, --help print help and exit" +} + + +while [ "$1" ]; do + case $1 in + -p|--partition) + SETUP_TARGET="partition" + print_target + ConfirmOrExit + partition_target + exit 0 ;; + -m|--mount) + SETUP_TARGET="mount" + print_target + ConfirmOrExit + mount_target + exit 0 ;; + -d|--directory) + SETUP_TARGET="directory" + print_target + ConfirmOrExit + directory_target + exit 0 ;; + -e|--enable) + SETUP_TARGET="enable" + print_target + ConfirmOrExit + enable_target + exit 0 ;; + -v|--view) + SETUP_TARGET="view" + print_target + exit 0 ;; + -h|--help) + print_help + exit 0 ;; + *) + echo "setup-target: invalid option $1" + exit 1 ;; + esac + shift +done diff --git a/linux/scripts/setup-virtual.sh b/linux/scripts/setup-virtual.sh new file mode 100644 index 0000000..3583bb6 --- /dev/null +++ b/linux/scripts/setup-virtual.sh @@ -0,0 +1,78 @@ +#!/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} +IMG=${2}.qcow2 +SIZE=${3} +CHROOT="/mnt" +DEV="/dev/${DEV_NAME}" + +echo "/srv/qemu/img/${IMG}" +echo "${SIZE}" +echo "DEV_NAME=${DEV_NAME}" +echo "DEV=${DEV}" +echo "CHROOT=${CHROOT}" + +ConfirmOrExit + +#qemu-img create -f qcow2 example.qcow2 20G +qemu-img create -f qcow2 /srv/qemu/img/${IMG} ${SIZE} +qemu-nbd -c ${DEV} /srv/qemu/img/${IMG} + +parted --script ${DEV} \ + mklabel gpt \ + unit mib \ + mkpart primary 2 4 \ + name 1 grub \ + mkpart ESP fat32 4 128 \ + name 2 efi \ + mkpart primary ext4 128 1128 \ + name 3 boot \ + mkpart primary ext4 1128 12128 \ + name 4 root \ + mkpart primary ext4 12128 14128 \ + name 5 var \ + mkpart primary ext4 14128 100% \ + name 6 lvm \ + set 1 bios_grub on \ + set 2 boot on \ + set 6 lvm on + +kpartx -a -s -l -u ${DEV} + +mkfs.fat -F 32 /dev/mapper/${DEV_NAME}p2 +mkfs.ext4 /dev/mapper/${DEV_NAME}p3 +mkfs.ext4 /dev/mapper/${DEV_NAME}p4 +mkfs.ext4 /dev/mapper/${DEV_NAME}p5 +pvcreate /dev/mapper/${DEV_NAME}p6 + +mount /dev/mapper/${DEV_NAME}p4 $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}p5 $CHROOT/var |