about summary refs log tree commit diff stats
path: root/core/scripts
diff options
context:
space:
mode:
authorSilvino Silva <silvino@bk.ru>2018-02-25 17:33:12 +0000
committerSilvino Silva <silvino@bk.ru>2018-02-25 17:33:12 +0000
commitef1f1f61daaf59d3e07d41ddd0ea713834f35e38 (patch)
tree5a34c6b419adc87a7887db8d2e6d25119e5434c3 /core/scripts
parent080558ffff535c438d6244ff17a5d106622c754e (diff)
downloaddoc-ef1f1f61daaf59d3e07d41ddd0ea713834f35e38.tar.gz
core install revision
Diffstat (limited to 'core/scripts')
-rw-r--r--core/scripts/act-chroot.sh36
-rw-r--r--core/scripts/backup-system.sh189
-rw-r--r--core/scripts/install-core.sh131
-rw-r--r--core/scripts/setup-core.sh154
-rwxr-xr-xcore/scripts/setup-install.sh296
-rw-r--r--core/scripts/setup-iso.sh52
-rwxr-xr-xcore/scripts/setup-target.sh3
7 files changed, 455 insertions, 406 deletions
diff --git a/core/scripts/act-chroot.sh b/core/scripts/act-chroot.sh
index 317b5b7..29103b1 100644
--- a/core/scripts/act-chroot.sh
+++ b/core/scripts/act-chroot.sh
@@ -1,37 +1,15 @@
 #!/bin/bash
 
-
 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
-#mount $BLK_EFI $CHROOT/boot/efi
-#
-#mount $BLK_VAR $CHROOT/var
-#mount $BLK_USR $CHROOT/usr
-#mount $BLK_PRT $CHROOT/usr/ports
-#mount $BLK_HOME $CHROOT/home
+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 -vt devpts devpts $CHROOT/dev/pts
-#mount -vt tmpfs shm $CHROOT/dev/shm
 mount -t proc proc $CHROOT/proc
 mount -t sysfs sys $CHROOT/sys
 mount --bind /dev $CHROOT/dev
diff --git a/core/scripts/backup-system.sh b/core/scripts/backup-system.sh
index 2bced8a..49b9873 100644
--- a/core/scripts/backup-system.sh
+++ b/core/scripts/backup-system.sh
@@ -18,8 +18,47 @@ ConfirmOrExit ()
     echo "You entered $CONFIRM. Continuing ..."
 }
 
+mkbk_coll_pkg() {
+    col=$1
+    # make copy of packages
+    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}
+        fi
+
+        if [ -f /usr/ports/packages/${line} ]; then
+            echo "Backing up package: ${line}"
+            echo ${line} >> ${DEST_DIR}/backup.pkg
+            cp /usr/ports/packages/${line} ${PORT_PKG}/${col}/
+        else
+            echo "Package not found: ${line}"
+            echo ${line} >> ${DEST_DIR}/${col}-notfound.pkg
+        fi
+    done < $DEST_DIR/${col}.pkg
+}
+
+mkbk_coll_ports() {
+    col=$1
+
+    #    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_metadata() {
 
+    # archive pkgutils data
+    tar --xattrs -zcpf $DATA_CNF/pkg-db.tar.gz \
+        /var/lib/pkg/db
+
     # 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
 
@@ -36,80 +75,141 @@ mkbk_metadata() {
 
 }
 
-mkbk_coll_pkg() {
-    col=$1
-    # make copy of packages
-    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}
-            fi
+mkbk_etc_conf() {
 
-            if [ -f /usr/ports/packages/${line} ]; then
-                echo "Backing up package: ${line}"
-                echo ${line} >> ${DEST_DIR}/backup.pkg
-                cp /usr/ports/packages/${line} ${PORT_PKG}/${col}/
-            else
-                echo "Package not found: ${line}"
-                echo ${line} >> ${DEST_DIR}/${col}-notfound.pkg
+    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 \
+        .
+}
+
+mkbk_srv_www() {
+
+    # 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
-    done < $DEST_DIR/${col}.pkg
+            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
 }
 
-mkbk_coll_ports() {
-    col=$1
+mkbk_srv_pgsql() {
 
-#    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/ \
-    .
+    # 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
 }
 
-mkbk_data_conf() {
+mkbk_srv_gitolite() {
 
-    tar --xattrs -zcpf $DATA_CNF/etc.tar.gz \
-        --directory=$ROOT_DIR/etc \
-        .
+    # backup gitolite repositories
 
-    tar --xattrs -zcpf $DATA_CNF/usr_etc.tar.gz \
-        --directory=$ROOT_DIR/usr/etc \
+    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 \
         .
 }
 
+mkbk_user_metadata() {
+
+    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
+}
 
-echo -n "root directory you want backup (/mnt/): "
+echo -n "root directory you want backup (/mnt/):\n "
 #read ROOT_DIR
 ROOT_DIR=$1
 
-echo -n "where you want to save (/home/user): "
+echo -n "where you want to save (/home/user):\n "
 DEST_DIR=$2
 
 # Temporary directory
 PORT_PKG="${DEST_DIR}/crux"
 PORT_PRT="${DEST_DIR}/ports"
 DATA_CNF="${DEST_DIR}/conf"
+DATA_USR="${DEST_DIR}/user"
+DATA_SRV="${DEST_DIR}/srv"
 
 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}"
+echo "DATA_USR=${DATA_USR}"
+echo "DATA_SRV=${DATA_SRV}"
 
 ConfirmOrExit
 
+if [ ${ROOT_DIR} == "/" ]; then
+    ROOT_DIR=""
+fi
+
 mkdir -p ${PORT_PKG}
 mkdir -p ${PORT_PRT}
 mkdir -p ${DATA_CNF}
+mkdir -p ${DATA_USR}
+mkdir -p ${DATA_SRV}
 
+# Light backup data
 mkbk_metadata
-mkbk_data_conf
+mkbk_etc_conf
+mkbk_user_metadata
+mkbk_srv_www
+mkbk_srv_pgsql
+mkbk_srv_gitolite
 
+# Port system
 mkbk_coll_ports "core"
 mkbk_coll_pkg "core"
 mkbk_coll_ports "opt"
@@ -121,20 +221,3 @@ mkbk_coll_pkg "xorg"
 
 mkbk_coll_pkg "other"
 
-#echo $DES_DIR
-#echo $ROOT_DIR
-#
-#tar --xattrs -zcpf $DEST_DIR/system-backup-`date '+%Y-%j-%H-%M-%S'`.tar.gz \
-#    --directory=$ROOT_DIR \
-#    --exclude=usr/ports \
-#    --exclude=usr/src \
-#    --exclude=var/run \
-#    --exclude=var/lock \
-#    --exclude=srv \
-#    --exclude=mnt \
-#    --exclude=home \
-#    --exclude=dev \
-#    --exclude=run \
-#    --exclude=tmp \
-#    --exclude=proc \
-#    --exclude=sys .
diff --git a/core/scripts/install-core.sh b/core/scripts/install-core.sh
new file mode 100644
index 0000000..8e61448
--- /dev/null
+++ b/core/scripts/install-core.sh
@@ -0,0 +1,131 @@
+#!/bin/bash
+
+CHROOT="/mnt"
+PORT_PKG="${CHROOT}/media/crux"
+
+#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
+
+    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_packages() {
+    echo "Installing $CHROOT/media/crux/opt/fakeroot"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/fakeroot#*
+    echo "Installing $CHROOT/media/crux/opt/dbus"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/dbus#*
+    echo "Installing $CHROOT/media/crux/opt/expat"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/expat#*
+    echo "Installing $CHROOT/media/crux/opt/libnl"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/libnl#*
+    echo "Installing $CHROOT/media/crux/opt/libpng"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/libpng#*
+    echo "Installing $CHROOT/media/crux/opt/freetype"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/freetype#*
+    echo "Installing $CHROOT/media/crux/opt/libffi"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/libffi#*
+    echo "Installing $CHROOT/media/crux/opt/sqlite3"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/sqlite3#*
+    echo "Installing $CHROOT/media/crux/opt/python"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/python#*
+    echo "Installing $CHROOT/media/crux/opt/glib"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/glib#*
+    echo "Installing $CHROOT/media/crux/opt/grub2"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/grub2#*
+    echo "Installing $CHROOT/media/crux/opt/grub2-efi"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/grub2-efi#*
+    echo "Installing $CHROOT/media/crux/opt/wireless-tools"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/wireless-tools#*
+    echo "Installing $CHROOT/media/crux/opt/wpa_supplicant"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/wpa_supplicant#*
+    echo "Installing $CHROOT/media/crux/opt/lvm2"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/lvm2#*
+    echo "Installing $CHROOT/media/crux/opt/mdadm"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/mdadm#*
+    echo "Installing $CHROOT/media/crux/opt/efivar"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/efivar#*
+    echo "Installing $CHROOT/media/crux/opt/efibootmgr"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/efibootmgr#*
+    echo "Installing $CHROOT/media/crux/opt/dosfstools"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/dosfstools#*
+    echo "Installing $CHROOT/media/crux/opt/parted"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/parted#*
+    echo "Installing $CHROOT/media/crux/opt/libgcrypt"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/libgcrypt#*
+    echo "Installing $CHROOT/media/crux/opt/cryptsetup"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/cryptsetup#*
+    echo "Installing $CHROOT/media/crux/opt/popt"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/popt#*
+    echo "Installing $CHROOT/media/crux/opt/libgpg-error"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/libgpg-error#*
+    echo "Installing $CHROOT/media/crux/opt/libevent"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/libevent#*
+    echo "Installing $CHROOT/media/crux/opt/libtirpc"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/libtirpc#*
+    echo "Installing $CHROOT/media/crux/opt/git"
+    $CHROOT/usr/bin/pkgadd -f -r $CHROOT $CHROOT/media/crux/opt/git#*
+
+}
+
+echo "PORT_PKG=${PORT_PKG}";
+echo "CHROOT=$CHROOT";
+
+ConfirmOrExit
+install_core
+install_packages
diff --git a/core/scripts/setup-core.sh b/core/scripts/setup-core.sh
new file mode 100644
index 0000000..8a85d4a
--- /dev/null
+++ b/core/scripts/setup-core.sh
@@ -0,0 +1,154 @@
+#!/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_DATA=$(dirname "$SCRIPTPATH");
+
+CHROOT="/mnt"
+DATA_CNF="${DIR_DATA}/conf"
+ADMIN_USER="c9admin"
+
+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/core/scripts/setup-install.sh b/core/scripts/setup-install.sh
deleted file mode 100755
index aca0115..0000000
--- a/core/scripts/setup-install.sh
+++ /dev/null
@@ -1,296 +0,0 @@
-#!/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"
diff --git a/core/scripts/setup-iso.sh b/core/scripts/setup-iso.sh
index e208378..11a38bc 100644
--- a/core/scripts/setup-iso.sh
+++ b/core/scripts/setup-iso.sh
@@ -1,5 +1,16 @@
 #!/bin/sh
 
+ISO_DIR=$1
+CHROOT="/mnt"
+
+ISO_URL="https://serverop.de/crux/crux-3.3/iso/crux-3.3.iso"
+MD5_URL="https://serverop.de/crux/crux-3.3/iso/crux-3.3.md5"
+
+ISO_FILE="${ISO_DIR}/crux-3.3.iso"
+MD5_FILE="${ISO_DIR}/crux-3.3.md5"
+
+
+
 # First we define the function
 ConfirmOrExit ()
 {
@@ -19,35 +30,16 @@ ConfirmOrExit ()
     echo "You entered $CONFIRM. Continuing ..."
 }
 
-# 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";
-
-ISO_URL="https://serverop.de/crux/crux-3.3/iso/crux-3.3.iso"
-MD5_URL="https://serverop.de/crux/crux-3.3/iso/crux-3.3.md5"
+prepare_iso() {
 
-ISO_FILE="${DIR_LOCAL}/crux-3.3.iso"
-MD5_FILE="${DIR_LOCAL}/crux-3.3.md5"
-
-echo "1.1.1 Paths to iso and md5 files:"
-echo "dir: ${DIR_LOCAL}"
-echo "iso url: ${ISO_URL}"
-echo "md5 url: ${MD5_URL}"
-ConfirmOrExit
-mkdir -p ${DIR_LOCAL}
-
-#prepare_iso() {
+    mkdir -p ${ISO_DIR}
 
     if [ -f $ISO_FILE ];
     then
         echo "File $ISO_FILE exists."
     else
         echo "File $ISO_FILE does not exist."
-        cd $DIR_LOCAL && { curl -k -O $ISO_URL ; cd -; }
+        cd $ISO_DIR && { curl -k -O $ISO_URL ; cd -; }
     fi
 
     if [ -f $MD5_FILE ];
@@ -55,15 +47,25 @@ mkdir -p ${DIR_LOCAL}
         echo "File ${MD5_FILE} exists."
     else
         echo "File ${MD5_FILE} does not exist."
-        cd ${DIR_LOCAL} && { curl -k -O ${MD5_URL} ; cd -; }
+        cd ${ISO_DIR} && { curl -k -O ${MD5_URL} ; cd -; }
     fi
 
-    if  cd ${DIR_LOCAL} && md5sum -c ${MD5_FILE} ;
+    if  cd ${ISO_DIR} && md5sum -c ${MD5_FILE} ;
     then
         echo "Valid iso md5sum"
     else
         echo "Invalid iso md5sum"
     fi
 
-#}
+    modprobe isofs
+    modprobe loop
+    mount -o loop $ISO_FILE $CHROOT/media
+}
 
+echo "1.1.1 Paths to iso and md5 files:"
+echo "dir: ${ISO_DIR}"
+echo "iso url: ${ISO_URL}"
+echo "md5 url: ${MD5_URL}"
+
+ConfirmOrExit
+prepare_iso
diff --git a/core/scripts/setup-target.sh b/core/scripts/setup-target.sh
index d46d4bb..b0828e5 100755
--- a/core/scripts/setup-target.sh
+++ b/core/scripts/setup-target.sh
@@ -147,9 +147,6 @@ enable_target () {
     mount -vt proc proc $CHROOT/proc
     mount -vt sysfs sysfs $CHROOT/sys
 
-    modprobe isofs
-    modprobe loop
-    mount -o loop $ISO_FILE $CHROOT/media
 }
 
 print_target() {