aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'config.d/controller/modules')
-rw-r--r--config.d/controller/modules/cfunctions.sh465
-rwxr-xr-xconfig.d/controller/modules/cinit_clean.sh36
-rwxr-xr-xconfig.d/controller/modules/cinit_mount_dev.sh82
-rwxr-xr-xconfig.d/controller/modules/cinit_pre-mount.sh237
-rw-r--r--config.d/controller/modules/dr_config29
-rw-r--r--config.d/controller/modules/dracut_modules63
-rw-r--r--config.d/controller/modules/files/ccoptions345
-rw-r--r--config.d/controller/modules/files/ccustom_pacl13
-rw-r--r--config.d/controller/modules/files/ccustom_scripts16
-rw-r--r--config.d/controller/modules/files/cdevname.info11
-rw-r--r--config.d/controller/modules/files/cfeatures10
-rw-r--r--config.d/controller/modules/files/cfstab.info10
-rw-r--r--config.d/controller/modules/files/cgentoo.conf12
-rw-r--r--config.d/controller/modules/files/cinject_files11
-rw-r--r--[-rwxr-xr-x]config.d/controller/modules/files/controller_gpg/gpg_pub (renamed from config.d/controller/modules/cinit_mount.sh)0
-rw-r--r--config.d/controller/modules/files/controller_ssh/cknown_hosts (renamed from config.d/controller/modules/sources/servers)0
-rw-r--r--config.d/controller/modules/files/controller_ssh/cssh_config (renamed from config.d/controller/modules/files/csshd)0
-rw-r--r--config.d/controller/modules/files/controller_ssh/cssh_priv0
-rw-r--r--config.d/controller/modules/files/system_configs/cconsolefont (renamed from config.d/controller/modules/files/cconsolefont)0
-rw-r--r--config.d/controller/modules/files/system_configs/cfstab (renamed from config.d/controller/modules/files/cfstab)0
-rw-r--r--config.d/controller/modules/files/system_configs/cgrub (renamed from config.d/controller/modules/files/cgrub)0
-rw-r--r--config.d/controller/modules/files/system_configs/chostname (renamed from config.d/controller/modules/files/chostname)0
-rw-r--r--config.d/controller/modules/files/system_configs/chosts (renamed from config.d/controller/modules/files/chosts)0
-rw-r--r--config.d/controller/modules/files/system_configs/clocale.gen (renamed from config.d/controller/modules/files/clocale.gen)0
-rw-r--r--config.d/controller/modules/files/system_configs/cnet (renamed from config.d/controller/modules/files/cnet)0
-rw-r--r--config.d/controller/modules/files/system_configs/crunlevels (renamed from config.d/controller/modules/files/crunlevels)0
-rw-r--r--config.d/controller/modules/files/system_configs/cssh.pub (renamed from config.d/controller/modules/files/cssh.pub)0
-rw-r--r--config.d/controller/modules/files/system_configs/csshd149
-rw-r--r--config.d/controller/modules/files/system_configs/csystem_links (renamed from config.d/controller/modules/files/cystem_links)0
-rw-r--r--config.d/controller/modules/files/system_configs/ctimezone (renamed from config.d/controller/modules/files/ctimezone)0
-rwxr-xr-xconfig.d/controller/modules/functions/cchroot.sh25
-rwxr-xr-x[-rw-r--r--]config.d/controller/modules/functions/cchroot_functions.sh63
-rw-r--r--config.d/controller/modules/functions/ccrevert_chroot.sh23
-rwxr-xr-xconfig.d/controller/modules/functions/cfunctions.sh667
-rwxr-xr-xconfig.d/controller/modules/functions/check_con.sh7
-rwxr-xr-xconfig.d/controller/modules/functions/cnetwork.sh38
-rwxr-xr-xconfig.d/controller/modules/functions/ct_config.sh43
-rwxr-xr-xconfig.d/controller/modules/functions/ct_devices.sh130
-rwxr-xr-xconfig.d/controller/modules/functions/ct_fetch.sh219
-rwxr-xr-xconfig.d/controller/modules/functions/ct_netf.sh149
-rwxr-xr-xconfig.d/controller/modules/functions/ct_newsys.sh40
-rwxr-xr-xconfig.d/controller/modules/functions/ct_prelim.sh421
-rwxr-xr-xconfig.d/controller/modules/functions/net_script.sh58
-rwxr-xr-xconfig.d/controller/modules/init_script.sh18
-rwxr-xr-xconfig.d/controller/modules/module-setup.sh343
45 files changed, 2553 insertions, 1180 deletions
diff --git a/config.d/controller/modules/cfunctions.sh b/config.d/controller/modules/cfunctions.sh
deleted file mode 100644
index 1aa8810..0000000
--- a/config.d/controller/modules/cfunctions.sh
+++ /dev/null
@@ -1,465 +0,0 @@
-#!/bin/bash
-
-die() {
- echo "$@" 1>&2 ; exit 1
-}
-
-_bsu_dfs() {
- # EXPORT BOOT DEVICE
- BOOTDEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $2 }')"
- export BOOTDEV
-
- # EXPORT SYSTEM DEVICE
- SYSDEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep SYS | awk -F ' ' '{ print $2 }')"
- export SYSDEV
-
- # EXPORT BACKUP DEVICE
- BACKUPDEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BACKUP | awk -F ' ' '{ print $2 }')"
- export BACKUPDEV
-
- # EXPORT USERDATA DEVICE
- USERDATADEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $2 }')"
- export USERDATADEV
-
- # EXPORT THE BOOT FILE SYSTEM TYPE
- BOOTFS="$(cat "${CTCONFDIR}/confdir/fstab.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $2 }')"
- export BOOTFS
-
- # EXPORT THE SYSTEM FILE SYSTEM TYPE
- SYSFS="$(cat "${CTCONFDIR}/confdir/fstab.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep SYS | awk -F ' ' '{ print $2 }')"
- export SYSFS
-
- # EXPORT THE BACKUP FILE SYSTEM TYPE
- BACKUPFS="$(cat "${CTCONFDIR}/confdir/fstab.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BACKUP | awk -F ' ' '{ print $2 }')"
- export BACKUPFS
-
- # EXPORT THE USERDATA FILE STSTEM TYPE
- USERDATAFS="$(cat "${CTCONFDIR}/confdir/fstab.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $2 }')"
- export USERDATAFS
-
- # EXPORT BOOT SIZE
- BOOTSFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $3 }')"
- export BOOTSFS
-
- # EXPORT SYSTEM SIZE
- SYSSFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep SYS | awk -F ' ' '{ print $3 }')"
- export SYSSFS
-
- # EXPORT BACKUP SIZE
- BACKUPSFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BACKUP | awk -F ' ' '{ print $3 }')"
- export BACKUPSFS
-
- # EXPORT USERDATA SIZE
- USERDATASFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $3 }')"
- export USERDATASFS
-
- if [[ "${_ctflag_confd}" == 0 ]]; then
- _sources_exp
- fi
-}
-
-_server_exp() {
- echo "Selecting server..."
- _ser_list=()
- while read -r "s";do
- _ser_list+=("${s}")
- done < "${CTCONFDIR}/sources/servers"
-
- if [[ "${#_ser_list[@]}" -ge 1 ]]; then
- _act_ser_ar=()
- for i in "${_ser_list[@]}"; do
- avms=$(ping -c 3 "$i" | tail -1| awk -F '/' '{print $5}')
- _act_ser+=("${avms}")
- done
- else
- avms=$(ping -c 3 "${_ser_list[0]}" | tail -1| awk -F '/' '{print $5}')
- _act_ser="${avms}"
- fi
-
- _max_entry="${_ser_list[0]}"
- for n in "${_ser_list[@]}" ; do
- if [[ "$n" != '' ]]; then
- ((${n%.*} > ${_max_entry%.*})) && _max_entry="$n"
- fi
- done
- _act_ser="${_max_entry}"
-}
-
-_sources_exp() {
- # SOURCE THE SOURCES CONFIGURATION FILES FOR EXPORTING THE SERVER INFORMATIONS
- source "${CTCONFDIR}/confdir/sources/sources.conf"
-
- if [[ -z "${_conf_dir}" ]]; then
- _conf_dir="$(grep "confdir" "${CTCONFDIR}/confdir/sources/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{ print $2 }')"
- export _conf_dir
- fi
-
- if [[ -z "${_dist_dir}" ]]; then
- _dist_dir="$(grep "distdir" "${CTCONFDIR}/confdir/sources/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{ print $2 }')"
- export _dist_dir
- fi
-
- if [[ -z "${_ser_user}" ]]; then
- _ser_user="$(grep "user" "${CTCONFDIR}/confdir/sources/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{ print $2 }')"
- export _ser_user
- fi
-}
-
-_call_net() {
- ifconfig "${_net_interface}" up
- udhcpc -t 5 -q -s "/bin/net_script.sh"
-}
-
-_mount_sysfs() {
- if [[ -n "$(grep "$1" "/proc/mounts" | awk -F ' ' '{ print $2 }')" ]]; then
- _unmount "$1"
- fi
-
- if mount -t "${SYSFS}" -o rw "${SYSDEV}" "$1"; then
- return 0
- else
- return 1
- fi
-}
-
-_call_backup_switch() {
- _ctflag_bootflag="BACKUP"
- export _ctflag_bootflag
-}
-
-_question() {
- for i in "$@"; do
- [[ "$i" ]] && echo "$i"
- done
-
- while true; do
- echo "Answer: Y/N "
- read -rp "Input :: <= " ANS
- case "${ANS}" in
- [yY])
- return 0
- break;;
- [nN]])
- return 1
- break;;
- esac
- done
-
- unset ANS
- unset _question_yes_action
- unset _question_no_action
-}
-
-_fetch_version() {
- if scp "${_act_user}@${_act_ser}/${_dist_dir}" "${CTCONFDIR}/version"; then
- _ctflag_sverison=0
- else
- _ctflag_sversion=1
- fi
- export _ctflag_sversion
-}
-
-_fetch_confd() {
- if rsync -aAXPhrv "${_act_user}@${_act_ser}/${_conf_dir}" "${CTCONFDIR}/confdir/"; then
- _ctflag_confd=0
- else
- _ctflag_confd=1
- fi
- export _ctflag_confd
-}
-
-_check_version() {
- _fetch_version
-
- if [[ "${_ctflag_sversion}" == 0 ]]; then
- _local_version="$(cat "/mnt/workdir/var/lib/version")"
- _server_version="$(cat "${CTCONFDIR}/version")"
- if [[ "${_local_version}" != "${_server_version}" ]]; then
- if [[ -n "${_ctflag_human}" ]]; then
- if _question "A new System Version is present on the server" "Do you wish to fetch the new system?"; then
- _ctflag_sysfetch=0
- else
- _ctflag_sysfetch=1
- fi
- else
- _ctflag_sysfetch=0
- fi
- else
- echo "Remote version matches the local"
- _ctflag_sysfetch=1
- fi
- export _ctflag_sysfetch
-}
-
-mv_pseudo() { # ${rsys}
- # Moving sys proc dev to rfs
- echo "Moving sys proc dev to rfs"
- for i in sys proc dev
- do
- echo "Moved ${i} to $2/${i}"
- mount --move "$1/${i}" "$2/${i}"
- done
-}
-
-mount_pseudo() {
- if [[ -n "$(grep "$1" "/proc/mounts" | awk -F ' ' '{ print $2 }')" ]]; then
- _unmount "$1"
- fi
-
- mount -t proc /proc "$1/proc" || return 1
- mount --rbind /dev "$1/dev" || return 1
- mount --rbind /sys "$1/sys" || return 1
- mount --make-rslave "$1/dev" || return 1
- mount --make-rslave "$1/sys" || return 1
-}
-
-umount_pseudo() {
- umount -l "$1/proc" >/dev/null 2>&1
- umount -l "$1/dev" >/dev/null 2>&1
- umount -l "$1/sys" >/dev/null 2>&1
- umount -l "$1"/* >/dev/null 2>&1
-}
-
-_unmount() {
- k=0
- if [[ -n "$(grep "$1" "/proc/mounts" | awk -F ' ' '{ print $2 }')" ]]; then
- while true; do
- while read -r i; do
- eval umount -l "$i"/* >/dev/null 2>&1
- eval umount -l "$i" >/dev/null 2>&1
- done < <(grep "$1" "/proc/mounts" | awk -F ' ' '{ print $2 }')
-
- if [[ -z $(grep "$1" "/proc/mounts" | awk -F ' ' '{ print $2 }') ]]; then
- break
- fi
-
- [[ "$k" -ge 20 ]] && return 1
- ((++k))
- done
- return 0
- fi
-}
-
-_chroot_config(){
- _revert_chroot() {
- if chroot "$1" "$2"; then
- return 0
- else
- return 1
- }
-
- _init_chroot() {
- if chroot "$1" "$2"; then
- echo "Configuration was successful"
- _sys_config=0
- else
- echo "Configuration failed"
- echo "Reverting changes"
- if _revert_chroot "$1" "var/tmp/ctworkdir/ccrevert_chroot.sh"; then
- echo "Changes reverted"
- else
- echo "Failed reverting changes"
- echo "Calling backup system"
- fi
- _sys_config=1
- fi
- export _sys_config
- }
-
- _prep_chroot() {
- if _mount_sysfs "$1" && mount_pseudo "$1"; then
- mkdir -p "$1/var/tmp/ctworkdir"
- cp -r "${CTCONFDIR}/confdir" "$1/var/tmp/ctworkdir/"
- cp "/usr/local/controller/cchroot.sh" "$1/var/tmp/ctworkdir/cchroot"
- _init_chroot "$@"
- else
- _sys_config=1
- export _sys_config
- fi
- }
-
- if _unmount "$1"; then
- _prep_chroot "$@"
- else
- _sys_config=1
- export _sys_config
- fi
-}
-
-_remake_sysfs() {
- if _unmount "$1"; then
- if [[ "${SYSFS}" == 'btrfs' ]]; then
- if eval "mkfs.${SYSFS}" -L ROOTFS -f "${SYSDEV}"; then
- echo "File system created"
- _ctflag_remake=0
- else
- echo "Failed creating new filesystem"
- _ctflag_remake=1
- fi
- else
- if eval "mkfs.${SYSFS}" -L ROOTFS "${SYSDEV}"; then
- echo "File system created"
- _ctflag_remake=0
- else
- echo "Failed creating new filesystem"
- _ctflag_remake=1
- fi
- fi
- else
- echo "Failed unmounting workdir"
- _ctflag_remake=1
- fi
- export _ctflag_remake
-}
-
-_fetch_new_sys() {
- if _mount_sysfs "$1"; then
- _sys_archive="stage3-amd64-${_server_version}.tar.bz2"
- export _sys_archive
-
- if sync -aAXhq "${_act_user}@${_act_ser}/${_dist_dir}/${_sys_archive}" "$1/"; then
- scp "${_act_user}@${_act_ser}/${_dist_dir}/${_sys_archive}.md5sum" "$1/"
- scp "${_act_user}@${_act_ser}/${_dist_dir}/${_sys_archive}.gpg" "$1/"
- echo "New system was fetched successfully"
- _ctflag_fetch=0
- else
- echo "Fetching new system FAILED"
- _ctflag_fetch=1
- fi
- else
- echo "Failed mounting ${SYSDEV} to $1"
- _ctflag_fetch=1
- fi
- export _ctflag_fetch
-}
-
-_verify_t() {
- _verify_md5sum() {
- (
- cd "$1"
-
- if md5sum -c "${_sys_archive}.md5sum"; then
- echo "PASS" > verify.info
- else
- echo "FAILED" > verify.info
- fi
- )
- }
-
- _verify_origin() {
- (
- cd "$1"
-
- if gpg --verify "${_sys_archive}.gpg"; then
- echo "PASS" > verify.info
- else
- echo "FAILED" > verify.info
- fi
- )
- }
-
- rm -f "$1/verify.info"
-
- _verify_origin "$1"
- if _check_s "$1"; then
- echo "Image's authentication verified"
- _verify_md5sum
- if _check_s "$1"; then
- echo "Image's integrity is healthy"
- _ctflag_verify=0
- else
- echo "Image's integrity check failed"
- _ctflag_verify=1
- fi
- else
- echo "Failed to verify the authentication of the image"
- _ctflag_verify=1
- fi
- export _ctflag_verify
-}
-
-_check_s() {
- if [[ "$(cat "$1/verify.info")" == 'PASS' ]]; then
- rm -f "$1/verify.info"
- return 0
- elif [[ "$(cat "$1/verify.info")" == 'FAILED' ]]; then
- rm -f "$1/verify.info"
- return 1
- fi
-}
-
-_extract_sys() {
- (
- cd "$1"
- if tar xvjpf "$2" --xattrs --numeric-owner; then
- echo "PASS" > verify.info
- else
- echo "FAILED" > verify.info
- fi
- )
-}
-
-_shell() {
- echo -e "\e[33mCalling bash subshell\e[0m"
- sleep 2
- echo 'echo -e "\e[33mInside Subshell\e[0m"' >> /root/.bashrc
- echo 'echo -e "\e[33mExit to return back to parent\e[0m"' >> /root/.bashrc
- (clear; exec /bin/bash;)
- sed -i "/Inside Subshell/d" "/root/.bashrc"
- sed -i "/Exit to return back to parent/d" "/root/.bashrc"
- echo -e "\e[33mYou are back to parent\e[0m"
-}
-
-# CALL SHELL
-_rescue_shell() {
- while true; do
- echo "$*"
- echo
- echo "Do you wish to call shell function and fix the issues manually?"
- echo "Answer Y/N "
- read -rp "Input :: <= " YN
- case "$YN" in
- [yY])
- chroot_master_loop "SHELL"
- break;;
- [nN])
- break;;
- esac
- done
-}
-
-# SUBSHELL LOOP FUNCTION, IT OFFERS
-subshell_loop() {
- while true; do
- _shell
- echo "If you fixed the issue, say CONTINUE proceed"
- echo "You can answer SHELL to open shell again"
- echo "Answer? CONTINUE/SHELL: "
- read -rp "Input :: <= " AANS
- case "${AANS}" in
- CONTINUE )
- LOOPVAR="EXITSHELL"
- break;;
- SHELL )
- LOOPVAR="SHELL"
- ;;
- * )
- ;;
- esac
- done
-}
-
-# CONTROLLER LOOP FUNCTION
-controller_master_loop() {
- [[ -z $(echo "$@") ]] && _print_info 3
- LOOPVAR="$1"
- while true; do
- case "${LOOPVAR}" in
- SHELL)
- subshell_loop;;
- EXITSHELL)
- break;;
-
- esac
- done
-}
diff --git a/config.d/controller/modules/cinit_clean.sh b/config.d/controller/modules/cinit_clean.sh
index e69de29..6f78a89 100755
--- a/config.d/controller/modules/cinit_clean.sh
+++ b/config.d/controller/modules/cinit_clean.sh
@@ -0,0 +1,36 @@
+# EXPORT CONTROLLER CONFDIR
+CTCONFDIR=/config.d
+export CTCONFDIR
+# EXPORT LOCAL SCRIPTDIR
+CTSCRIPTS=/usr/local/controller
+export CTSCRIPTS
+# UPDATE PATH
+export "PATH=${PATH}:/usr/local/controller"
+# CONTROLLER PRELIMINARY FUNCTIONS
+source "${CTSCRIPTS}/ct_prelim.sh"
+
+if [[ "${_ctflag_setup}" == 0 || "${_ctflag_extract}" == 0 || "${_sys_config}" == 0 ]]; then
+ if [[ -z "${_sys_archive}" ]]; then
+ if [[ -z "${_server_version}" ]]; then
+ _server_version="$(cat "${CTCONFDIR}/version")"
+ fi
+
+ _sys_archive="stage3-amd64-${_server_version}.tar.bz2"
+ fi
+
+ mount -L "SYSFS" "/mnt/workdir"
+
+ if [[ "${_ctflag_extract}" == 0 ]]; then
+ rm -f "/mnt/workdir/${_sys_archive}"
+ rm -f "/mnt/workdir/${_sys_archive}.md5sum"
+ rm -f "/mnt/workdir/${_sys_archive}.sig"
+ fi
+
+ if [[ "${_sys_config}" == 0 ]]; then
+ rm -rf "/mnt/workdir/var/tmp/ctworkdir"
+ fi
+
+ umount "/mnt/workdir"
+fi
+
+
diff --git a/config.d/controller/modules/cinit_mount_dev.sh b/config.d/controller/modules/cinit_mount_dev.sh
new file mode 100755
index 0000000..4136f11
--- /dev/null
+++ b/config.d/controller/modules/cinit_mount_dev.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+# EXPORT CONTROLLER CONFDIR
+CTCONFDIR=/config.d
+export CTCONFDIR
+# EXPORT LOCAL SCRIPTDIR
+CTSCRIPTS=/usr/local/controller
+export CTSCRIPTS
+# UPDATE PATH
+export "PATH=${PATH}:/usr/local/controller"
+# CONTROLLER PRELIMINARY FUNCTIONS
+source "${CTSCRIPTS}/ct_prelim.sh"
+# MAKE SURE RFS BFS WORKDIR ARE NOT MOUNTED
+_unmount_all_targets
+
+if grep -q "ctetc=1" "/proc/cmdline"; then
+ _extract_target() {
+ (
+ cd "$1"
+ rm -f "/tmp/verify.info"
+ if tar xvjpf "$2" --xattrs --numeric-owner >/dev/null; then
+ echo "PASS" > "/tmp/verify.info"
+ rm -f "$2"
+ else
+ echo "FAIL" > "/tmp/verify.info"
+ fi
+ )
+ }
+
+ _unmount "/sysroot/etc"
+
+ if grep -q "bootetc=1" "/proc/cmdline"; then
+ mkdir -p "/bootetc"
+ mount -t tmpfs tmpfs "/sysroot/etc"
+
+ mount -L "BOOTFS" "/bootetc"
+ cp "/bootetc/etc.tar.bz2" "/sysroot/etc/etc.tar.bz2"
+ _extract_target "/sysroot/etc" "etc.tar.bz2"
+ if grep -q "PASS" "/tmp/verify.info"; then
+ echo "etc configured successfully"
+ else
+ echo "etc failed to configure"
+ umount -l "/sysroot/etc"
+ fi
+
+ umount -l "/bootetc"
+ else
+ cp -r "/sysroot/etc" "/tmpfs_etc"
+ mount -t tmpfs tmpfs "/sysroot/etc"
+ rsync -aAPhrq "/tmpfs_etc" "/sysroot/etc/"
+ fi
+fi
+
+if grep -q "ctvar=1" "/proc/cmdline" && grep -q "bootvar=1" "/proc/cmdline"; then
+ _unmount "/sysroot/var"
+
+ mount -t tmpfs tmpfs "/sysroot/var"
+ mkdir -p "/bootvar"
+ mount -L "BOOTFS" "/bootvar"
+ cp "/bootetc/var.tar.bz2" "/sysroot/var/var.tar.bz2"
+ _extract_target "/sysroot/etc" "etc.tar.bz2"
+ if grep -q "PASS" "/tmp/verify.info"; then
+ echo "var configured successfully"
+ else
+ echo "var failed to configure"
+ umount -l "/sysroot/var"
+ fi
+
+ umount -l "/bootvar"
+elif grep -q "ctvar_tmp=1" "/proc/cmdline"; then
+ _unmount "/sysroot/var"
+
+ mount -t tmpfs tmpfs "/sysroot/var/tmp"
+fi
+
+if grep -q "cttmp=1" "/proc/cmdline"; then
+ _unmount "/sysroot/tmp"
+
+ mount -t tmpfs tmpfs "/sysroot/tmp"
+fi
+
+
diff --git a/config.d/controller/modules/cinit_pre-mount.sh b/config.d/controller/modules/cinit_pre-mount.sh
index a076333..d60bea6 100755
--- a/config.d/controller/modules/cinit_pre-mount.sh
+++ b/config.d/controller/modules/cinit_pre-mount.sh
@@ -1,66 +1,263 @@
#!/bin/bash
+# This is the first controller's script.
+# The script is sourced at pre-mount hook points, after udev has finished with a priority of 08.
+
# EXPORT CONTROLLER CONFDIR
CTCONFDIR=/config.d
export CTCONFDIR
-
# EXPORT LOCAL SCRIPTDIR
CTSCRIPTS=/usr/local/controller
export CTSCRIPTS
-
# UPDATE PATH
export "PATH=${PATH}:/usr/local/controller"
+# CONTROLLER PRELIMINARY FUNCTIONS
+source "${CTSCRIPTS}/ct_prelim.sh"
+# MAKE SURE RFS BFS WORKDIR ARE NOT MOUNTED
+_unmount_all_targets
+# MAKE SURE CT FLAGS ARE NOT SET
+_unset_ct
+# CHECK AND EXPORT LABELS
+_a_priori_devices
+# EXPORT DEVICES AND FILESYSTEMS
+_bsu_dfs
+# CHECK IF ROOTFS AND BACKUPFS HAVE ROOT SYSTEMS INSIDE
+_check_rbfs
+
+# CASE OF MISSING SYSFS DEVICE OR BOOTFS DEVICE
+# THIS SHOULD NEVER HAPPEN, BUT IT'S POSSIBLE SOMETIMES.
+# AN EXAMPLE WOULD BE A FAILURE OF MKFS.${FS} DURING THE PROCESS
+if [[ ! -e "${SYSDEV}" ]] || [[ ! -e "${BACKUPDEV}" ]]; then
+ _recheck_dev() {
+ _a_priori_devices
+ _bsu_dfs
-# CONTROLLER FUNCTIONS
-source "${CTSCRIPTS}/cfunctions.sh"
+ if [[ -e "${SYSDEV}" && -e "${BACKUPDEV}" ]]; then
+ return 0
+ else
+ return 1
+ fi
+ }
+
+ while true; do
+ _rescue_shell "Important labels are missing." "Please create the partitions you wish with SYSFS and BACKUPFS labels"
+
+ if _recheck_dev; then
+ break
+ fi
+ done
+fi
+
+# IMPORT GPG PUB KEY
+# THIS FEATURE IS DISABLED FOR NOW
+# _gpg_import
# NETWORK SCRIPT
source "${CTSCRIPTS}/cnetwork.sh"
+# FETCH FUNCTIONS
+source "${CTSCRIPTS}/ct_fetch.sh"
+# NEW SYSTEM FUNCTIONS
+source "${CTSCRIPTS}/ct_newsys.sh"
+
+# CHECK NETWORK FLAG AND FETCH VERSION AND CONFIG.D DIRECTORY
+if [[ "${_ctflag_net}" == 0 ]]; then
+ # EXPORT SERVER'S INFO
+ _sources_exp
+ # FETCH CONFIG.D
+ _fetch_confd
+ # FETCH LATEST VERSION
+ _fetch_version
+fi
+
+if [[ "${_ctflag_setup}" == 0 ]]; then
+ _ctflag_sysfetch=0
+ _ctflag_bconf=0
+elif [[ "${_ctflag_setup}" == 1 ]]; then
+ _call_backup_switch
+ _ctflag_bconf=1
+else
+ if [[ "${_ctflag_setup}" == 2 ]]; then
+ _ctflag_bconf=0
+ else
+ _ctflag_bconf=1
+ fi
+
+ # MOUNT SYSFS AS RW
+ _mount_sysfs "/mnt/workdir"
+ # CHECK LOCAL VERSION OF SYSFS WITH SERVERS VERSION
+ _check_version
+ _unmount "/mnt/workdir"
+fi
# WIPE OLD FS, CREATE NEW FS & FETCH NEW SYSTEM
-if [[ "${_ctflag_sysfetch}" == 0 && "${_ctflag_net}" == 0 ]]; then
+# _CTFLAG_SYSFETCH IS DEFINED @ _CHECK_VERSION
+# _CTFLAG_NET IS DEFINED @ CNETWORK.SH
+if [[ "${_ctflag_setup}" == 0 && "${_ctflag_net}" == 1 ]]; then
+ _rescue_shell "No active system could be located, neither a network connection could be established from a system fetch"
+elif [[ "${_ctflag_sysfetch}" == 0 && "${_ctflag_net}" == 0 ]]; then
+ _case_fail() {
+ if [[ "${_ctflag_bconf}" == 0 ]]; then
+ _rescue_shell "Process failed" "Backup system is missing"
+ else
+ _call_backup_switch
+ fi
+ }
+
# WIPE & CREATE NEW FS
- _remake_sysfs "/mnt/workdir"
-
+ _remake_dev "/mnt/workdir" "${SYSDEV}"
# FETCH NEW SYSTEM
+ # _CTFLAG_REMAKE IS DEFINED @ _RMAKE_DEV
if [[ "${_ctflag_remake}" == 0 ]]; then
_fetch_new_sys "/mnt/workdir"
elif [[ "${_ctflag_remake}" == 1 ]]; then
- _call_backup_switch
+ _case_fail
fi
# VERIFY FETCHED IMAGE
+ # _CTFLAG_FETCH IS DEFINE @ _FETCH_NEW_SYS
if [[ "${_ctflag_fetch}" == 0 ]]; then
- _verify_t "/mnt/workdir"
+ if ! _verify_target "/mnt/workdir"; then
+ _call_backup_switch
+ fi
elif [[ "${_ctflag_fetch}" == 1 ]]; then
- _call_backup_switch
+ _case_fail
fi
# EXTRACT NEW SYSTEM
if [[ "${_ctflag_verify}" == 0 ]]; then
- _extract_sys "/mnt/workdir"
+ # CASE OF A LEFTOVER CHECK
rm -f "/mnt/workdir/verify.info"
- if _check_s "/mnt/workdir"; then
+ # EXTRACT SYSTEM TARBALL
+ # _SYS_ARCHIVE IS DEFINED @ _FETCH_NEW_FS
+ _extract_sys "/mnt/workdir" "${_sys_archive}"
+ if _check_last "/mnt/workdir"; then
_ctflag_extract=0
else
_ctflag_extract=1
fi
+
+ # CREATE /VAR/LIB/GSE DIR
+ if [[ ! -e "/mnt/workdir/var/lib/gse" ]]; then
+ mkdir -p "/mnt/workdir/var/lib/gse"
+ fi
+
+ # COPY FETCHED VERSION UNDER /VAR/LIB/GSE
+ cp "${CTCONFDIR}/version" "/mnt/workdir/var/lib/gse/version"
+
+ rm -f "/mnt/workdir/verify.info"
export _ctflag_extract
elif [[ "${_ctflag_verify}" == 1 ]]; then
- _call_backup_switch
+ _case_fail
fi
+
+ _unmount "/mnt/workdir"
+elif [[ "${_ctflag_sysfetch}" == 9 ]]; then
+ _call_backup_switch
+fi
+
+if [[ "${_ctflag_switch}" == 0 ]]; then
+ echo "switch $_ctflag_switch"
+ #return 1
fi
+# BACKUP SWITCH CONDITION
+# _CTFLAG_SWITCH IS DEFINED FROM ALL _CALL_BACKUP_SWITCH
+_switch_rfs_bfs() {
+ _unmount_all_targets
+ echo -e "[\e[35m*\e[0m] Initiating switch"
+ if [[ "${_ctflag_switch}" == 0 ]]; then
+ SYSFS_EXPIRED="${SYSFS}"
+ SYSDEV_EXPIRED="${SYSDEV}"
+ export SYSFS_EXPIRED
+ export SYSDEV_EXPIRED
+
+ if [[ "${SYSFS}" == 'ext4' ]]; then
+ e2label "${SYSDEV}" "EXPIRED"
+ e2label "${BACKUPDEV}" SYSFS
+ elif [[ "${SYSFS}" == 'btrfs' ]]; then
+ btrfs filesystem label "${SYSDEV}" "EXPIRED"
+ btrfs filesystem label "${BACKUPDEV}" "SYSFS"
+ fi
+
+ SYSFS="${BACKUPFS}"
+ SYSDEV="${BACKUPDEV}"
+ export SYSFS
+ export SYSDEV
+
+ _unmount "/mnt/workdir"
+ fi
+}
+
+# SWITCH BACKUPFS TO SYSFS IF SWITCH FLAG IS ON
+_switch_rfs_bfs
+
# CONFIGURATION
+# _CTFLAG_CONFD IS DEFINED @ _FETCH_CONFD
+# _CTFLAG_EXTRACT IS DEFINED @ _EXTRACT_SYS
if [[ "${_ctflag_net}" == 0 ]] && [[ "${_ctflag_confd}" == 0 || "${_ctflag_extract}" == 0 ]]; then
- # MOUNT SYSTEM
- if _mount_sysfs "/mnt/workdir"; then
- # CHROOT SYSTEM AND INITIATE THE CCHROOT.SH
- _chroot_config "$/mnt/workdir" "var/tmp/ctworkdir/cchroot"
- if [[ "{_ctflag_extract}" == 0 && "${_sys_config}" == 1 ]]; then
+ source "/usr/local/controller/ct_config.sh"
+
+ echo -e "[\e[34m*\e[0m] Preparing for configuration"
+ # CHROOT SYSTEM AND INITIATE THE CCHROOT.SH
+ if _chroot_config "/mnt/workdir" "var/tmp/ctworkdir"; then
+ unset _ctflag_switch
+ _unmount_all_targets
+
+ if [[ "${_sys_config}" == 1 ]]; then
_call_backup_switch
+ _switch_rfs_bfs
+ fi
+ fi
+ _unmount_all_targets
+fi
+
+echo -e "[\e[34m*\e[0m] Checking if BACKUPFS requires setup"
+# Sync backup
+if [[ "${_ctflag_bconf}" == 0 || "${_ctflag_setup}" == 2 ]]; then
+ echo -e "[\e[33m*\e[0m] Setup is required."
+ echo -e "[\e[34m*\e[0m] Syncing..."
+ _sync_targets
+elif [[ "${_ctflag_switch}" == 0 && "${_ctflag_bconf}" != 0 ]]; then
+ echo -e "[\e[34m*\e[0m] Calling wipefs ${SYSDEV_EXPIRED}"
+ wipefs "${SYSDEV_EXPIRED}"
+ unset _ctflag_remake
+
+ echo -e "[\e[34m*\e[0m] Partitioning ${SYSDEV_EXPIRED} with ${SYSFS_EXPIRED} filesystem"
+ if [[ "${SYSFS_EXPIRED}" == 'btrfs' ]]; then
+ if mkfs."${SYSFS_EXPIRED}" "${SYSDEV_EXPIRED}" -f -L "BACKUPFS"; then
+ _ctflag_remake=0
+ else
+ _ctflag_remake=1
fi
else
- echo "Could not mout sysfs @ /mnt/workdir"
+ if mkfs."${SYSFS_EXPIRED}" "${SYSDEV_EXPIRED}" -F -L "BACKUPFS"; then
+ _ctflag_remake=0
+ else
+ _ctflag_remake=1
+ fi
fi
-fi \ No newline at end of file
+
+ BACKUPFS="${SYSFS_EXPIRED}"
+ BACKUPDEV="${SYSDEV_EXPIRED}"
+ export BACKUPFS
+ export BACKUPDEV
+
+ if [[ "${_ctflag_remake}" == 0 ]]; then
+ echo -e "[\e[32m*\e[0m] Partitioned successfully"
+ echo -e "[\e[34m*\e[0m] Syncing SYSFS to BACKUPFS"
+ if _sync_targets; then
+ echo -e "[\e[32m*\e[0m] Synced"
+ _ctflag_bconf=1
+ else
+ echo -e "[\e[31m*\e[0m] Failure"
+ _ctflag_bconf=9
+ fi
+ else
+ echo -e "[\e[31m*\e[0m] Partitioning ${SYSDEV_EXPIRED} failed"
+ _ctflag_bconf=9
+ fi
+else
+ echo -e "[\e[32m*\e[0m] No setup is required"
+fi
+
+
diff --git a/config.d/controller/modules/dr_config b/config.d/controller/modules/dr_config
new file mode 100644
index 0000000..0281186
--- /dev/null
+++ b/config.d/controller/modules/dr_config
@@ -0,0 +1,29 @@
+# Equivalent to cmdline option --drivers="modules..."
+#drivers+="module module module"
+
+# Equivalent to cmdline option --add-drivers
+#add_drivers+="module"
+
+# Equivalent to cmdline option --omit-drivers="modules"
+#omit_drivers+="module"
+
+# Equivalent to cmdline option --filesystems="filesystems"
+#filesystems+="filesystems"
+
+# Equivalent to cmdline option --kmoddir="/lib/modules/gentoo-ver"
+#drivers_dir="/lib/modules/gentoo-ver"
+
+# Equivalent to cmdline option --fwdir=":/lib/fw/alt:/lib/fw/alt2"
+#fw_dir+=":/lib/fw/alt:/lib/fw/alt2"
+
+# Equivalent to -H
+#hostonly="yes"
+
+# Equivalent to cmdline option -m "module module module"
+#dracutmodules+="dash kernel-modules rootfs-block udev-rules usrmount base fs-lib shutdown"
+
+# Equivalent to cmdline option -a "module"
+#add_dracutmodules+="module"
+
+# Equivalent to cmdline option -o "module"
+#omit_dracutmodules+="module"
diff --git a/config.d/controller/modules/dracut_modules b/config.d/controller/modules/dracut_modules
new file mode 100644
index 0000000..dc01240
--- /dev/null
+++ b/config.d/controller/modules/dracut_modules
@@ -0,0 +1,63 @@
+bash
+bootchart
+dash
+caps
+modsign
+rescue
+watchdog
+busybox
+i18n
+convertfs
+network
+ifcfg
+url-lib
+drm
+gensplash
+plymouth
+cms
+btrfs
+crypt
+dm
+dmraid
+dmsquash-live
+kernel-modules
+kernel-network-modules
+livenet
+lvm
+mdraid
+multipath
+qemu
+qemu-net
+crypt-gpg
+crypt-loop
+cifs
+dasd
+dasd_mod
+dasd_rules
+fcoe-uefi
+fstab-sys
+iscsi
+nbd
+nfs
+resume
+rootfs-block
+ssh-client
+terminfo
+udev-rules
+virtfs
+zfcp
+zfcp_rules
+znet
+securityfs
+biosdevname
+masterkey
+ecryptfs
+integrity
+pollcdrom
+syslog
+usrmount
+base
+fs-lib
+img-lib
+shutdown
+uefi-lib
diff --git a/config.d/controller/modules/files/ccoptions b/config.d/controller/modules/files/ccoptions
deleted file mode 100644
index 2ceb9fb..0000000
--- a/config.d/controller/modules/files/ccoptions
+++ /dev/null
@@ -1,345 +0,0 @@
-#!/bin/bash
-
-# Distcc, distcc_pump, ccache & some features
-
-CHFEATURES=''
-# CHROOT CONFIGURATION STAGE
-# COMMENT OUT TO REMOVE
-
-# Enable portage support for the distcc package.
-#
-CHFEATURES="${CHFEATURES} distcc"
-
-# Enable portage support for the distcc package with pump mode.
-#
-CHFEATURES="${CHFEATURES} distcc-pump"
-
-# Use Linux control group to control processes spawned by ebuilds.
-# This allows emerge to safely kill all subprocesses when ebuild phase exits.
-#
-# CHFEATURES="${CHFEATURES} cgroups"
-
-# Enable automatic execution of the command specified by the PORT_LOGDIR_CLEAN variable.
-# The default PORT_LOGDIR_CLEAN setting will remove all files from PORT_LOGDIR that were last modified at least 7 days ago.
-#
-# CHFEATURES="${CHFEATURES} clean-logs"
-
-# The causes all build logs to be compressed while they are being written.
-# Log file names have an extension that is appropriate for the compression type.
-# Currently, only gzip(1) compression is supported, so build logs will have a '.gz' extension when this feature is enabled.
-#
-# CHFEATURES="${CHFEATURES} clean-logs"
-
-# This causes the CONFIG_PROTECT behavior to be skipped for files that have not been modified since they were installed.
-# This feature is enabled by default.
-#
-# CHFEATURES="${CHFEATURES} config-protect-if-modified"
-
-# Do not delete the ${T} directory after the merge process.
-#
-# CHFEATURES="${CHFEATURES} keeptemp"
-
-# Do not delete the ${WORKDIR} directory after the merge process.
-# ${WORKDIR} can then be reused since this feature disables most of the clean phase that runs prior to each build.
-# Due to lack of proper cleanup, this feature can interfere with normal emerge operation
-# and therefore it should not be left enabled for more than a short period of time.
-#
-# CHFEATURES="${CHFEATURES} keepwork"
-
-# After a package is merged or unmerged, sync relevant files to disk in order to avoid data-loss in the event of a power failure.
-# This feature is enabled by default.
-#
-# CHFEATURES="${CHFEATURES} merge-sync"
-
-# Automatically perform a metadata transfer when `emerge --sync` is run. In versions of portage >=2.1.5, this feature is disabled by default.
-# When metadata-transfer is disabled, metadata cache from the ${repository_location}/metadata/md5-cache/ directory will be used directly (if available).
-#
-# CHFEATURES="${CHFEATURES} metadata-transfer"
-
-# Preserve extended attributes (filesystem-stored metadata) when installing files (see attr(1)).
-# The PORTAGE_XATTR_EXCLUDE variable may be used to exclude specific attributes from being preserved.
-#
-# CHFEATURES="${CHFEATURES} xattr"
-
-# Enable GPG verification when using emerge-webrsync.
-#
-# CHFEATURES="${CHFEATURES} webrsync-gpg"
-
-# Drop privileges to the owner of ${repository_location} for emerge(1) --sync operations.
-# Note that this feature assumes that all subdirectories of ${repository_location} have the same ownership as ${repository_location} itself.
-# It is the user's responsibility to ensure correct ownership, since otherwise Portage would have to waste time validating ownership for each and every sync operation.
-#
-# CHFEATURES="${CHFEATURES} usersync"
-
-# Enable the sandbox in the compile phase, when running without root privs (userpriv).
-#
-# CHFEATURES="${CHFEATURES} usersandbox"
-
-# Allow portage to drop root privileges and compile packages as portage:portage without a sandbox (unless usersandbox is also used).
-#
-# CHFEATURES="${CHFEATURES} userpriv"
-
-# When portage is run as root, drop privileges to portage:portage during the fetching of package sources.
-#
-# CHFEATURES="${CHFEATURES} userfetch"
-
-# If a file is not claimed by another package in the same slot and it is not protected by CONFIG_PROTECT,
-# unmerge it even if the modification time or checksum differs from the file that was originally installed.
-#
-# CHFEATURES="${CHFEATURES} unmerge-orphans"
-
-# Keep logs from successful unmerge phases. This is relevant only when PORT_LOGDIR is set.
-#
-# CHFEATURES="${CHFEATURES} unmerge-logs"
-
-# Call quickpkg(1) to create a backup of each package before it is unmerged (if a binary package of the same version does not already exist).
-# Also see the related downgrade-backup feature.
-#
-# CHFEATURES="${CHFEATURES} unmerge-backup"
-
-# Warn if FEATURES contains one or more unknown values.
-#
-# CHFEATURES="${CHFEATURES} unknown-features-warn"
-
-# Filter out any unknown values that the FEATURES variable contains.
-#
-# CHFEATURES="${CHFEATURES} unknown-features-filter"
-
-# If "test" is enabled FEATURES and the test phase of an ebuild fails, continue to execute the remaining phases as if the failure had not occurred.
-# Note that the test phase for a specific package may be disabled by masking the "test" USE flag in package.use.mask (see portage(5)).
-#
-# CHFEATURES="${CHFEATURES} test-fail-continue"
-
-# Run package-specific tests during each merge to help make sure the package compiled properly.
-# See test in ebuild(1) and src_test() in ebuild(5).
-# This feature implies the "test" USE flag if it is a member of IUSE, either explicitly or implicitly (see ebuild(5) for more information about IUSE).
-# The "test" USE flag is also automatically disabled when the "test" feature is disabled.
-#
-# CHFEATURES="${CHFEATURES} test"
-
-# Before merging packages to the live filesystem, automatically strip setuid bits from any file that is not listed in /etc/portage/suidctl.conf.
-#
-# CHFEATURES="${CHFEATURES} suidctl"
-
-# Have portage react strongly to conditions that have the potential to be dangerous (like missing or incorrect digests for ebuilds).
-#
-# CHFEATURES="${CHFEATURES} strict"
-
-# Have portage react strongly to conditions that may conflict with system security provisions (for example textrels, executable stack).
-# Read about the QA_STRICT_* variables in make.conf(5).
-#
-# CHFEATURES="${CHFEATURES} stricter"
-
-# Prior to stripping ELF etdyn and etexec files, the debugging info is stored for later use by various debuggers.
-# This feature is disabled by nostrip. You should also consider setting compressdebug so the files don't suck up a lot of space.
-# For installation of source code, see installsources.
-#
-# CHFEATURES="${CHFEATURES} splitdebug"
-
-# Store build logs in category subdirectories of PORT_LOGDIR/build, instead of using PORT_LOGDIR directly.
-#
-# CHFEATURES="${CHFEATURES} split-log"
-
-# Store logs created by PORTAGE_ELOG_SYSTEM="save" in category subdirectories of PORT_LOGDIR/elog, instead of using PORT_LOGDIR/elog directly.
-#
-# CHFEATURES="${CHFEATURES} split-elog"
-
-# Skip write access checks on DISTDIR when fetching files.
-# This is useful when FETCHCOMMAND and RESUMECOMMAND are used to forward fetch requests to a server that exposes DISTDIR as a read-only NFS share.
-# A read-only DISTDIR is not compatible with the distlocks, so it is recommended to also add "-distlocks" to FEATURES in order to avoid warning messages
-# that are triggered by this incompatibility.
-#
-# CHFEATURES="${CHFEATURES} skiprocheck"
-
-# When commiting work to cvs with repoman(1), sign the Manifest with a GPG key. Read about the PORTAGE_GPG_KEY variable in make.conf(5).
-#
-# CHFEATURES="${CHFEATURES} sign"
-
-# Stands for Smart Filesystem Permissions. Before merging packages to the live filesystem, automatically search for and set permissions on setuid and setgid files.
-# Files that are setuid have the group and other read bits removed while files that are setgid have the other read bit removed. See also suidctl below.
-#
-# CHFEATURES="${CHFEATURES} sfperms"
-
-# Enable SELinux sandbox-ing. Do not toggle this FEATURE yourself.
-#
-# CHFEATURES="${CHFEATURES} sesandbox"
-
-# Enable sandbox-ing when running emerge(1) and ebuild(1).
-#
-# CHFEATURES="${CHFEATURES} sandbox"
-
-# Output a verbose trace of python execution to stderr when a command's --debug option is enabled.
-#
-# CHFEATURES="${CHFEATURES} python-trace"
-
-# This is identical to the collision-protect feature except that files may be overwritten if they are not explicitly listed in the contents of a currently installed package.
-# This is particularly useful on systems that have lots of orphan files that have been left behind by older versions of portage that did not support the unmerge-orphans feature.
-# Like collision-protect, the COLLISION_IGNORE variable can be used to selectively disable this feature.
-# It is recommended to leave either protect-owned or collision-protect enabled at all times, since otherwise file collisions between packages may result in files being overwritten or uninstalled at inappropriate times.
-# If collision-protect is enabled then it takes precedence over protect-owned.
-#
-# CHFEATURES="${CHFEATURES} protect-owned"
-
-# Preserve libraries when the sonames change during upgrade or downgrade. Libraries are preserved only if consumers of those libraries are detected.
-# Preserved libraries are automatically removed when there are no remaining consumers. Run `emerge @preserved-rebuild` in order to rebuild all consumers of preserved libraries.
-#
-# CHFEATURES="${CHFEATURES} preserve-libs"
-
-# If prelink(8) is installed then use it to undo any prelinks on files before computing checksums for merge and unmerge.
-# This feature is useful only if prelink(8) is installed and accurate checksums (despite prelinking) are needed for some reason such as for checking the integrity of installed files or because the unmerge-orphans feature is disabled.
-#
-# Note that normal emerging of packages from source computes the checksums before things will be prelinked, so in such cases, this feature isn't required either.
-# Undoing prelinking while merging is only required when using tools like quickpkg(1) which can cause already prelinked files to be merged.
-#
-# CHFEATURES="${CHFEATURES} prelink-checksums"
-
-# Use finer-grained locks when installing packages, allowing for greater parallelization. For additional parallelization, disable ebuild-locks.
-#
-# CHFEATURES="${CHFEATURES} parallel-install"
-
-# Fetch in the background while compiling. Run `tail -f /var/log/emerge-fetch.log` in a terminal to view parallel-fetch progress.
-#
-# CHFEATURES="${CHFEATURES} parallel-fetch"
-
-# Disables xterm titlebar updates (which contains status info).
-#
-# CHFEATURES="${CHFEATURES} notitles"
-
-# Prevents the stripping of binaries that are merged to the live filesystem.
-#
-# CHFEATURES="${CHFEATURES} nostrip"
-
-# Do not install manpages.
-#
-# CHFEATURES="${CHFEATURES} noman"
-
-# Do not install info pages.
-#
-# CHFEATURES="${CHFEATURES} noinfo"
-
-# Do not install doc files (/usr/share/doc).
-#
-# CHFEATURES="${CHFEATURES} nodoc"
-
-# Do not delete the the source and temporary files after the merge process.
-#
-# CHFEATURES="${CHFEATURES} noclean"
-
-# When utilizing ebuild(1), only run the function requested.
-# Also, forces the corresponding ebuild and eclasses to be sourced again for each phase, in order to account for modifications.
-#
-# CHFEATURES="${CHFEATURES} noauto"
-
-# Enable GLEP 42 news support. See https://wiki.gentoo.org/wiki/GLEP:42.
-#
-CHFEATURES="${CHFEATURES} -news"
-
-# Enable escaping network-sandbox through SOCKSv5 proxy. Enabling distcc feature also enables the proxy.
-#
-# CHFEATURES="${CHFEATURES} network-sandbox-proxy"
-
-# Isolate the ebuild phase functions from host network interfaces. Supported only on Linux. Requires network namespace support in kernel.
-#
-# CHFEATURES="${CHFEATURES} network-sandbox"
-
-# Many Makefiles assume that their libraries should go to /usr/lib, or $(prefix)/lib.
-# This assumption can cause a serious mess if /usr/lib isn't a symlink to /usr/lib64. To find the bad packages, we have a portage feature called multilib-strict.
-# It will prevent emerge from putting 64bit libraries into anything other than (/usr)/lib64.
-#
-# CHFEATURES="${CHFEATURES} multilib-strict"
-
-# Fetch everything in SRC_URI regardless of USE settings, except do not fetch anything when mirror is in RESTRICT.
-#
-# CHFEATURES="${CHFEATURES} mirror"
-
-# Automatically perform a metadata transfer when `emerge --sync` is run. In versions of portage >=2.1.5, this feature is disabled by default.
-# When metadata-transfer is disabled, metadata cache from the ${repository_location}/metadata/md5-cache/ directory will be used directly (if available).
-#
-# CHFEATURES="${CHFEATURES} metadata-transfer"
-
-# When mirror is enabled in FEATURES, fetch files even when mirror is also in the ebuild(5) RESTRICT variable.
-# Do NOT use lmirror for clients that need to override RESTRICT when fetching from a local mirror, but instead use a "local" mirror setting in /etc/portage/mirrors,
-# as described in portage(5).
-#
-# CHFEATURES="${CHFEATURES} lmirror"
-
-# Isolate the ebuild phase functions from host IPC namespace. Supported only on Linux. Requires IPC namespace support in kerne
-#
-# CHFEATURES="${CHFEATURES} ipc-sandbox"
-
-# Install source code into /usr/src/debug/${CATEGORY}/${PF} (also see splitdebug).
-# This feature works only if debugedit is installed and CFLAGS is set to include debug information (such as with the -ggdb flag).
-#
-# CHFEATURES="${CHFEATURES} installsources"
-
-# Enable portage support for the icecream package.
-#
-# CHFEATURES="${CHFEATURES} icecream"
-
-# Force emerges to always try to fetch files from the PORTAGE_BINHOST. See make.conf(5) for more information.
-#
-# CHFEATURES="${CHFEATURES} getbinpkg"
-
-# Enable prefix support for all ebuilds, regardless of EAPI, since older EAPIs would otherwise be useless with prefix configurations.
-# This brings compatibility with the prefix branch of portage, which also supports EPREFIX for all EAPIs (for obvious reasons).
-#
-# CHFEATURES="${CHFEATURES} force-prefix"
-
-# Only fetch files from configured mirrors, ignoring SRC_URI, except when mirror is in the ebuild(5) RESTRICT variable.
-#
-# CHFEATURES="${CHFEATURES} force-mirror"
-
-# Modifies .la files to not include other .la files and some other fixes (order of flags, duplicated entries, ...)
-#
-# CHFEATURES="${CHFEATURES} fixlafiles"
-
-# Enable fakeroot for the install and package phases when a non-root user runs the ebuild(1) command.
-#
-# CHFEATURES="${CHFEATURES} fakeroot"
-
-# Clean up temporary files after a build failure. This is particularly useful if you have PORTAGE_TMPDIR on tmpfs.
-# If this feature is enabled, you probably also want to enable PORT_LOGDIR in order to save the build log.
-# Both the ebuild(1) command and the noclean feature cause the fail-clean feature to be automatically disabled.
-#
-# CHFEATURES="${CHFEATURES} fail-clean"
-
-# Use locks to ensure that unsandboxed ebuild phases never execute concurrently. Also see parallel-install.
-#
-# CHFEATURES="${CHFEATURES} ebuild-locks"
-
-# When a package is downgraded to a lower version, call quickpkg(1) in order to create a backup of the installed
-# version before it is unmerged (if a binary package of the same version does not already exist).
-# Also see the related unmerge-backup feature.
-#
-# CHFEATURES="${CHFEATURES} downgrade-backup"
-
-# Portage uses lockfiles to ensure competing instances don't clobber each other's files.
-# This feature is enabled by default but may cause heartache on less intelligent remote filesystems like NFSv2
-# and some strangely configured Samba server (oplocks off, NFS re-export).
-# A tool /usr/lib/portage/bin/clean_locks exists to help handle lock issues when a problem arises (normally due to a crash or disconnect).
-#
-# CHFEATURES="${CHFEATURES} distlocks"
-
-# Enable portage support for the ccache package. If the ccache dir is not present in the user's environment, then portage will default to ${PORTAGE_TMPDIR}/ccache.
-#
-CHFEATURES="${CHFEATURES} ccache"
-
-# Build binary packages for just packages in the system set.
-#
-# CHFEATURES="${CHFEATURES} buildsyspkg"
-
-# Binary packages will be created for all packages that are merged. Also see quickpkg(1) and emerge(1) --buildpkg and --buildpkgonly options.
-#
-# CHFEATURES="${CHFEATURES} buildpkg"
-
-# Keep logs from successful binary package merges. This is relevant only when PORT_LOGDIR is set.
-#
-# CHFEATURES="${CHFEATURES} binpkg-logs"
-
-export CHFEATURES
-
-# SETTING A VALUE HERE, ENABLES CCACHE
-CCCACHESIZE='2G'
-
-export CCCACHESIZE
-
diff --git a/config.d/controller/modules/files/ccustom_pacl b/config.d/controller/modules/files/ccustom_pacl
deleted file mode 100644
index 4be0baf..0000000
--- a/config.d/controller/modules/files/ccustom_pacl
+++ /dev/null
@@ -1,13 +0,0 @@
-# Custom package list
-# Include here the packages you want to be emerged.
-# Note: You are building a stateless system, which implies that many rootfs areas will be read only.
-# The more complex you make your system, the highest the chance of breaking the setup will be.
-#
-# Always include packages that require sane write permissions or configure them accordingly to support such a system
-# Also remember to update the USEFLAGS from the Portage menu entry and keep in mind that USE flags often conflict!
-# Add the full package name and category, otherwise on ebuilds with same name from different categories the process wont be able to proceed.
-# Example: foo-category/bar-portage_package
-#
-
-
-# EOF \ No newline at end of file
diff --git a/config.d/controller/modules/files/ccustom_scripts b/config.d/controller/modules/files/ccustom_scripts
deleted file mode 100644
index 4a111fe..0000000
--- a/config.d/controller/modules/files/ccustom_scripts
+++ /dev/null
@@ -1,16 +0,0 @@
-# Custom scripts configuration file
-# Please input the path to your script ( absolute path ) to make it start and run once on bootup.
-#
-# It requires no explanation about the effects of a miss-configured script that runs on bootup.
-# So please include scripts that have been checked and must really be included.
-#
-# For now, this services provides only the features of /etc/local.d
-# In the future a new file will be added with guided interface for configuring Initscripts, which for now
-# go way beyond the scope of this project.
-#
-# Syntax: {/path/to/script}
-
-
-
-
-# EOF \ No newline at end of file
diff --git a/config.d/controller/modules/files/cdevname.info b/config.d/controller/modules/files/cdevname.info
index a62dfcb..9892391 100644
--- a/config.d/controller/modules/files/cdevname.info
+++ b/config.d/controller/modules/files/cdevname.info
@@ -1,14 +1,15 @@
# This file is will be automatically generated if you choose the guided fstab configuration entry
# However there is a manual entry on the submenu to aid extra needs.
+#
# The general syntax of a line is as follows: {LABEL} {device} {size{M,G}/all}
# Example 1 BOOT /dev/sda1 100M will create a partition /dev/sda1 with a fixed size of 100M and LABEL=BOOT
# Example 2 BOOT /dev/sda1 1G will create a partition /dev/sda1 with a fixed size of 1G and LABEL=BOOT
# Example 3 SYS /dev/sdb1 full will create a partition /dev/sdb1 which will take all the available space and LABEL=SYS
# The filesystem type is located at the fstab.info file which is automatically created from the guided fstab entry
# and it can also be configured manually from the same submenu.
-BOOT /dev/sda 500M
-SYS /dev/sdb
-USERDATA /dev/sdc
+#
-
-# EOF \ No newline at end of file
+BOOTFS SDX /dev/sda6 2G btrfs
+SYSFS SDX /dev/sda7 20G ext4
+USERDATAFS SDX /dev/sda8 20G btrfs
+BACKUPFS SDX /dev/sda9 20G ext4
diff --git a/config.d/controller/modules/files/cfeatures b/config.d/controller/modules/files/cfeatures
new file mode 100644
index 0000000..7e0cdca
--- /dev/null
+++ b/config.d/controller/modules/files/cfeatures
@@ -0,0 +1,10 @@
+# CONTROLLER FEATURES
+# CHANGE TO NO IF YOU WISH TO DISABLE SSH FUNCTION
+ssh=yes
+
+# CHANGE TO NO IF YOU WISH TO DIABLE GPG FUCNTION
+gpg=yes
+
+# CHANGE TO NO IF YOU WISH TO EXCLUDE MD5/SHA SUM CHECKS
+sums=yes
+
diff --git a/config.d/controller/modules/files/cfstab.info b/config.d/controller/modules/files/cfstab.info
deleted file mode 100644
index 5b09303..0000000
--- a/config.d/controller/modules/files/cfstab.info
+++ /dev/null
@@ -1,10 +0,0 @@
-# This file realtes the filesystem's type of each device holding the related label
-# Example BOOT vfat will format the partition holding the label LABEL=BOOT with a vfat filesystem
-# This file, together with the fstab and devname.info are probably one of the most essential files
-# that the controller will be built on and use for booting.
-BOOT btrfs
-SYS btrfs
-USERDATA btrfs
-
-
-# EOF \ No newline at end of file
diff --git a/config.d/controller/modules/files/cgentoo.conf b/config.d/controller/modules/files/cgentoo.conf
deleted file mode 100644
index c53ff63..0000000
--- a/config.d/controller/modules/files/cgentoo.conf
+++ /dev/null
@@ -1,12 +0,0 @@
-[DEFAULT]
-main-repo = gentoo
-
-[gentoo]
-location = /usr/portage
-sync-type = rsync
-sync-uri = rsync://192.168.2.2:/usr/portage
-auto-sync = yes
-
-# for daily squashfs snapshots
-#sync-type = squashdelta
-#sync-uri = mirror://gentoo/../snapshots/squashfs
diff --git a/config.d/controller/modules/files/cinject_files b/config.d/controller/modules/files/cinject_files
deleted file mode 100644
index 018613d..0000000
--- a/config.d/controller/modules/files/cinject_files
+++ /dev/null
@@ -1,11 +0,0 @@
-# This file will be used to inject files to the system before it is archived
-#
-# Syntax: {/path/at/local/file} {/path/to/file}
-# Example: /usr/lib64/foo /usr/lib64/bar -> rsync -aAXPhrv /usr/lib64/foo $DISTDIR/stage3/usr/lib64/bar
-
-
-
-
-
-
-# EOF \ No newline at end of file
diff --git a/config.d/controller/modules/cinit_mount.sh b/config.d/controller/modules/files/controller_gpg/gpg_pub
index e69de29..e69de29 100755..100644
--- a/config.d/controller/modules/cinit_mount.sh
+++ b/config.d/controller/modules/files/controller_gpg/gpg_pub
diff --git a/config.d/controller/modules/sources/servers b/config.d/controller/modules/files/controller_ssh/cknown_hosts
index e69de29..e69de29 100644
--- a/config.d/controller/modules/sources/servers
+++ b/config.d/controller/modules/files/controller_ssh/cknown_hosts
diff --git a/config.d/controller/modules/files/csshd b/config.d/controller/modules/files/controller_ssh/cssh_config
index 2f728d2..2f728d2 100644
--- a/config.d/controller/modules/files/csshd
+++ b/config.d/controller/modules/files/controller_ssh/cssh_config
diff --git a/config.d/controller/modules/files/controller_ssh/cssh_priv b/config.d/controller/modules/files/controller_ssh/cssh_priv
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/config.d/controller/modules/files/controller_ssh/cssh_priv
diff --git a/config.d/controller/modules/files/cconsolefont b/config.d/controller/modules/files/system_configs/cconsolefont
index a815cbc..a815cbc 100644
--- a/config.d/controller/modules/files/cconsolefont
+++ b/config.d/controller/modules/files/system_configs/cconsolefont
diff --git a/config.d/controller/modules/files/cfstab b/config.d/controller/modules/files/system_configs/cfstab
index 600b339..600b339 100644
--- a/config.d/controller/modules/files/cfstab
+++ b/config.d/controller/modules/files/system_configs/cfstab
diff --git a/config.d/controller/modules/files/cgrub b/config.d/controller/modules/files/system_configs/cgrub
index 593b019..593b019 100644
--- a/config.d/controller/modules/files/cgrub
+++ b/config.d/controller/modules/files/system_configs/cgrub
diff --git a/config.d/controller/modules/files/chostname b/config.d/controller/modules/files/system_configs/chostname
index e945a22..e945a22 100644
--- a/config.d/controller/modules/files/chostname
+++ b/config.d/controller/modules/files/system_configs/chostname
diff --git a/config.d/controller/modules/files/chosts b/config.d/controller/modules/files/system_configs/chosts
index aab3b89..aab3b89 100644
--- a/config.d/controller/modules/files/chosts
+++ b/config.d/controller/modules/files/system_configs/chosts
diff --git a/config.d/controller/modules/files/clocale.gen b/config.d/controller/modules/files/system_configs/clocale.gen
index e43f238..e43f238 100644
--- a/config.d/controller/modules/files/clocale.gen
+++ b/config.d/controller/modules/files/system_configs/clocale.gen
diff --git a/config.d/controller/modules/files/cnet b/config.d/controller/modules/files/system_configs/cnet
index 30a5030..30a5030 100644
--- a/config.d/controller/modules/files/cnet
+++ b/config.d/controller/modules/files/system_configs/cnet
diff --git a/config.d/controller/modules/files/crunlevels b/config.d/controller/modules/files/system_configs/crunlevels
index 2b544cb..2b544cb 100644
--- a/config.d/controller/modules/files/crunlevels
+++ b/config.d/controller/modules/files/system_configs/crunlevels
diff --git a/config.d/controller/modules/files/cssh.pub b/config.d/controller/modules/files/system_configs/cssh.pub
index 20239c5..20239c5 100644
--- a/config.d/controller/modules/files/cssh.pub
+++ b/config.d/controller/modules/files/system_configs/cssh.pub
diff --git a/config.d/controller/modules/files/system_configs/csshd b/config.d/controller/modules/files/system_configs/csshd
new file mode 100644
index 0000000..2f728d2
--- /dev/null
+++ b/config.d/controller/modules/files/system_configs/csshd
@@ -0,0 +1,149 @@
+# $OpenBSD: sshd_config,v 1.99 2016/07/11 03:19:44 tedu Exp $
+
+# This is the sshd server system-wide configuration file. See
+# sshd_config(5) for more information.
+
+# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
+
+# The strategy used for options in the default sshd_config shipped with
+# OpenSSH is to specify options with their default value where
+# possible, but leave them commented. Uncommented options override the
+# default value.
+
+#Port 22
+#AddressFamily any
+#ListenAddress 0.0.0.0
+#ListenAddress ::
+
+# The default requires explicit activation of protocol 1
+#Protocol 2
+
+# HostKey for protocol version 1
+#HostKey /etc/ssh/ssh_host_key
+# HostKeys for protocol version 2
+#HostKey /etc/ssh/ssh_host_rsa_key
+#HostKey /etc/ssh/ssh_host_dsa_key
+#HostKey /etc/ssh/ssh_host_ecdsa_key
+#HostKey /etc/ssh/ssh_host_ed25519_key
+
+# Lifetime and size of ephemeral version 1 server key
+#KeyRegenerationInterval 1h
+#ServerKeyBits 1024
+
+# Ciphers and keying
+#RekeyLimit default none
+
+# Logging
+#SyslogFacility AUTH
+#LogLevel INFO
+
+# Authentication:
+
+#LoginGraceTime 2m
+#PermitRootLogin prohibit-password
+#StrictModes yes
+#MaxAuthTries 6
+#MaxSessions 10
+
+#RSAAuthentication yes
+#PubkeyAuthentication yes
+
+# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
+# but this is overridden so installations will only check .ssh/authorized_keys
+#AuthorizedKeysFile .ssh/authorized_keys
+
+#AuthorizedPrincipalsFile none
+
+#AuthorizedKeysCommand none
+#AuthorizedKeysCommandUser nobody
+
+# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
+#RhostsRSAAuthentication no
+# similar for protocol version 2
+#HostbasedAuthentication no
+# Change to yes if you don't trust ~/.ssh/known_hosts for
+# RhostsRSAAuthentication and HostbasedAuthentication
+#IgnoreUserKnownHosts no
+# Don't read the user's ~/.rhosts and ~/.shosts files
+#IgnoreRhosts yes
+
+# To disable tunneled clear text passwords, change to no here!
+PasswordAuthentication no
+#PermitEmptyPasswords no
+
+# Change to no to disable s/key passwords
+#ChallengeResponseAuthentication yes
+
+# Kerberos options
+#KerberosAuthentication no
+#KerberosOrLocalPasswd yes
+#KerberosTicketCleanup yes
+#KerberosGetAFSToken no
+
+# GSSAPI options
+#GSSAPIAuthentication no
+#GSSAPICleanupCredentials yes
+
+# Set this to 'yes' to enable PAM authentication, account processing,
+# and session processing. If this is enabled, PAM authentication will
+# be allowed through the ChallengeResponseAuthentication and
+# PasswordAuthentication. Depending on your PAM configuration,
+# PAM authentication via ChallengeResponseAuthentication may bypass
+# the setting of "PermitRootLogin without-password".
+# If you just want the PAM account and session checks to run without
+# PAM authentication, then enable this but set PasswordAuthentication
+# and ChallengeResponseAuthentication to 'no'.
+UsePAM yes
+
+#AllowAgentForwarding yes
+#AllowTcpForwarding yes
+#GatewayPorts no
+#X11Forwarding no
+#X11DisplayOffset 10
+#X11UseLocalhost yes
+#PermitTTY yes
+PrintMotd no
+PrintLastLog no
+#TCPKeepAlive yes
+#UseLogin no
+#UsePrivilegeSeparation sandbox
+#PermitUserEnvironment no
+#Compression delayed
+#ClientAliveInterval 0
+#ClientAliveCountMax 3
+#UseDNS no
+#PidFile /run/sshd.pid
+#MaxStartups 10:30:100
+#PermitTunnel no
+#ChrootDirectory none
+#VersionAddendum none
+
+# no default banner path
+#Banner none
+
+# override default of no subsystems
+Subsystem sftp /usr/lib64/misc/sftp-server
+
+# the following are HPN related configuration options
+# tcp receive buffer polling. disable in non autotuning kernels
+#TcpRcvBufPoll yes
+
+# disable hpn performance boosts
+#HPNDisabled no
+
+# buffer size for hpn to non-hpn connections
+#HPNBufferSize 2048
+
+
+# allow the use of the none cipher
+#NoneEnabled no
+
+# Example of overriding settings on a per-user basis
+#Match User anoncvs
+# X11Forwarding no
+# AllowTcpForwarding no
+# PermitTTY no
+# ForceCommand cvs server
+
+# Allow client to pass locale environment variables #367017
+AcceptEnv LANG LC_*
diff --git a/config.d/controller/modules/files/cystem_links b/config.d/controller/modules/files/system_configs/csystem_links
index d110980..d110980 100644
--- a/config.d/controller/modules/files/cystem_links
+++ b/config.d/controller/modules/files/system_configs/csystem_links
diff --git a/config.d/controller/modules/files/ctimezone b/config.d/controller/modules/files/system_configs/ctimezone
index 7ac3f6d..7ac3f6d 100644
--- a/config.d/controller/modules/files/ctimezone
+++ b/config.d/controller/modules/files/system_configs/ctimezone
diff --git a/config.d/controller/modules/functions/cchroot.sh b/config.d/controller/modules/functions/cchroot.sh
index 9be8f8c..2d6652d 100755
--- a/config.d/controller/modules/functions/cchroot.sh
+++ b/config.d/controller/modules/functions/cchroot.sh
@@ -1,23 +1,32 @@
#!/bin/bash
# EXPORT IMPORTANT VARIABLES BEFORE GOING ON
-source /etc/profile && export PS1="( 'Configuration Phase' ) $PS1"
-CHROOT_DIR="var/tmp/ctworkdir/"
+source "/etc/profile" && export PS1="( 'Configuration Phase' ) $PS1"
+env-update > /dev/null 2>&1
+CHROOT_DIR="var/tmp/ctworkdir"
export CHROOT_DIR
PATH=${PATH}:${CHDIR}
export PATH
-if source "${CHROOT_DIR}/cchroot_functions"; then
- echo "Exporting chroot functions"
+
+if source "${CHROOT_DIR}/cchroot_functions.sh"; then
+ echo -e "[\e[32m*\e[0m] Exporting chroot functions"
else
- echo "Failed to export chroot functions, aborting"
+ echo -e "[\e[31m*\e[0m] Failed to export chroot functions, aborting"
exit 1
fi
-_ctflag_chroot="chroot"
+case "$1" in
+ chroot)
+ _ctflag_chroot="chroot";;
+ revert)
+ _ctflag_chroot="revert";;
+esac
+
export _ctflag_chroot
-# Configuration files
+# CONFIGURATION FILES
_configure_system
-# Runlevels
+# RUNLEVELS
_runlevel_configuration
+
diff --git a/config.d/controller/modules/functions/cchroot_functions.sh b/config.d/controller/modules/functions/cchroot_functions.sh
index f481e56..c5d4c21 100644..100755
--- a/config.d/controller/modules/functions/cchroot_functions.sh
+++ b/config.d/controller/modules/functions/cchroot_functions.sh
@@ -22,16 +22,19 @@ _configure_timezone() {
if [[ "${_ctflag_chroot}" == 'chroot' ]]; then
_state_save "/etc/timezone"
source "${CHROOT_DIR}/ctimezone"
+
if [[ "${TIMEZONE}" != TMZ ]]; then
- echo "${TIMEZONE}" > /etc/timezone && echo -e "[\e[32m*\e[0m] Configuring \e[34mTimezone\e[0m"
+ echo "${TIMEZONE}" > /etc/timezone && echo -e "[\e[32m*\e[0m] Configuring \e[34m${TIMEZONE}\e[0m \e[34mTimezone\e[0m"
else
- echo "UTC" > /etc/timezone && echo -e "[\e[32m*\e[0m] \e[34mConfiguring Timezone\e[0m"
+ echo "UTC" > /etc/timezone && echo -e "[\e[32m*\e[0m] Configuring \e[33mUTC\e[0m \e[34mTimezone\e[0m"
fi
+
_timezone_set
elif [[ "${_ctflag_chroot}" == 'revert' ]]; then
+ echo -e "[\e[33m*\e[0m] Reverting timezone"
cp "${CHROOT_DIR}/last_state/timezone" "/etc/timezone"
_timezone_set
- fi
+ fi
}
_configure_locale() {
@@ -56,23 +59,27 @@ _configure_locale() {
fi
fi
+ echo -e "[\e[34m*\e[0m] Generating locale list"
locale-gen
export LC_ALL="en_US.UTF-8"
SETLOC=$(eselect locale list | grep en_US | awk -F ' ' '{ print $1 }' \
| awk -F '[' '{ print $2 }' | awk -F ']' '{ print $1 }')
- echo "${SETLOC}" > "${CHROOT_DIR}/last_state/SETLOC"
+ echo "${SETLOC}" > "${CHROOT_DIR}/last_state/setloc"
+ echo -e "[\e[34m*\e[0m] Setting locale to [\e[34men_US\e[0m]"
if eselect locale set "${SETLOC}"; then
- echo -e "[\e[32m*\e[0m] Setting locale to [\e[34men_US\e[0m]" \
+ echo -e "[\e[32m*\e[0m] Locale set"
else
echo -e "[\e[31m*\e[0m] Failed setting locale to [\e[34men_US\e[0m]"
fi
+ source "/etc/profile"
unset SETLOC
elif [[ "${_ctflag_chroot}" == 'revert' ]]; then
+ echo -e "[\e[33m*\e[0m] Reverting locale"
cp "${CHROOT_DIR}/last_state/locale.gen" "/etc/locale.gen"
locale-gen
- SETLOC="$(cat "${CHROOT_DIR}/last_state")"
+ SETLOC="$(cat "${CHROOT_DIR}/last_state/setloc")"
eselect locale set "${SETLOC}"
unset SETLOC
fi
@@ -170,10 +177,6 @@ _state_save() {
}
_configure_system() {
- env-update > /dev/null 2>&1 && source /etc/profile
- PATH=${PATH}:${CHROOT_DIR}
- export PATH
-
# TIMEZONE CONFIGURATION
_configure_timezone
@@ -184,6 +187,7 @@ _configure_system() {
# GENERATING FSTAB
_configure_fstab
elif [[ "${_ctflag_chroot}" == 'revert' ]]; then
+ echo -e "[\e[33m*\e[0m] Reverting fstab"
cp "${CHROOT_DIR}/last_state/fstab" "/etc/fstab"
fi
@@ -205,20 +209,29 @@ _configure_system() {
### INSCRIPT ENTRIES WILL BE INCLUDED HERE
# CONFIGURE SSH.PUB
- _state_save "/root/.ssh/authorized_keys"
- [[ -n $(cat "${CHROOT_DIR}/cssh.pub" | sed '/^#/ d' | sed '/^\s*$/d') ]] && mkdir -p /root/.ssh \
- && if cat "${CHROOT_DIR}/cssh.pub" | sed '/^#/ d' | sed '/^\s*$/d' > /root/.ssh/authorized_keys; then
- echo -e "\e[33m----------------------------------------------------------------------------\e[0m"
- echo -e "[\e[32m*\e[0m] Adding ssh.pub key to [\e[34m/root/.ssh/authorized_keys\e[0m]"
- echo -e "\e[33m----------------------------------------------------------------------------\e[0m"
- else
- exit 1
+ if [[ -e "/root/.ssh/authorized_keys" ]]; then
+ _state_save "/root/.ssh/authorized_keys"
+ if [[ -n $(cat "${CHROOT_DIR}/cssh.pub" | sed '/^#/ d' | sed '/^\s*$/d') ]]; then
+ mkdir -p /root/.ssh
+ if cat "${CHROOT_DIR}/cssh.pub" | sed '/^#/ d' | sed '/^\s*$/d' > /root/.ssh/authorized_keys; then
+ echo -e "\e[33m----------------------------------------------------------------------------\e[0m"
+ echo -e "[\e[32m*\e[0m] Adding ssh.pub key to [\e[34m/root/.ssh/authorized_keys\e[0m]"
+ echo -e "\e[33m----------------------------------------------------------------------------\e[0m"
+ else
+ echo -e "[\e[33m*\e[0m] Failed updating authorized_keys"
+ fi
+ fi
fi
- elif [[ "${_ctflag_chroot}" == 'chroot' ]]; then
+ elif [[ "${_ctflag_chroot}" == 'revert' ]]; then
+ echo -e "[\e[33m*\e[0m] Reverting hostname"
cp "${CHROOT_DIR}/last_state/hostname" "/etc/conf.d/hostname"
+ echo -e "[\e[33m*\e[0m] Reverting /etc/conf.d/net"
cp "${CHROOT_DIR}/last_state/net" "/etc/conf.d/net"
+ echo -e "[\e[33m*\e[0m] Reverting /etc/conf.d/grub"
cp "${CHROOT_DIR}/last_state/grub" "/etc/default/grub"
+ echo -e "[\e[33m*\e[0m] Reverting /etc/ssh/sshd_config"
cp "${CHROOT_DIR}/last_state/sshd" "/etc/ssh/sshd_config"
+ echo -e "[\e[33m*\e[0m] Reverting authorized_keys"
cp "${CHROOT_DIR}/last_state/authorized_keys" "/root/.ssh/authorized_keys"
fi
}
@@ -253,8 +266,8 @@ EOF
done < <(rc-update -v | awk -F '|' '{ print $1}')
for i in "${_rl_ar[@]}"; do
- if [[ -n "$(rc-update -v | grep udev | awk -F '|' '{print $2}'| sed "s/[^a-zA-Z]//g")" ]]; then
- _var1="$(rc-update -v | grep udev | awk -F '|' '{print $2}'| sed "s/[^a-zA-Z]//g" | sed '/^#/ d' | sed '/^\s*$/d' | head -n 1)"
+ if [[ -n "$(rc-update -v | grep "$i" | awk -F '|' '{print $2}'| sed "s/[^a-zA-Z]//g")" ]]; then
+ _var1="$(rc-update -v | grep "$i" | awk -F '|' '{print $2}'| sed "s/[^a-zA-Z]//g" | sed '/^#/ d' | sed '/^\s*$/d' | head -n 1)"
echo "$i add ${_var1}" >> "${CHROOT_DIR}/last_state/crunlevels"
unset _var1
fi
@@ -263,7 +276,8 @@ EOF
echo "# EOF" >> "${CHROOT_DIR}/last_state/crunlevels"
unset _rl_ar
_update_runlevels "${CHROOT_DIR}/crunlevels"
- elif [[ "${_ctflag_chroot}" == 'chroot' ]]; then
+ elif [[ "${_ctflag_chroot}" == 'revert' ]]; then
+ echo -e "[\e[33m*\e[0m] Reverting runlevels"
_update_runlevels "${CHROOT_DIR}/last_state/crunlevels"
fi
}
@@ -330,4 +344,7 @@ controller_master_loop() {
break;;
esac
done
-} \ No newline at end of file
+}
+
+
+
diff --git a/config.d/controller/modules/functions/ccrevert_chroot.sh b/config.d/controller/modules/functions/ccrevert_chroot.sh
deleted file mode 100644
index 8ec882a..0000000
--- a/config.d/controller/modules/functions/ccrevert_chroot.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-# EXPORT IMPORTANT VARIABLES BEFORE GOING ON
-source /etc/profile && export PS1="( 'Configuration Phase' ) $PS1"
-CHROOT_DIR="var/tmp/ctworkdir/"
-export CHROOT_DIR
-PATH=${PATH}:${CHDIR}
-export PATH
-if source "${CHROOT_DIR}/cchroot_functions"; then
- echo "Exporting chroot functions"
-else
- echo "Failed to export chroot functions, aborting"
- exit 1
-fi
-
-_ctflag_chroot="revert"
-export _ctflag_chroot
-
-# REVERT CONFIGURATION FILES
-_configure_system
-
-# REVERT RUNLEVELS
-_runlevel_configuration \ No newline at end of file
diff --git a/config.d/controller/modules/functions/cfunctions.sh b/config.d/controller/modules/functions/cfunctions.sh
index 08d669b..ea121e5 100755
--- a/config.d/controller/modules/functions/cfunctions.sh
+++ b/config.d/controller/modules/functions/cfunctions.sh
@@ -4,53 +4,162 @@ die() {
echo "$@" 1>&2 ; exit 1
}
+_a_priori_devices() {
+ if [[ -e "/dev/disk/by-label/SYSFS" ]]; then
+ _SYSLABEL=0
+ else
+ _SYSLABEL=1
+ fi
+
+ export _SYSLABEL
+
+ if [[ -e "/dev/disk/by-label/BOOTFS" ]]; then
+ _BOOTLABEL=0
+ else
+ _BOOTLABEL=1
+ fi
+
+ export _BOOTLABEL
+
+ if [[ -e "/dev/disk/by-label/BACKUPFS" ]]; then
+ _BACKUPLABEL=0
+ else
+ _BACKUPLABEL=1
+ fi
+
+ export _BACKUPLABEL
+
+ if [[ -e "/dev/disk/by-label/USERDATAFS" ]]; then
+ _USERDATALABEL=0
+ _NOUSERDATA=0
+ else
+ _USERDATALABEL=1
+ _NOUSERDATA=1
+ fi
+
+ export _NOUSERDATA
+ export _USERDATALABEL
+}
+
+_case_id() {
+ # EXPORT THE ID OPTION FOR THE TARGET
+ eval _SYID="$(grep "$1" "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $2 }')"
+
+ case "${_SYID}" in
+ BYID)
+ # EXPORT SDX{Y} DEVICE FROM DEVICE ID
+ _tmp_id="$(grep "$1" "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $3 }')"
+ _tmp_type="$(blkid "/dev/disk/by-id/${_tmp_id}" | awk -F 'UUID=' '{ print $2 }' | cut -d ' ' -f 1 | cut -d '"' -f 2)"
+ eval "$2"="$(blkid | grep "${_tmp_type}" | awk -F ':' '{ print $1 }')"
+ ;;
+ UUID)
+ # EXPORT SDX{Y} DEVICE FROM UUID
+ _tmp_id="$(grep "$1" "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $3 }')"
+ eval "$2"="$(blkid | grep "${_tmp_id}" | awk -F ':' '{ print $1 }')"
+ ;;
+ SDX)
+ if ls "${_SYID}" >/dev/null 2>&1; then
+ # SDX{Y} DEVICE
+ eval "$2"="${_SYID}"
+ else
+ # SDX{Y} DEVICE
+ _tmp_fs01="$(grep "$1" "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $3 }')"
+ eval "$2"="${_tmp_fs01}"
+ # THIS OPTION WILL BE USED TO IDENTIFY THE DEVICE.
+ # IN SDX{Y} PARTITION IS MISSING, THE PROCESS WILL CREATE A NEW INTERFACE.
+ fi
+ ;;
+ *)
+ echo "No local device matches $(blkid | grep "${_tmp_type}" | awk -F ':' '{ print $1 }')"
+ return 1
+ ;;
+ esac
+
+ unset _tmp_fs01
+ unset _tmp_i
+ unset _tmp_type
+}
+
+_scan_id_ty() {
+ # CHECK IF { SYSFS, BOOTFS, BACKUPFS, USERDATAFS } LABELS EXIST
+ _a_priori_devices
+
+ # EXPORT SDX{Y} FOR SYSFS/BOOTFS/BACKUPFS/USERDATAFS
+ if [[ "${_SYSLABEL}" == 0 ]]; then
+ SYSDEV="$(blkid | grep "SYSFS" | awk -F ':' '{ print $1 }')"
+ elif [[ "${_SYSLABEL}" == 1 ]]; then
+ _case_id "SYSFS" "SYSDEV"
+ fi
+
+ if [[ "${_BOOTLABEL}" == 0 ]]; then
+ BOOTDEV="$(blkid | grep "BOOTFS" | awk -F ':' '{ print $1 }')"
+ elif [[ "${_BOOTLABEL}" == 1 ]]; then
+ _case_id "BOOTFS" "BOOTDEV"
+ fi
+
+ if [[ "${_BACKUPLABEL}" == 0 ]]; then
+ BACKUPDEV="$(blkid | grep "BACKUPFS" | awk -F ':' '{ print $1 }')"
+ elif [[ "${_BACKUPLABEL}" == 1 ]]; then
+ _case_id "BACKUPFS" "BACKUPDEV"
+ fi
+
+ if [[ "${_USERDATALABEL}" == 0 ]]; then
+ USERDATADEV="$(blkid | grep "USERDATAFS" | awk -F ':' '{ print $1 }')"
+ elif [[ "${_USERDATALABEL}" == 1 ]]; then
+ _case_id "USERDATAFS" "USERDATADEV"
+ fi
+
+ eval "_PAR_BOOTDEV"="$(echo "${BOOTDEV}" | sed 's/[!0-9]//g')"
+ eval "_PAR_NUM_BOOTDEV"="${BOOTDEV: -1}"
+
+ eval "_PAR_SYSDEV"="$(echo "${SYSDEV}" | sed 's/[!0-9]//g')"
+ eval "_PAR_NUM_SYSDEV"="${SYSDEV: -1}"
+
+ eval "_PAR_BACKUPDEV"="$(echo "${BACKUPDEV}" | sed 's/[!0-9]//g')"
+ eval "_PAR_NUM_BACKUPDEV"="${BACKUPDEV: -1}"
+
+ eval "_PAR_USERDATADEV"="$(echo "${USERDATADEV}" | sed 's/[!0-9]//g')"
+ eval "_PAR_NUM_USERDATADEV"="${USERDATADEV: -1}"
+}
+
_bsu_dfs() {
- # EXPORT BOOT DEVICE
- BOOTDEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $2 }')"
- export BOOTDEV
+ _scan_id_ty "$@"
- # EXPORT SYSTEM DEVICE
- SYSDEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep SYS | awk -F ' ' '{ print $2 }')"
+ export BOOTDEV
export SYSDEV
-
- # EXPORT BACKUP DEVICE
- BACKUPDEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BACKUP | awk -F ' ' '{ print $2 }')"
export BACKUPDEV
-
- # EXPORT USERDATA DEVICE
- USERDATADEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $2 }')"
export USERDATADEV
# EXPORT THE BOOT FILE SYSTEM TYPE
- BOOTFS="$(cat "${CTCONFDIR}/confdir/fstab.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $2 }')"
+ BOOTFS="$(grep BOOTFS "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $5 }')"
export BOOTFS
# EXPORT THE SYSTEM FILE SYSTEM TYPE
- SYSFS="$(cat "${CTCONFDIR}/confdir/fstab.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep SYS | awk -F ' ' '{ print $2 }')"
+ SYSFS="$(grep SYSFS "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $5 }')"
export SYSFS
# EXPORT THE BACKUP FILE SYSTEM TYPE
- BACKUPFS="$(cat "${CTCONFDIR}/confdir/fstab.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BACKUP | awk -F ' ' '{ print $2 }')"
+ BACKUPFS="$(grep BACKUPFS "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $5 }')"
export BACKUPFS
# EXPORT THE USERDATA FILE STSTEM TYPE
- USERDATAFS="$(cat "${CTCONFDIR}/confdir/fstab.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $2 }')"
+ USERDATAFS="$(grep USERDATAFS "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $5 }')"
export USERDATAFS
# EXPORT BOOT SIZE
- BOOTSFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $3 }')"
+ BOOTSFS="$(grep BOOTFS "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $4 }')"
export BOOTSFS
# EXPORT SYSTEM SIZE
- SYSSFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep SYS | awk -F ' ' '{ print $3 }')"
+ SYSSFS="$(grep SYSFS "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $4 }')"
export SYSSFS
# EXPORT BACKUP SIZE
- BACKUPSFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BACKUP | awk -F ' ' '{ print $3 }')"
+ BACKUPSFS="$(grep BACKUPFS "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $4 }')"
export BACKUPSFS
# EXPORT USERDATA SIZE
- USERDATASFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $3 }')"
+ USERDATASFS="$(grep USERDATAFS "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $4 }')"
export USERDATASFS
if [[ "${_ctflag_confd}" == 0 ]]; then
@@ -58,47 +167,357 @@ _bsu_dfs() {
fi
}
-server_exp() {
+_create_interface() {
+ _btrfs_subvols() {
+ _create_subvol() {
+ if btrfs subvolume create "$@"; then
+ return 0
+ else
+ return 1
+ fi
+ }
+
+ _check_subvol_entry() {
+ if ! btrfs subvolume list -o "/mnt/workdir" | grep -q "$2"; then
+ echo "Subvolume $2 is missing."
+ echo "Creating subvolume $2 for ${_WRK_LABEL}"
+
+ if _create_subvol "/mnt/workdir/$2"; then
+ echo "Subvolume created successfully"
+ return 0
+ else
+ echo "Failed creating subvolume"
+ return 1
+ fi
+ else
+ echo "Subvolume $2 for ${_WRK_LABEL} exists"
+ fi
+ }
+
+ _check_subvol() {
+ echo "LABEL FOR CHECKSUBVOL: ${_WRK_LABEL}"
+ case "${_WRK_LABEL}" in
+ _BOOTLABEL)
+ _check_subvol_entry "/mnt/workdir" "bootfs";;
+ _SYSLABEL)
+ _check_subvol_entry "/mnt/workdir" "sysfs";;
+ _BACKUPFS)
+ _check_subvol_entry "/mnt/workdir" "backupfs";;
+ _USERDATAFS)
+ _check_subvol_entry "/mnt/workdir" "userdatafs"
+ sleep 0.5
+ _check_subvol_entry "/mnt/workdir" "userdatafs/persistent"
+ sleep 0.5
+ _check_subvol_entry "/mnt/workdir" "userdatafs/persistent/local"
+ sleep 0.5
+ _check_subvol_entry "/mnt/workdir" "userdatafs/persistent/local/home"
+ sleep 0.5
+ _check_subvol_entry "/mnt/workdir" "userdatafs/persistent/local/data"
+ sleep 0.5
+ _check_subvol_entry "/mnt/workdir" "userdatafs/persistent/local/root"
+ sleep 0.5
+ _check_subvol_entry "/mnt/workdir" "userdatafs/persistent/local/config.d"
+ ;;
+ esac
+ }
+
+ echo "Mounting-Remounting ${_WRK_LABEL}"
+ if [[ -n "$(grep "/mnt/workdir" "/proc/mounts" | awk -F ' ' '{ print $2 }')" ]]; then
+ _unmount "/mnt/workdir"
+ fi
+
+ if mount -t "${_WRK_FS}" -o rw "${_WRK_DEV}" "/mnt/workdir"; then
+ echo "${_WRK_LABEL} mounted on /mnt/workdir"
+ if _check_subvol "/mnt/workdir"; then
+ return 0
+ else
+ return 1
+ fi
+ else
+ echo "Could not mount {_WRK_LABEL} on /mnt/workdir"
+ echo "Subvolumes for {_WRK_LABEL} can not be verified"
+ return 1
+ fi
+
+ if [[ -n "$(grep "/mnt/workdir" "/proc/mounts" | awk -F ' ' '{ print $2 }')" ]]; then
+ _unmount "/mnt/workdir"
+ fi
+ }
+
+ _remake_x() {
+ case "${_WRK_LABEL}" in
+ _BOOTLABEL)
+ _R_LABEL='BOOTFS';;
+ _SYSLABEL)
+ _R_LABEL='SYSFS';;
+ _USERDATALABEL)
+ _R_LABEL='USERDATAFS';;
+ _BACKUPLABEL)
+ _R_LABEL='BACKUPFS';;
+ esac
+
+ if [[ "${_WRK_FS}" == 'btrfs' ]]; then
+ _opt_var="-f -L"
+ else
+ _opt_var="-L"
+ fi
+
+ if _remake "${_WRK_FS}" "${_opt_var}" "${_R_LABEL}" "${_WRK_DEV}"; then
+ return 0
+ else
+ return 1
+ fi
+
+ unset _opt_var
+ }
+
+ _interface_x() {
+ echo ${_WRK_PAR}
+ echo ${_WRK_PAR_NUM}
+ echo ${_WRK_SFS}
+ case "$1" in
+ dos)
+ if echo -e "n\np\n${_WRK_PAR_NUM}\n\n+${_WRK_SFS}\nw" | fdisk "${_WRK_PAR}"; then
+ return 0
+ else
+ return 1
+ fi
+ ;;
+ gpt)
+ if echo -e "n\n${_WRK_PAR_NUM}\n\n+${_WRK_SFS}\nw" | fdisk "${_WRK_PAR}"; then
+ return 0
+ else
+ return 1
+ fi
+ ;;
+ na)
+ wipefs "${_WRK_PAR}"
+ if echo -e "g\nn\n${_WRK_PAR_NUM}\n\n+${_WRK_SFS}\nw" | fdisk "${_WRK_PAR}"; then
+ return 0
+ else
+ return 1
+ fi
+ ;;
+ *)
+ echo "Function: _interface_x: Something went wrong"
+ return 1
+ ;;
+ esac
+ }
+
+ _check_drv_condition() {
+ if [[ -n "${_WRK_DEV}" && -n "${_WRK_PAR}" && -n "${_WRK_PAR_NUM}" && -n "${_WRK_SFS}" && -n "${_WRK_FS}" ]]; then
+ echo "Checking is {_WRK_PAR} has a disklabel"
+ _disk_label_type="$(fdisk -l "${_WRK_PAR}" | grep 'Disklabel type:' | cut -d ' ' -f 3)"
+
+ if [[ -n "${_disk_label_type}" ]]; then
+ case "${_disk_label_type}" in
+ gpt)
+ _disklabel="gpt"
+ ;;
+ dos)
+ _disklabel="dos"
+ ;;
+ *)
+ echo "Disklabel format not supported by this scrip."
+ return 1
+ ;;
+ esac
+ else
+ echo "No disklabel detected on ${_WRK_PAR}"
+ _disklabel="na"
+ fi
+
+ echo "Chaking if ${_WRK_PAR} holds any disk partitions"
+ _disk_sub_parts=($(ls -1 ${_WRK_PAR} | grep "[0-9]"))
+
+ if [[ -n "${_disk_sub_parts}" ]]; then
+ echo "${_WRK_PAR} has no disklabel signature, neither hosts a partition"
+ _disk_mark="clear"
+ else
+ echo "${_WRK_PAR} has no disklabel signature, neither hosts a partition"
+ _disk_mark="notclear"
+ fi
+
+ if [[ -z "${_disk_label_type}" && ! -e "${_WRK_DEV}" ]]; then
+ echo "${_WRK_DEV} is not configured"
+ echo "Configuring..."
+
+ if _interface_x "na"; then
+ echo "${_WRK_DEV} created"
+ else
+ echo "Failed to creating ${_WRK_DEV}"
+ return 1
+ fi
+
+ elif [[ -n "${_disk_label_type}" && ! -e "{_WRK_DEV}" ]]; then
+ if _interface_x "${_disk_label_type}"; then
+ echo "${_WRK_DEV} created"
+ else
+ echo "Failed to configure ${_WRK_DEV}"
+ return 1
+ fi
+ elif [[ -n "${_disk_label_type}" && -e "{_WRK_DEV}" ]]; then
+ echo "${_WRK_DEV} is already configured"
+ fi
+ else
+ echo "Device is not set"
+ return 1
+ fi
+
+ _tmp_cfs="$(blkid /dev/sdc1 | grep "TYPE=\"${_WRK_FS}\"")"
+
+ if [[ -z "${_tmp_cfs}" ]]; then
+ echo "Creating ${_WRK_FS} files system on {_WRK_DEV}"
+ if _remake_x; then
+ echo "${_WRK_FS} file system created on ${_WRK_DEV} with ${_R_LABEL} label"
+ else
+ echo "Failed creating ${_WRK_FS} filesystem on ${_WRK_DEV}"
+ return 1
+ fi
+ fi
+
+ if [[ "${_WRK_FS}" == 'btrfs' ]]; then
+ echo "Checking subvolume/s for ${_WRK_LABEL}"
+ _btrfs_subvols "/mnt/workdir"
+ fi
+
+ unset _disk_label_type
+ unset _tmp_cfs
+ }
+
+ for i in "BOOT" "SYS" "USERDATA" "BACKUP"; do
+ _TMP_WRKDEV="${i}DEV"
+ _WRK_DEV="${!_TMP_WRKDEV}"
+
+ _TMP_WRKFS="${i}FS"
+ _WRK_FS="${!_TMP_WRKFS}"
+
+ _TMP_WRKSFS="${i}SFS"
+ _WRK_SFS="${!_TMP_WRKSFS}"
+
+ _TMP_PARDEV="_PAR_${_TMP_WRKDEV}"
+ _WRK_PAR="${!_TMP_PARDEV}"
+
+ _TMP_PARDEV_NUM="_PAR_NUM_${_TMP_WRKDEV}"
+ _WRK_PAR_NUM="${!_TMP_PARDEV_NUM}"
+
+ _TMP_LABEL="_${i}LABEL"
+ _WRK_LABEL="_${i}LABEL"
+ _WRK_LABEL_CON="${!_TMP_LABEL}"
+
+ export _WRK_PAR_NUM
+ export _WRK_PAR
+ export _WRK_SFS
+ export _WRK_FS
+ export _WRK_DEV
+ export _WRK_LABEL
+ export _WRK_LABEL_CON
+
+ echo "Checking $i"
+ if [[ "${_WRK_LABEL_CON}" == 1 ]]; then
+ echo "LABEL: ${_WRK_LABEL}"
+ if _check_drv_condition "$i"; then
+ echo "${_WRK_LABEL} has been configured"
+ echo "Proceeding..."
+ sleep 1
+ else
+ echo "Failed configuring ${_WRK_LABEL}"
+ return 1
+ fi
+ elif [[ "${_WRK_LABEL_CON}" == 0 ]]; then
+ echo "$i is already configured"
+ elif [[ -z "${_WRK_LABEL_CON}" ]]; then
+ echo "Dvice label condtion habe not been exported."
+ echo "Can not proceed."
+ return 1
+ fi
+ done
+
+ unset _TMP_LABEL
+ unset _TMP_PARDEV_NUM
+ unset _TMP_PARDEV
+ unset _TMP_WRKSFS
+ unset _TMP_WRKFS
+ unset _TMP_WRKDEV
+}
+
+_server_exp() {
echo "Selecting server..."
+
+ # CREATE AN ARRAY WHICH HOLDS THE SERVERS
_ser_list=()
- while read -r "s";do
- _ser_list+=("${s}")
- done < "${CTCONFDIR}/sources/servers"
+ # CREATE AN ARRAY WHICH HOLDS THE SERVERS AVERAGE LETENCIES
+ _act_ser_ar=()
- if [[ "${#_ser_list[@]}" -ge 1 ]]; then
- _act_ser_ar=()
- for i in "${_ser_list[@]}"; do
- avms=$(ping -c 3 "$i" | tail -1| awk -F '/' '{print $5}')
- _act_ser+=("${avms}")
- done
- else
- avms=$(ping -c 3 "${_ser_list[0]}" | tail -1| awk -F '/' '{print $5}')
- _act_ser="${avms}"
- fi
-
- _max_entry="${_ser_list[0]}"
- for n in "${_ser_list[@]}" ; do
- if [[ "$n" != '' ]]; then
- ((${n%.*} > ${_max_entry%.*})) && _max_entry="$n"
+ # POPULATE THE ABOVE TWO ARRAYS
+ while read -r s; do
+ echo "Checking $s"
+ # DROP AN ENTRY IF PING FAILS
+ if ping -c 1 "$s" >/dev/null 2>&1; then
+ echo "Connection for $s is true"
+ # GET AVERAGE LETENCY FROM 3 PING ACTIONS ON THE ENTRY
+ avms=$(ping -c 3 "$s" | tail -1 | awk -F '/' '{print $5}')
+ if [[ -n "${avms}" ]]; then
+ # SET THE SERVER THAT COULD BE PINGED
+ _ser_list+=("${s}")
+ # SET THE AVERAGE LETENCY FOR THE ABOVE SERVER AS 1:1
+ _act_ser_ar+=("${avms}")
+ else
+ # SKIP ENTRY
+ echo "Could not get average value for $i"
+ echo "Rejecting this entry"
+ fi
+ else
+ # SKIP ENTRY
+ echo "Connection with $s could not be established"
+ echo "Rejecting this entry"
fi
+
+ done < <(cat ${CTCONFDIR}/sources/servers | sed '/^#/ d' | sed '/^\s*$/d')
+
+ # EXPORT SERVER ARRAY SIZE -1
+ # WE SUBSTRACT -1 BECAUSE ARRAYS START FROM 0 ENTRY
+ _tmp_var_ms="$(( ${#_ser_list[@]} - 1 ))"
+
+ # SET MINIMUM MS AS THE FIRST ENTRY
+ _min_ms="${_act_ser_ar[0]}"
+
+ # COMPARE THE ENTRIES AND KEEP THE MINIMUM
+ for i in $(eval echo "{0..${_tmp_var_ms}}"); do
+ if ((${_act_ser_ar[$i]%.*} <= ${_min_ms%.*})); then
+ _min_ms="${_act_ser_ar[$i]%.*}"
+ _act_ser="${_ser_list[$i]}"
+ fi
done
- _act_ser="${_max_entry}"
+
+ # THE ACTIVE SERVER _ACT_SER IS THE ENTRY WHICH HAD THE LOWEST MS FROM THE 1:1 MS ARRAY
+ echo "Most effective server is: ${_act_ser} with average ms: ${_min_ms}"
+
+ unset _tmp_var_ms
+ unset _min_ms
+ unset _ser_list
+ unset _act_ser_ar
+ unset avms
}
_sources_exp() {
# SOURCE THE SOURCES CONFIGURATION FILES FOR EXPORTING THE SERVER INFORMATIONS
source "${CTCONFDIR}/confdir/sources/sources.conf"
+ # THIS PATH INDICATES THE LOCATION OF THE CONFIG.D DIRECTORY ON THE SERVER SIDE. EXAMPLE: /home/user1/gse/config.d
if [[ -z "${_conf_dir}" ]]; then
_conf_dir="$(grep "confdir" "${CTCONFDIR}/confdir/sources/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{ print $2 }')"
export _conf_dir
fi
+ # THIS PATH INDICATES THE LOCATION OF THE DIST.D DIRECTORY. SEE CONFDIR EXAMPLE
if [[ -z "${_dist_dir}" ]]; then
_dist_dir="$(grep "distdir" "${CTCONFDIR}/confdir/sources/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{ print $2 }')"
export _dist_dir
fi
+ # THIS VARIABLE IS THE USER THAT WILL BE USED FOR THE CONNECTION BETWEEN THE HOST AND THE SERVER.
if [[ -z "${_ser_user}" ]]; then
_ser_user="$(grep "user" "${CTCONFDIR}/confdir/sources/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{ print $2 }')"
export _ser_user
@@ -106,11 +525,20 @@ _sources_exp() {
}
_call_net() {
- ifconfig "${_net_interface}" up
- udhcpc -t 5 -q -s "/bin/net_script.sh"
+ # CALL A SIMPLE DHPCD BUSYBOX NETWORK FUNCTION
+ if grep -q "ip=dhcp" "/proc/cmdline"; then
+ ifconfig "${_net_interface}" up
+ busybox udhcpc -t 5 -q -s "/bin/net_script.sh"
+ fi
+
+ # HERE WILL BE ADDED A CUSTOM NETWORK FUNCTION
+ # MEANING THAT INSTEAD OF RUNNING THE ABOVE DHCP NET FUNCTION
+ # ONE WILL BE ABLE TO SOURCE HIS OWN NETWORKING SCRIPT.
}
+# MOUNT SYSTEM
_mount_sysfs() {
+ # IF MOUNT, THEN REMOUNT
if [[ -n "$(grep "$1" "/proc/mounts" | awk -F ' ' '{ print $2 }')" ]]; then
_unmount "$1"
fi
@@ -122,11 +550,15 @@ _mount_sysfs() {
fi
}
+# THIS FUNCTION CHANGES THE BOOTFLAG FROM SYSFS TO BACKUP
+# LATER ON, THIS DEVICE WILL REPLACE THE CURRENT DEVICE HOSTING THE SYSTEM.
_call_backup_switch() {
_ctflag_bootflag="BACKUP"
export _ctflag_bootflag
}
+# INTERACTIVE FUNCTION
+# DISABLED BY DEFAULT, PROBABLY WILL BE REMOVED
_question() {
for i in "$@"; do
[[ "$i" ]] && echo "$i"
@@ -150,6 +582,7 @@ _question() {
unset _question_no_action
}
+# FETCH THE DEFAULT VERSION FROM THE SERVER
_fetch_version() {
if scp "${_act_user}@${_act_ser}/${_dist_dir}" "${CTCONFDIR}/version"; then
_ctflag_sverison=0
@@ -159,6 +592,7 @@ _fetch_version() {
export _ctflag_sversion
}
+# FETCH NEW CONFIG.D DIRECTORY
_fetch_confd() {
if rsync -aAXPhrv "${_act_user}@${_act_ser}/${_conf_dir}" "${CTCONFDIR}/confdir/"; then
_ctflag_confd=0
@@ -174,20 +608,21 @@ _check_version() {
if [[ "${_ctflag_sversion}" == 0 ]]; then
_local_version="$(cat "/mnt/workdir/var/lib/version")"
_server_version="$(cat "${CTCONFDIR}/version")"
- if [[ "${_local_version}" != "${_server_version}" ]]; then
- if [[ -n "${_ctflag_human}" ]]; then
- if _question "A new System Version is present on the server" "Do you wish to fetch the new system?"; then
- _ctflag_sysfetch=0
+ if [[ "${_local_version}" != "${_server_version}" ]]; then
+ if [[ -n "${_ctflag_human}" ]]; then
+ if _question "A new System Version is present on the server" "Do you wish to fetch the new system?"; then
+ _ctflag_sysfetch=0
+ else
+ _ctflag_sysfetch=1
+ fi
else
- _ctflag_sysfetch=1
+ _ctflag_sysfetch=0
fi
- export _ctflag_sysfetch
else
- _ctflag_sysfetch=0
- export _ctflag_sysfetch
+ echo "Remote version matches the local"
+ _ctflag_sysfetch=1
fi
- else
- echo "Remote version matches the local"
+ export _ctflag_sysfetch
fi
}
@@ -246,6 +681,7 @@ _chroot_config(){
return 0
else
return 1
+ fi
}
_init_chroot() {
@@ -255,7 +691,7 @@ _chroot_config(){
else
echo "Configuration failed"
echo "Reverting changes"
- if _revert_chroot "$1" "var/tmp/ctworkdir/ccrevert_chroot"; then
+ if _revert_chroot "$1" "var/tmp/ctworkdir/ccrevert_chroot.sh"; then
echo "Changes reverted"
else
echo "Failed reverting changes"
@@ -263,7 +699,7 @@ _chroot_config(){
fi
_sys_config=1
fi
- export _no_config
+ export _sys_config
}
_prep_chroot() {
@@ -273,13 +709,8 @@ _chroot_config(){
cp "/usr/local/controller/cchroot.sh" "$1/var/tmp/ctworkdir/cchroot"
_init_chroot "$@"
else
- if [[ "{_ctflag_extract}" == 0 ]]; then
- _call_backup_switch
- else
- echo "Could not initiate system configuration, aborting phase and proceeding"
- fi
_sys_config=1
- export _no_config
+ export _sys_config
fi
}
@@ -287,32 +718,42 @@ _chroot_config(){
_prep_chroot "$@"
else
_sys_config=1
- export _no_config
- controller_master_loop "Could not umount pseudos"
+ export _sys_config
+ fi
+}
+
+_remake() {
+ if eval "mkfs.$1" "$2" "$3" "$4"; then
+ return 0
+ else
+ return 1
fi
}
_remake_sysfs() {
if _unmount "$1"; then
if [[ "${SYSFS}" == 'btrfs' ]]; then
- if eval "mkfs.${SYSFS}" -L ROOTFS -f "${SYSDEV}"; then
+ if _remake "${SYSFS}" "-f -L" "SYSFS" "${SYSDEV}"; then
echo "File system created"
+ _ctflag_remake=0
else
echo "Failed creating new filesystem"
- _call_backup_switch
+ _ctflag_remake=1
fi
else
- if eval "mkfs.${SYSFS}" -L ROOTFS "${SYSDEV}"; then
+ if _remake "${SYSFS}" "-L" "SYSFS" "${SYSDEV}"; then
echo "File system created"
+ _ctflag_remake=0
else
echo "Failed creating new filesystem"
- _call_backup_switch
+ _ctflag_remake=1
fi
fi
else
echo "Failed unmounting workdir"
- _call_backup_switch
+ _ctflag_remake=1
fi
+ export _ctflag_remake
}
_fetch_new_sys() {
@@ -323,60 +764,95 @@ _fetch_new_sys() {
if sync -aAXhq "${_act_user}@${_act_ser}/${_dist_dir}/${_sys_archive}" "$1/"; then
scp "${_act_user}@${_act_ser}/${_dist_dir}/${_sys_archive}.md5sum" "$1/"
scp "${_act_user}@${_act_ser}/${_dist_dir}/${_sys_archive}.gpg" "$1/"
- _verify_t
echo "New system was fetched successfully"
- _ctflag_extract=0
+ _ctflag_fetch=0
else
echo "Fetching new system FAILED"
- _ctflag_extract=1
+ _ctflag_fetch=1
fi
- export _ctflag_extract
else
echo "Failed mounting ${SYSDEV} to $1"
- _call_backup_switch
+ _ctflag_fetch=1
+ fi
+ export _ctflag_fetch
+}
+
+_gpg_import() {
+ gpg --import "/usr/local/controller/gpg/gpg_pub"
+}
+
+_gpg_verify() {
+ if gpg --verify "$1" "$2"; then
+ return 0
+ else
+ return 1
fi
}
_verify_t() {
_verify_md5sum() {
+ (
+ cd "$1"
+
if md5sum -c "${_sys_archive}.md5sum"; then
- return 0
+ echo "PASS" > verify.info
else
- return 1
+ echo "FAILED" > verify.info
fi
+ )
}
-
+
_verify_origin() {
(
cd "$1"
- if gpg --verify "$1/${_sys_archive}.gpg"; then
+ if _gpg_verify "${_sys_archive}.gpg" "${_sys_archive}"; then
echo "PASS" > verify.info
else
echo "FAILED" > verify.info
fi
)
}
+
+ rm -f "$1/verify.info"
- if _verify_origin "$1"; then
- echo "Image's integrity verified"
- _verify_md5sum "$1"
- if [[ "$(cat verify.info)" == 'PASS' ]]; then
- echo "Image's authentication verified"
- elif [[ "$(cat verify.info)" == 'FAILED' ]]; then
- echo "Failed to verify the authentication of the image"
- _call_backup_switch
+ _verify_origin "$1"
+
+ if _check_s "$1"; then
+ echo "Image's authentication verified"
+ _verify_md5sum
+ if _check_s "$1"; then
+ echo "Image's integrity is healthy"
+ _ctflag_verify=0
+ else
+ echo "Image's integrity check failed"
+ _ctflag_verify=1
fi
- rm -f verify.info
else
- echo "Image integrity failed"
+ echo "Failed to verify the authentication of the image"
+ _ctflag_verify=1
+ fi
+ export _ctflag_verify
+}
+
+_check_s() {
+ if [[ "$(cat "$1/verify.info")" == 'PASS' ]]; then
+ rm -f "$1/verify.info"
+ return 0
+ elif [[ "$(cat "$1/verify.info")" == 'FAILED' ]]; then
+ rm -f "$1/verify.info"
+ return 1
fi
}
_extract_sys() {
(
cd "$1"
- tar xvjpf "$2" --xattrs --numeric-owner
+ if tar xvjpf "$2" --xattrs --numeric-owner; then
+ echo "PASS" > verify.info
+ else
+ echo "FAILED" > verify.info
+ fi
)
}
@@ -432,7 +908,6 @@ subshell_loop() {
# CONTROLLER LOOP FUNCTION
controller_master_loop() {
- [[ -z $(echo "$@") ]] && _print_info 3
LOOPVAR="$1"
while true; do
case "${LOOPVAR}" in
@@ -444,3 +919,21 @@ controller_master_loop() {
esac
done
}
+
+_call_tmpfs() {
+ _other_points() {
+ mkdir -p "$NEWROOT/.var"
+ mkdir -p "$NEWROOT/.tmp"
+ mount -t tmpfs -o size=2G tmpfs "$NEWROOT/.var"
+ mount -t tmpfs -o size=5G tmpfs "$NEWROOT/.tmp"
+ rsync -aAXPhrv "$NEWROOT/var/" "$NEWROOT/.var" >/dev/null 2>&1
+ rsync -aAXPhrv "$NEWROOT/tmp/" "$NEWROOT/.tmp" >/dev/null 2>&1
+ mount --move "$NEWROOT/.var" "$NEWROOT/var"
+ mount --move "$NEWROOT/.tmp" "$NEWROOT/tmp"
+ }
+
+ mkdir -p "$NEWROOT/.etc"
+ mount -t tmpfs tmpfs "$NEWROOT/.etc"
+ rsync -aAXPhrv "$NEWROOT/etc/" "$NEWROOT/.etc" >/dev/null 2>&1
+ mount --move "$NEWROOT/.etc" "$NEWROOT/etc"
+}
diff --git a/config.d/controller/modules/functions/check_con.sh b/config.d/controller/modules/functions/check_con.sh
new file mode 100755
index 0000000..019070a
--- /dev/null
+++ b/config.d/controller/modules/functions/check_con.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if echo "$(emerge --version 2>/dev/null | tail -n 1)" | grep -q "$(uname -r)"; then
+ exit 0
+else
+ exit 1
+fi \ No newline at end of file
diff --git a/config.d/controller/modules/functions/cnetwork.sh b/config.d/controller/modules/functions/cnetwork.sh
index 1408f47..aebe1bb 100755
--- a/config.d/controller/modules/functions/cnetwork.sh
+++ b/config.d/controller/modules/functions/cnetwork.sh
@@ -1,28 +1,22 @@
#!/bin/bash
-# SIMPLE DHCP NETWORKING
-if _call_net; then
- _ctflag_net=0
- export _ctflag_net
-fi
-
-# CHECK NETWORK FLAG AND FETCH VERSION AND CONFIG.D DIRECTORY
-if [[ "${_ctflag_net}" ]]; then
- # DEFINE BEST ACTIVE SERVER
- _server_exp
+# NET FUNCTIONS
+source "${CTSCRIPTS}/ct_netf.sh"
- # SOURCES EXP
- _sources_exp
+# EXPORT SERVER
+_server_exp
- # FETCH CONFIG.D
- _fetch_confd
- if [[ "$_ctflag_confd}" == 0 ]]; then
- # EXPORT NEW CONFIGS
- _bsu_dfs
+# CHECK IF NETSELECT OR CUSTOM NET SCRIPT HAS MANAGED TO DEFINE A SERVER
+if _check_net; then
+ # SET NET FLAG TO 0 IF AN ACTIVE SERVER HAS BEEN SET, OTHERWISE SET TO 1
+ if [[ -n "${_ctserver}" ]]; then
+ _ctflag_net=0
+ else
+ _ctflag_net=1
fi
+else
+ _ctflag_net=1
+fi
+
+export _ctflag_net
- # MOUNT SYSFS AS RO
- _mount_sysfs "/mnt/workdir"
- # CHECK LOCAL VERSION OF SYSFS WITH SERVERS VERSION
- _check_version
-fi \ No newline at end of file
diff --git a/config.d/controller/modules/functions/ct_config.sh b/config.d/controller/modules/functions/ct_config.sh
new file mode 100755
index 0000000..6ebdee2
--- /dev/null
+++ b/config.d/controller/modules/functions/ct_config.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+_chroot_config(){
+ _init_chroot() {
+ if chroot "$1" "$2/cchroot.sh" "chroot"; then
+ echo -e "[\e[32m*\e[0m] Configuration was successful"
+ _sys_config=0
+ else
+ echo -e "[\e[31m*\e[0m] Configuration failed"
+ echo -e "[\e[33m*\e[0m] Reverting changes"
+ echo -e "[\e[33m*\e[0m]Initiating revert function"
+ if chroot "$1" "$2/cchroot.sh" "revert"; then
+ echo -e "[\e[32m*\e[0m] Changes reverted"
+ _sys_revert=0
+ else
+ _sys_revert=1
+ echo -e "[\e[31m*\e[0m] Failed reverting changes"
+ echo -e "[\e[33m*\e[0m] Calling backup system"
+ fi
+ export _sys_revert
+ _sys_config=1
+ fi
+ export _sys_config
+ }
+
+ _prep_chroot() {
+ if _mount_sysfs "$1" && _mount_pseudos "$1"; then
+ mkdir -p "$1/$2"
+
+ cp -r "${CTCONFDIR}"/confdir/system_configs/* "$1/$2/"
+ cp "/usr/local/controller/cchroot.sh" "$1/$2/"
+ cp "/usr/local/controller/cchroot_functions.sh" "$1/$2/"
+ _init_chroot "$@"
+ else
+ echo -e "[\e[33m*\e[0m] Failed initiating chroot functions"
+ _sys_config=1
+ export _sys_config
+ fi
+ }
+
+ echo -e "[\e[34m*\e[0m] Initiating chroot"
+ _prep_chroot "$@"
+}
diff --git a/config.d/controller/modules/functions/ct_devices.sh b/config.d/controller/modules/functions/ct_devices.sh
new file mode 100755
index 0000000..0f32886
--- /dev/null
+++ b/config.d/controller/modules/functions/ct_devices.sh
@@ -0,0 +1,130 @@
+#!/bin/bash
+
+# MARKED FOR REMOVAL
+_case_id() {
+ # EXPORT THE ID OPTION FOR THE TARGET
+ eval _SYID="$(grep "$1" "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $2 }')"
+
+ case "${_SYID}" in
+ BYID)
+ # EXPORT SDX{Y} DEVICE FROM DEVICE ID
+ _tmp_id="$(grep "$1" "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $3 }')"
+ _tmp_type="$(blkid "/dev/disk/by-id/${_tmp_id}" | awk -F 'UUID=' '{ print $2 }' | cut -d ' ' -f 1 | cut -d '"' -f 2)"
+ eval "$2"="$(blkid | grep "${_tmp_type}" | awk -F ':' '{ print $1 }')"
+ ;;
+ UUID)
+ # EXPORT SDX{Y} DEVICE FROM UUID
+ _tmp_id="$(grep "$1" "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $3 }')"
+ eval "$2"="$(blkid | grep "${_tmp_id}" | awk -F ':' '{ print $1 }')"
+ ;;
+ SDX)
+ if ls "${_SYID}" >/dev/null 2>&1; then
+ # SDX{Y} DEVICE
+ eval "$2"="${_SYID}"
+ else
+ # SDX{Y} DEVICE
+ _tmp_fs01="$(grep "$1" "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $3 }')"
+ eval "$2"="${_tmp_fs01}"
+ # THIS OPTION WILL BE USED TO IDENTIFY THE DEVICE.
+ # IN SDX{Y} PARTITION IS MISSING, THE PROCESS WILL CREATE A NEW INTERFACE.
+ fi
+ ;;
+ *)
+ echo "No local device matches $(blkid | grep "${_tmp_type}" | awk -F ':' '{ print $1 }')"
+ return 1
+ ;;
+ esac
+
+ unset _tmp_fs01
+ unset _tmp_i
+ unset _tmp_type
+}
+
+# MARKED FOR REMOVAL
+_scan_id_ty() {
+ # CHECK IF { SYSFS, BOOTFS, BACKUPFS, USERDATAFS } LABELS EXIST
+ _a_priori_devices
+
+ # EXPORT SDX{Y} FOR SYSFS/BOOTFS/BACKUPFS/USERDATAFS
+ if [[ "${_SYSLABEL}" == 0 ]]; then
+ SYSDEV="$(blkid | grep "SYSFS" | awk -F ':' '{ print $1 }')"
+ elif [[ "${_SYSLABEL}" == 1 ]]; then
+ _case_id "SYSFS" "SYSDEV"
+ fi
+
+ if [[ "${_BOOTLABEL}" == 0 ]]; then
+ BOOTDEV="$(blkid | grep "BOOTFS" | awk -F ':' '{ print $1 }')"
+ elif [[ "${_BOOTLABEL}" == 1 ]]; then
+ _case_id "BOOTFS" "BOOTDEV"
+ fi
+
+ if [[ "${_BACKUPLABEL}" == 0 ]]; then
+ BACKUPDEV="$(blkid | grep "BACKUPFS" | awk -F ':' '{ print $1 }')"
+ elif [[ "${_BACKUPLABEL}" == 1 ]]; then
+ _case_id "BACKUPFS" "BACKUPDEV"
+ fi
+
+ if [[ "${_USERDATALABEL}" == 0 ]]; then
+ USERDATADEV="$(blkid | grep "USERDATAFS" | awk -F ':' '{ print $1 }')"
+ elif [[ "${_USERDATALABEL}" == 1 ]]; then
+ _case_id "USERDATAFS" "USERDATADEV"
+ fi
+
+ eval "_PAR_BOOTDEV"="$(echo "${BOOTDEV}" | sed 's/[!0-9]//g')"
+ eval "_PAR_NUM_BOOTDEV"="${BOOTDEV: -1}"
+
+ eval "_PAR_SYSDEV"="$(echo "${SYSDEV}" | sed 's/[!0-9]//g')"
+ eval "_PAR_NUM_SYSDEV"="${SYSDEV: -1}"
+
+ eval "_PAR_BACKUPDEV"="$(echo "${BACKUPDEV}" | sed 's/[!0-9]//g')"
+ eval "_PAR_NUM_BACKUPDEV"="${BACKUPDEV: -1}"
+
+ eval "_PAR_USERDATADEV"="$(echo "${USERDATADEV}" | sed 's/[!0-9]//g')"
+ eval "_PAR_NUM_USERDATADEV"="${USERDATADEV: -1}"
+}
+
+# MARKED FOR REMOVAL
+_bsu_dfs() {
+ _scan_id_ty "$@"
+
+ export BOOTDEV
+ export SYSDEV
+ export BACKUPDEV
+ export USERDATADEV
+
+ # EXPORT THE BOOT FILE SYSTEM TYPE
+ BOOTFS="$(grep BOOTFS "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $5 }')"
+ export BOOTFS
+
+ # EXPORT THE SYSTEM FILE SYSTEM TYPE
+ SYSFS="$(grep SYSFS "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $5 }')"
+ export SYSFS
+
+ # EXPORT THE BACKUP FILE SYSTEM TYPE
+ BACKUPFS="$(grep BACKUPFS "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $5 }')"
+ export BACKUPFS
+
+ # EXPORT THE USERDATA FILE STSTEM TYPE
+ USERDATAFS="$(grep USERDATAFS "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $5 }')"
+ export USERDATAFS
+
+ # EXPORT BOOT SIZE
+ BOOTSFS="$(grep BOOTFS "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $4 }')"
+ export BOOTSFS
+
+ # EXPORT SYSTEM SIZE
+ SYSSFS="$(grep SYSFS "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $4 }')"
+ export SYSSFS
+
+ # EXPORT BACKUP SIZE
+ BACKUPSFS="$(grep BACKUPFS "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $4 }')"
+ export BACKUPSFS
+
+ # EXPORT USERDATA SIZE
+ USERDATASFS="$(grep USERDATAFS "${CTCONFDIR}/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $4 }')"
+ export USERDATASFS
+
+ if [[ "${_ctflag_confd}" == 0 ]]; then
+ _sources_exp
+ fi
+}
diff --git a/config.d/controller/modules/functions/ct_fetch.sh b/config.d/controller/modules/functions/ct_fetch.sh
new file mode 100755
index 0000000..fcdf6cb
--- /dev/null
+++ b/config.d/controller/modules/functions/ct_fetch.sh
@@ -0,0 +1,219 @@
+#!/bin/bash
+
+# MOUNT SYSTEM
+_mount_sysfs() {
+ # IF MOUNT, THEN REMOUNT
+ if [[ -n "$(grep "$1" "/proc/mounts" | awk -F ' ' '{ print $2 }')" ]]; then
+ _unmount "$1"
+ fi
+
+ echo -e "[\e[34m*\e[0m] Using fsck on ${SYSDEV}"
+ if fsck -y "${SYSDEV}" >/dev/null 2>&1; then
+ echo -e "[\e[32m*\e[0m] Filesystem looks healthy"
+ _fscheck=0
+ else
+ echo -e "[\e[33m*\e[0m] Filesystem appears corrupted"
+ echo -e "[\e[34m*\e[0m] Attempting to repair"
+ if fsck -yf "${SYSDEV}"; then
+ echo -e "[\e[32m*\e[0m] Repair was successful"
+ _fscheck=0
+ else
+ echo -e "[\e[31m*\e[0m] Automatic repair failed"
+ _fscheck=1
+ fi
+ fi
+
+ if [[ "${_fscheck}" == 1 ]]; then
+ _rescue_shell
+ fi
+
+ unset _fscheck
+
+ echo -e "[\e[34m*\e[0m] Attempting to mount ${SYSDEV} at $1"
+ if eval mount -t "${SYSFS}" -o rw -L "SYSFS" "$1"; then
+ echo -e "[\e[32m*\e[0m] Mounted successfully"
+ return 0
+ else
+ echo -e "[\e[31m*\e[0m] Failed mounting"
+ return 1
+ fi
+}
+
+# FETCH THE DEFAULT VERSION FROM THE SERVER
+_fetch_version() {
+ if scp "${_ser_user}@${_ctserver}:${_dist_dir}/latest_stage" "${CTCONFDIR}/version"; then
+ _ctversion=0
+ else
+ _ctversion=1
+ fi
+ export _ctversion
+}
+
+# FETCH NEW CONFIG.D DIRECTORY
+_fetch_confd() {
+ echo -e "[\e[34m*\e[0m] Syncing confdir from server"
+ if [[ -n "$(rsync -aAPhrcn "${_ser_user}@${_ctserver}:${_conf_dir}/controller/modules/files/" "${CTCONFDIR}/confdir/" --delete | sed '/receiving incremental file list/d')" ]]; then
+ if rsync -aAPhrqc "${_ser_user}@${_ctserver}:${_conf_dir}/controller/modules/files/" "${CTCONFDIR}/confdir/" --delete; then
+ echo -e "[\e[32m*\e[0m] Sync was successful"
+ echo -e "[\e[34m*\e[0m] Syncing new confdir to storage"
+
+ mount -t "${BOOTFS}" -o rw "${BOOTDEV}" "/mnt/log"
+
+ if rsync -aAPhqrc "${CTCONFDIR}/confdir" "/mnt/log/" --delete; then
+ echo -e "[\e[32m*\e[0m] Synced"
+ sync;sync
+ else
+ echo -e "[\e[33m*\e[0m] Failed"
+ fi
+
+ umount -l "/mnt/log"
+
+ _ctflag_confd=0
+ else
+ _ctflag_confd=1
+ fi
+ else
+ echo -e "[\e[35m*\e[0m] No changes detected"
+ _ctflag_confd=1
+ fi
+ export _ctflag_confd
+}
+
+_check_version() {
+ if [[ "${_ctversion}" == 0 ]]; then
+ _server_version="$(cat "${CTCONFDIR}/version")"
+ if [[ -e "/mnt/workdir/var/lib/gse/version" ]]; then
+ _local_version="$(cat "/mnt/workdir/var/lib/gse/version")"
+ if [[ "${_local_version}" != "${_server_version}" ]]; then
+ if [[ -n "${_ctflag_human}" ]]; then
+ if _question "A new System Version is present on the server" "Do you wish to fetch the new system?"; then
+ _ctflag_sysfetch=0
+ else
+ _ctflag_sysfetch=1
+ fi
+ else
+ echo -e "[\e[33m*\e[0m] Remote version does not matches local"
+ _ctflag_sysfetch=0
+ fi
+ else
+ echo -e "[\e[35m*\e[0m] Remote version matches the local"
+ _ctflag_sysfetch=1
+ fi
+ elif [[ ! -e "/mnt/workdir/var/lib/gse/version" ]]; then
+ echo -e "[\e[31m*\e[0m] System is corrupted"
+ _ctflag_sysfetch=9
+ fi
+ export _ctflag_sysfetch
+ fi
+}
+
+_fetch_new_sys() {
+ if _mount_sysfs "$1"; then
+ _sys_archive="stage3-amd64-${_server_version}.tar.bz2"
+ export _sys_archive
+
+ if scp "${_ser_user}@${_ctserver}:${_dist_dir}/${_sys_archive}" "$1/"; then
+ scp "${_ser_user}@${_ctserver}:${_dist_dir}/${_sys_archive}.md5sum" "$1/"
+ #scp "${_ser_user}@${_ctserver}:${_dist_dir}/${_sys_archive}.sig" "$1/"
+ echo -e "[\e[32m*\e[0m] New system was fetched successfully"
+ _ctflag_fetch=0
+ else
+ echo -e "[\e[31m*\e[0m] Fetching new system FAILED"
+ _ctflag_fetch=1
+ fi
+ else
+ echo -e "[\e[31m*\e[0m] Failed mounting ${SYSDEV} to $1"
+ _ctflag_fetch=1
+ fi
+ export _ctflag_fetch
+}
+
+_verify_target() {
+ _verify_md5sum() {
+ (
+ cd "$1"
+
+ if md5sum -c "${_sys_archive}.md5sum"; then
+ echo "PASS" > "/tmp/verify.info"
+ else
+ echo "FAILED" > "/tmp/verify.info"
+ fi
+ )
+ }
+
+ _verify_origin() {
+ (
+ cd "$1"
+
+ if _gpg_verify "${_sys_archive}.sig" "${_sys_archive}"; then
+ echo "PASS" > "/tmp/verify.info"
+ else
+ echo "FAILED" > "/tmp/verify.info"
+ fi
+ )
+ }
+
+ _check_last() {
+ if [[ "$(cat "/tmp/verify.info")" == 'PASS' ]]; then
+ rm -f "/tmp/verify.info"
+ return 0
+ elif [[ "$(cat "/tmp/verify.info")" == 'FAILED' ]]; then
+ rm -f "/tmp/verify.info"
+ return 1
+ fi
+ }
+
+ rm -f "/tmp/verify.info"
+
+ #_verify_origin "$1"
+
+ _md5_check() {
+ _verify_md5sum "$1"
+ if _check_last; then
+ _ctflag_verify=0
+ return 0
+ else
+ _ctflag_verify=1
+ return 1
+ fi
+ }
+
+ _restricted() {
+ if _check_last; then
+ echo -e "[\e[35m*\e[0m] Origin verified"
+ _md5_check "$1"
+ else
+ if [[ ! -e "${CTSCRIPTS}/gpg/gpg_pub" ]]; then
+ echo -e "[\e[33m*\e[0m] No gpg key found!"
+ _md5_check "$1"
+ elif [[ -e "${CTSCRIPTS}/gpg/gpg_pub" ]]; then
+ echo -e "[\e[31m*\e[0m] Failed to verify the authentication of the image"
+ _ctflag_verify=1
+ fi
+ fi
+ }
+
+ if _md5_check "$1"; then
+ echo -e "[\e[35m*\e[0m] Integrity verified"
+ else
+ echo -e "[\e[33m*\e[0m] Integrity check failed"
+ fi
+ export _ctflag_verify
+}
+
+_extract_sys() {
+ (
+ cd "$1"
+ _e_report_back "Extracting system tarball..."
+ if tar xvjpf "$2" --xattrs --numeric-owner >/dev/null; then
+ echo -e "[\e[32m*\e[0m] Extracted"
+ echo "PASS" > "/tmp/verify.info"
+ else
+ echo -e "[\e[31m*\e[0m] An error occured"
+ echo "FAILED" > "/tmp/verify.info"
+ fi
+ )
+}
+
+
+
diff --git a/config.d/controller/modules/functions/ct_netf.sh b/config.d/controller/modules/functions/ct_netf.sh
new file mode 100755
index 0000000..b0a1660
--- /dev/null
+++ b/config.d/controller/modules/functions/ct_netf.sh
@@ -0,0 +1,149 @@
+#!/bin/bash
+
+# Export the sources.conf file
+_sources_exp() {
+ _ctserv_num="$(grep "${_ctserver}" "${CTCONFDIR}/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{print $1}')"
+ _ctserv_num="${_ctserv_num:6:7}"
+
+ # THIS PATH INDICATES THE LOCATION OF THE CONFIG.D DIRECTORY ON THE SERVER SIDE. EXAMPLE: /home/user1/gse/config.d
+ _conf_dir="$(grep "confdir${_ctserv_num}" "${CTCONFDIR}/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{ print $2 }')"
+ export _conf_dir
+
+ # THIS PATH INDICATES THE LOCATION OF THE DIST.D DIRECTORY. SEE CONFDIR EXAMPLE
+ _dist_dir="$(grep "distdir${_ctserv_num}" "${CTCONFDIR}/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{ print $2 }')"
+ export _dist_dir
+
+ # THIS VARIABLE IS THE USER THAT WILL BE USED FOR THE CONNECTION BETWEEN THE HOST AND THE SERVER.
+ _ser_user="$(grep "user${_ctserv_num}" "${CTCONFDIR}/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{ print $2 }')"
+ export _ser_user
+
+ # EXPORT THE SYSTEM FILE SYSTEM TYPE
+ SYSFS="$(blkid | grep "LABEL=\"SYSFS\"" | awk -F ' ' '{print $4}' | awk -F '=' '{print $2}' | sed 's/\"//g')"
+ export SYS
+}
+
+_server_exp() {
+ # Manual method in case one wishes to remove netselect for size or any other reason
+ # MUCH SLOWER
+ #
+ _manual_check() {
+ # CREATE AN ARRAY WHICH HOLDS THE SERVERS
+ _ser_list=()
+ # CREATE AN ARRAY WHICH HOLDS THE SERVERS AVERAGE LETENCIES
+ _act_ser_ar=()
+
+ # POPULATE THE ABOVE TWO ARRAYS
+ while read -r s; do
+ _e_report_back "Checking $s"
+ # DROP AN ENTRY IF PING FAILS
+ if ping -c 1 "$s" >/dev/null 2>&1; then
+ echo -e "[\e[32m*\e[0m] Connection for $s is true"
+ # GET AVERAGE LETENCY FROM 3 PING ACTIONS ON THE ENTRY
+ avms=$(ping -c 3 "$s" | tail -1 | awk -F '/' '{print $5}')
+ if [[ -n "${avms}" ]]; then
+ # SET THE SERVER THAT COULD BE PINGED
+ _ser_list+=("${s}")
+ # SET THE AVERAGE LETENCY FOR THE ABOVE SERVER AS 1:1
+ _act_ser_ar+=("${avms}")
+ else
+ # SKIP ENTRY
+ echo -e "[\e[33m*\e[0m] Could not get average value for $i"
+ _e_report_back "Rejecting this entry"
+ fi
+ else
+ # SKIP ENTRY
+ echo -e "[\e[33m*\e[0m] Connection with $s could not be established"
+ echo -e "[\e[33m*\e[0m] Rejecting this entry"
+ fi
+
+ done < $(grep "server" "${CTCONFDIR}/sources/sources.conf" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{print $2}')
+
+ # EXPORT SERVER ARRAY SIZE -1
+ # WE SUBSTRACT -1 BECAUSE ARRAYS START FROM 0 ENTRY
+ _tmp_var_ms="$(( ${#_ser_list[@]} - 1 ))"
+
+ # SET MINIMUM MS AS THE FIRST ENTRY
+ _min_ms="${_act_ser_ar[0]}"
+
+ # COMPARE THE ENTRIES AND KEEP THE MINIMUM
+ for i in $(eval echo "{0..${_tmp_var_ms}}"); do
+ if ((${_act_ser_ar[$i]%.*} <= ${_min_ms%.*})); then
+ _min_ms="${_act_ser_ar[$i]%.*}"
+ _act_ser="${_ser_list[$i]}"
+ fi
+ done
+
+ # THE ACTIVE SERVER _ACT_SER IS THE ENTRY WHICH HAD THE LOWEST MS FROM THE 1:1 MS ARRAY
+ _o_report_back "Most effective server is: ${_act_ser} with average ms: ${_min_ms}"
+ _ctserver="${_act_ser}"
+ export _ctserver
+
+ unset _act_ser
+ unset _tmp_var_ms
+ unset _min_ms
+ unset _ser_list
+ unset _act_ser_ar
+ unset avms
+ }
+
+ echo -e "[\e[34m*\e[0m] Selecting server..."
+
+ if [[ -e "/usr/bin/netselect" ]]; then
+ _ser_tmp=()
+
+ for i in $(cat ${CTCONFDIR}/sources.conf | grep server | sed '/^#/ d' | sed '/^\s*$/d' | awk -F ':' '{print $2}'); do
+ _ser_tmp+=("$i")
+ done
+
+ _ser_list=()
+
+ for i in $(netselect -v -t2 -s10 "${_ser_tmp[@]}" | awk -F ' ' '{print $2}'); do
+ _ser_list+=("$i")
+ _e_report_back "$i"
+ done
+
+ unset _ser_tmp
+
+ _ctserver="${_ser_list[0]}"
+ else
+ _manual_check
+ fi
+}
+
+_check_net() {
+ if [[ -n "${_ctserver}" ]]; then
+ return 0
+ else
+ if grep -q "net:0" "/usr/local/unet/udent_flag"; then
+ # RE-SOURCE THE CUSTOM NET SCRIPT AND CHECK AGAIN
+ echo -e "[\e[33m*\e[0m] Re-sourcing the custom net script"
+ source "/usr/local/unet/unet.sh"
+ _tmp_net_ct=0
+ while true; do
+ if ip a | grep -q "state UP"; then
+ break
+ fi
+
+ ((++_tmp_net_ct))
+ sleep 1
+
+ if [[ "${_tmp_net_ct}" -ge 10 ]]; then
+ break
+ fi
+ done
+
+ _server_exp
+
+ if [[ "${_ctserver}" == '' ]]; then
+ return 0
+ else
+ return 1
+ fi
+ else
+ return 1
+ fi
+ fi
+}
+
+
+
diff --git a/config.d/controller/modules/functions/ct_newsys.sh b/config.d/controller/modules/functions/ct_newsys.sh
new file mode 100755
index 0000000..5ffa5d1
--- /dev/null
+++ b/config.d/controller/modules/functions/ct_newsys.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+_remake() {
+ if eval "mkfs.$1" "$2" "$3" "$4"; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+_remake_dev() {
+ if _unmount "$1"; then
+ if [[ "${SYSFS}" == 'btrfs' ]]; then
+ wipefs "$2"
+ if _remake "${SYSFS}" "-f -L" "SYSFS" "$2"; then
+ echo "File system created"
+ _ctflag_remake=0
+ else
+ echo "Failed creating new filesystem"
+ _ctflag_remake=1
+ fi
+ else
+ wipefs "$2"
+ if _remake "${SYSFS}" "-F -L" "SYSFS" "$2"; then
+ echo "File system created"
+ _ctflag_remake=0
+ else
+ echo "Failed creating new filesystem"
+ _ctflag_remake=1
+ fi
+ fi
+ else
+ echo "Failed unmounting /mnt/workdir"
+ _ctflag_remake=1
+ fi
+ export _ctflag_remake
+}
+
+
+
diff --git a/config.d/controller/modules/functions/ct_prelim.sh b/config.d/controller/modules/functions/ct_prelim.sh
new file mode 100755
index 0000000..4edae82
--- /dev/null
+++ b/config.d/controller/modules/functions/ct_prelim.sh
@@ -0,0 +1,421 @@
+#!/bin/bash
+
+# Exit and print to stderr
+die() {
+ echo "$@" 1>&2 ; exit 1
+}
+
+_call_backup_switch() {
+ if [[ "${_ctflag_bconf}" != 0 && "${_ctflag_setup}" != 0 ]]; then
+ _ctflag_switch=0
+ export _ctflag_switch
+ else
+ echo -e "[\e[31m*\e[0m] Switch to backup is called but there is no backup"
+ _rescue_shell "Switch to backup is called but there is no backup"
+ # exit 1
+ fi
+}
+
+_gpg_import() {
+ gpg --import "/usr/local/controller/gpg/gpg_pub" >/dev/null 2>&1
+}
+
+_gpg_verify() {
+ if gpg --verify "$1" "$2"; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+_bsu_dfs() {
+ #/DEV/SDX
+ SYSDEV="$(blkid | grep "SYSFS" | awk -F ':' '{ print $1 }')"
+ BACKUPDEV="$(blkid | grep "BACKUPFS" | awk -F ':' '{ print $1 }')"
+ BOOTDEV="$(blkid | grep "BOOTFS" | awk -F ':' '{ print $1 }')"
+ USERDATADEV="$(blkid | grep "USERDATAFS" | awk -F ':' '{ print $1 }')"
+
+ export SYSDEV
+ export BACKUPDEV
+ export USERDATADEV
+ export BOOTDEV
+
+ # EXPORT SYSTEM'S FS
+ SYSFS="$(blkid | grep "LABEL=\"SYSFS\"" | awk -F ' ' '{print $4}' | awk -F '=' '{print $2}' | sed 's/\"//g')"
+ export SYS
+
+ # EXPORT BACKUP's FS
+ BACKUPFS="$(blkid | grep "LABEL=\"BACKUPFS\"" | awk -F ' ' '{print $4}' | awk -F '=' '{print $2}' | sed 's/\"//g')"
+ export BACKUPFS
+
+ BOOTFS="$(blkid "${BOOTDEV}" | awk -F ' ' '{print $4}' | sed 's/TYPE=//g' | sed 's/"//g')"
+ USERDATAFS="$(blkid "${USERDATADEV}" | awk -F ' ' '{print $4}' | sed 's/TYPE=//g' | sed 's/"//g')"
+ export BOOTFS
+ export USERDATAFS
+
+ _server_version="$(cat "${CTCONFDIR}/version")"
+
+ if [[ -n "${BOOTFS}" ]]; then
+ mkdir -p "/mnt/log"
+ mount -t "${BOOTFS}" -o rw "${BOOTDEV}" "/mnt/log"
+
+ if [[ -e "/mnt/log/confdir" ]]; then
+ echo -e "[\e[34m*\e[0m] Updating confdir from local storage"
+
+ if rsync -aAPrhqc "/mnt/log/confdir" "${CTCONFDIR}/" --delete; then
+ sync;sync
+ echo -e "[\e[32m*\e[0m] Updated"
+ else
+ echo -e "[\e[31m*\e[0m] Failed"
+ fi
+ fi
+
+ umount -l "/mnt/log"
+ else
+ echo -e "[\e[33m*\e[0m] WARNING: BOOTFS has not been defined"
+ fi
+
+ if [[ -n "${USERDATAFS}" ]]; then
+ : # TBU
+ else
+ echo -e "[\e[33m*\e[0m] WARNING: USERDATAFS has not been defined"
+ fi
+}
+
+_unmount_all_targets() {
+ _unmount "/mnt/workdir"
+ _unmount "/mnt/bfs"
+ _unmount "/mnt/rfs"
+}
+
+_e_report_back() {
+ echo -e "\e[33m$*\e[0m" 1>&2
+}
+
+_o_report_back() {
+ echo -e "\e[34m$*\e[0m" 1>&2
+}
+
+pass() {
+ echo -e "[\e[34m$@\e[0m]"
+}
+
+# CHECK IF LABELS EXIST
+_a_priori_devices() {
+ if [[ -e "/dev/disk/by-label/SYSFS" ]]; then
+ _SYSLABEL=0
+ else
+ _SYSLABEL=1
+ fi
+
+ export _SYSLABEL
+
+ if [[ -e "/dev/disk/by-label/BOOTFS" ]]; then
+ _BOOTLABEL=0
+ else
+ _BOOTLABEL=1
+ fi
+
+ export _BOOTLABEL
+
+ if [[ -e "/dev/disk/by-label/BACKUPFS" ]]; then
+ _BACKUPLABEL=0
+ else
+ _BACKUPLABEL=1
+ fi
+
+ export _BACKUPLABEL
+
+ if [[ -e "/dev/disk/by-label/USERDATAFS" ]]; then
+ _USERDATALABEL=0
+ _NOUSERDATA=0
+ else
+ _USERDATALABEL=1
+ _NOUSERDATA=1
+ fi
+
+ export _NOUSERDATA
+ export _USERDATALABEL
+}
+
+# MOUNT TARGET
+_mount_target() {
+ # IF MOUNT, THEN REMOUNT
+ if [[ -n "$(grep "$1" "/proc/mounts" | awk -F ' ' '{ print $2 }')" ]]; then
+ _unmount "$1"
+ fi
+
+ echo -e "[\e[34m*\e[0m] Using fsck on $2"
+ if fsck -y "$2" >/dev/null 2>&1; then
+ echo -e "[\e[32m*\e[0m] Filesystem looks healthy"
+ _fscheck=0
+ else
+ echo -e "[\e[33m*\e[0m] Filesystem appears corrupted"
+ echo -e "[\e[34m*\e[0m] Attempting to repair"
+ if fsck -yf "$2"; then
+ echo -e "[\e[32m*\e[0m] Repair was successful"
+ _fscheck=0
+ else
+ echo -e "[\e[31m*\e[0m] Automatic repair failed"
+ _fscheck=1
+ fi
+ fi
+
+ if [[ "${_fscheck}" == 1 ]]; then
+ _rescue_shell
+ fi
+
+ unset _fscheck
+
+ echo -e "[\e[34m*\e[0m] Attempting to mount $3 at $1"
+ if eval mount -t "$2" -o rw -L "$3" "$1"; then
+ echo -e "[\e[32m*\e[0m] Mounted successfully"
+ return 0
+ else
+ echo -e "[\e[31m*\e[0m] Failed mounting"
+ return 1
+ fi
+}
+
+_mount_pseudos() {
+ for i in "dev" "sys" "proc"; do
+ if [[ ! -e "$1/$i" ]]; then
+ return 1
+ fi
+ done
+
+ if ! mount -t proc /proc "$1/proc"; then
+ return 1
+ fi
+
+ for i in "dev" "sys"; do
+ if ! mount --rbind "/$i" "$1/$i"; then
+ return 1
+ fi
+ done
+
+ for i in "dev" "sys"; do
+ if ! mount --make-rslave "$1/$i"; then
+ return 1
+ fi
+ done
+}
+
+_sync_backupfs() {
+ if rsync -aAXrhqc --exclude={"/proc","/dev","/sys"} "/mnt/rfs/" "/mnt/bfs/" --delete; then
+ mkdir -p "/mnt/bfs/proc"
+ mkdir -p "/mnt/bfs/sys"
+ mkdir -p "/mnt/bfs/dev"
+
+ return 0
+ else
+ return 1
+ fi
+}
+
+_check_rbfs() {
+ if _mount_target "/mnt/rfs" "${SYSFS}" "SYSFS"; then
+ if _mount_pseudos "/mnt/rfs"; then
+ cp "/usr/local/controller/check_con.sh" "/mnt/rfs/"
+ chmod +x "/mnt/rfs/check_con.sh"
+ if chroot "/mnt/rfs" "/check_con.sh"; then
+ _rfs_check=0
+ else
+ _rfs_check=1
+ fi
+ else
+ _rfs_check=1
+ fi
+ else
+ _rescue_shell "Could not mount ${SYSDEV}"
+ fi
+
+ if _mount_target "/mnt/bfs" "${BACKUPFS}" "BACKUPFS"; then
+ if _mount_pseudos "/mnt/bfs"; then
+ cp "/usr/local/controller/check_con.sh" "/mnt/bfs/"
+ chmod +x "/mnt/bfs/check_con.sh"
+ if chroot "/mnt/bfs" "/check_con.sh"; then
+ _bfs_check=0
+ else
+ _bfs_check=1
+ fi
+ else
+ _bfs_check=1
+ fi
+ else
+ _rescue_shell "Could not mount ${BACKUPDEV}"
+ fi
+
+ unset _ctflag_setup
+
+ if [[ "${_rfs_check}" == 1 && "${_bfs_check}" == 1 ]]; then
+ echo -e "[\e[33m*\e[0m] Neither one of SYSFS or BACKUPFS appear to host a root system"
+ _ctflag_setup=0
+ elif [[ "${_rfs_check}" == 1 && "${_bfs_check}" == 0 ]]; then
+ echo -e "[\e[33m*\e[0m] SYSFS appears to be missing"
+ _ctflag_setup=1
+ elif [[ "${_rfs_check}" == 0 && "${_bfs_check}" == 1 ]]; then
+ echo -e "[\e[33m*\e[0m] BACKUPFS is missing, fixing..."
+ _ctflag_setup=2
+ else
+ echo -e "[\e[34m*\e[0m] Both SYSFS and BACKUPFS appear to host a root system"
+ _ctflag_setup=3
+ fi
+
+ export _ctflag_setup
+
+ unset _rfs_check
+ unset _bfs_check
+
+ _unmount "/mnt/rfs"
+ _unmount "/mnt/bfs"
+ _unmount "/mnt/workdir"
+}
+
+_sync_targets() {
+ _mount_target "/mnt/rfs" "${SYSFS}" "SYSFS"
+ _mount_target "/mnt/bfs" "${BACKUPFS}" "BACKUPFS"
+
+ _sync_backupfs
+
+ _unmount "/mnt/rfs"
+ _unmount "/mnt/bfs"
+}
+
+_unset_ct() {
+ unset _ctflag_switch
+ unset _ctflag_net
+ unset _ctflag_sysfetch
+ unset _ctflag_setup
+ unset _ctflag_extract
+ unset _ctflag_bconf
+ unset _ctflag_fetch
+ unset _ctflag_verify
+ unset _ctflag_remake
+ unset _ctflag_confd
+ unset _sys_config
+ unset _sys_revert
+ unset _check_sysver
+}
+
+# INTERACTIVE FUNCTION
+# DISABLED BY DEFAULT, PROBABLY WILL BE REMOVED
+_question() {
+ for i in "$@"; do
+ [[ "$i" ]] && _e_report_back "$i"
+ done
+
+ while true; do
+ _e_report_back "Answer: Y/N "
+ read -rp "Input :: <= " ANS
+ case "${ANS}" in
+ [yY])
+ return 0
+ break;;
+ [nN]])
+ return 1
+ break;;
+ esac
+ done
+
+ unset ANS
+ unset _question_yes_action
+ unset _question_no_action
+}
+
+_shell() {
+ echo -e "\e[33mCalling bash subshell\e[0m"
+ sleep 2
+ echo 'echo -e "\e[33mInside Subshell\e[0m"' >> /root/.bashrc
+ echo 'echo -e "\e[33mExit to return back to parent\e[0m"' >> /root/.bashrc
+ (clear; exec /bin/bash && echo s;)
+ sed -i "/Inside Subshell/d" "/root/.bashrc"
+ sed -i "/Exit to return back to parent/d" "/root/.bashrc"
+ echo -e "\e[33mYou are back to parent\e[0m"
+}
+
+# CALL SHELL
+_rescue_shell() {
+ while true; do
+ for i in "$@"; do
+ echo "$i"
+ done
+
+ _e_report_back "Do you wish to call shell function and fix the issues manually?"
+ _e_report_back "Answer Y/N "
+ read -rp "Input :: <= " YN
+ case "$YN" in
+ [yY])
+ subshell_loop "SHELL"
+ break;;
+ [nN])
+ break;;
+ esac
+ done
+}
+
+# SUBSHELL LOOP FUNCTION, IT OFFERS
+subshell_loop() {
+ while true; do
+ _shell
+ _e_report_back "If you fixed the issue, say CONTINUE proceed"
+ _e_report_back "You can answer SHELL to open shell again"
+ _e_report_back "Answer? CONTINUE/SHELL: "
+ read -rp "Input :: <= " AANS
+ case "${AANS}" in
+ CONTINUE )
+ LOOPVAR="EXITSHELL"
+ break;;
+ SHELL )
+ LOOPVAR="SHELL"
+ ;;
+ * )
+ ;;
+ esac
+ done
+}
+
+# CONTROLLER LOOP FUNCTION
+controller_master_loop() {
+ LOOPVAR="$1"
+ while true; do
+ case "${LOOPVAR}" in
+ SHELL)
+ subshell_loop;;
+ EXITSHELL)
+ break;;
+
+ esac
+ done
+}
+
+# UNMOUNT TARGET
+_unmount() {
+ k=0
+ if [[ -n "$(grep "$1" "/proc/mounts" | awk -F ' ' '{ print $2 }')" ]]; then
+ while true; do
+ while read -r i; do
+ if echo "$i" | grep -q "$1"; then
+ eval umount -l "$i"/* >/dev/null 2>&1
+ eval umount -l "$i" >/dev/null 2>&1
+ fi
+ done < "/proc/mounts"
+
+ if [[ -z $(grep "$1" "/proc/mounts") ]]; then
+ break
+ fi
+
+ if [[ "$k" -ge 20 ]]; then
+ echo -e "[\e[31m*\e[0m] Could not unmount target $1"
+ return 1
+ fi
+ sleep 0.1
+ ((++k))
+ done
+
+ return 0
+
+ fi
+}
+
+
diff --git a/config.d/controller/modules/functions/net_script.sh b/config.d/controller/modules/functions/net_script.sh
deleted file mode 100755
index ca4ff9a..0000000
--- a/config.d/controller/modules/functions/net_script.sh
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/bin/busybox sh
-# udhcpc script edited by Tim Riker <Tim@Rikers.org>
-
-RESOLV_CONF="/etc/resolv.conf"
-
-[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
-
-NETMASK=""
-[ -n "$subnet" ] && NETMASK="netmask $subnet"
-BROADCAST="broadcast +"
-[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
-
-case "$1" in
- deconfig)
- echo "Setting IP address 0.0.0.0 on $interface"
- ifconfig $interface 0.0.0.0
- ;;
-
- renew|bound)
- echo "Setting IP address $ip on $interface"
- ifconfig $interface $ip $NETMASK $BROADCAST
-
- if [ -n "$router" ] ; then
- echo "Deleting routers"
- while route del default gw 0.0.0.0 dev $interface ; do
- :
- done
-
- metric=0
- for i in $router ; do
- echo "Adding router $i"
- if [ "$subnet" = "255.255.255.255" ]; then
- # special case for /32 subnets:
- # /32 instructs kernel to always use routing for all outgoing packets
- # (they can never be sent to local subnet - there is no local subnet for /32).
- # Used in datacenters, avoids the need for private ip-addresses between two hops.
- ip route add $i dev $interface
- fi
- route add default gw $i dev $interface metric $((metric++))
- done
- fi
-
- echo "Recreating $RESOLV_CONF"
- # If the file is a symlink somewhere (like /etc/resolv.conf
- # pointing to /run/resolv.conf), make sure things work.
- realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
- tmpfile="$realconf-$$"
- > "$tmpfile"
- [ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
- for i in $dns ; do
- echo " Adding DNS server $i"
- echo "nameserver $i" >> "$tmpfile"
- done
- mv "$tmpfile" "$realconf"
- ;;
-esac
-
-exit 0
diff --git a/config.d/controller/modules/init_script.sh b/config.d/controller/modules/init_script.sh
new file mode 100755
index 0000000..4311314
--- /dev/null
+++ b/config.d/controller/modules/init_script.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+echo "Creating tmp_dir"
+if mkdir -p tmp_dir; then
+ echo "Created"
+ echo "Mounting /dev/sda5 to tmp_dir"
+
+ if mount -t ext4 -o rw /dev/sda5 tmp_dir; then
+ echo "Mounted"
+ _proceed_var=0
+ else
+ _proceed_var=1
+ fi
+else
+ _proceed_var=1
+fi
+
+
diff --git a/config.d/controller/modules/module-setup.sh b/config.d/controller/modules/module-setup.sh
index a8c721a..7c24557 100755
--- a/config.d/controller/modules/module-setup.sh
+++ b/config.d/controller/modules/module-setup.sh
@@ -4,93 +4,312 @@
check() {
if [[ -e $moddir/cinit_pre-mount.sh ]]; then
{
- return 0
+ return 0
}
else
{
- return 1
+ return 1
}
fi
}
# called by dracut
install() {
+
# Install packages
- inst_multiple chroot chown chmod ls sed awk mount ls ln umount
- inst_multiple cp mv busybox rsync ssh gpg bash rmmod dmesg modprobe findmnt
- inst_multiple tar bzip2 ping clear mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.btrfs mkfs.vfat
- inst_multiple e2label mlabel swaplabel scp md5sum sha512sum lsblk tee sed awk arping
- inst_multiple dhclient ifconfig scp lsmod fusermount rmmod strace rm
+ inst_multiple chroot chown chmod ls sed awk mount ls ln umount tail
+ inst_multiple cp mv busybox rsync dmesg findmnt dirname head
+ inst_multiple tar bash bzip2 clear scp lsblk tee sed awk basename sync
+ inst_multiple fusermount strace wipefs rm grep ps uname du find uname fdisk
+
+ # test
+ inst_multiple vim vi sensors ssh sshd
+ inst_simple "/etc/ssh/ssh_config" "/etc/ssh/ssh_config"
+ inst_simple "/etc/ssh/sshd_config" "/etc/ssh/sshd_config"
+
+ # Network packages
+ _ct_netmod() {
+ inst_multiple dhclient ping ping6 netstat netselect dhcpcd arping ifconfig ip
+
+ # Install libs for the dns functions
+ inst_simple "/lib64/libnss_dns.so.2" "/lib64/libnss_dns.so.2"
+ inst_simple "/lib64/libnss_files.so.2" "/lib64/libnss_files.so.2"
+ inst_simple "/lib64/ld-linux-x86-64.so.2" "/lib64/ld-linux-x86-64.so.2"
+ inst_simple "/lib64/libresolv.so.2" "/lib64/libresolv.so.2"
+ inst_simple "/lib64/libc.so.6" "/lib64/libc.so.6"
+ inst_simple "/lib64/libmount.so.1" "/lib64/libmount.so.1"
+ inst_simple "/lib64/libblkid.so.1" "/lib64/libblkid.so.1"
+ inst_simple "/lib64/libuuid.so.1" "/lib64/libuuid.so.1"
+ inst_simple "/lib64/ld-linux-x86-64.so.2" "/lib64/ld-linux-x86-64.so.2"
+ inst_simple "/lib64/libext2fs.so.2" "/lib64/libext2fs.so.2"
+ inst_simple "/lib64/libcom_err.so.2" "/lib64/libcom_err.so.2"
+ inst_simple "/lib64/libe2p.so.2" "/lib64/libe2p.so.2"
+ inst_simple "/lib64/libpthread.so.0" "/lib64/libpthread.so.0"
+ inst_simple "/lib64/libdl.so.2" "/lib64/libdl.so.2"
+ inst_simple "/lib64/libz.so.1" "/lib64/libz.so.1"
+ inst_simple "/lib64/liblzo2.so.2" "/lib64/liblzo2.so.2"
+ inst_simple "/usr/lib64/libfdisk.so.1.1.0" "/usr/lib64/libfdisk.so.1.1.0"
+ inst_simple "/lib64/libsmartcols.so.1" "/lib64/libsmartcols.so.1"
+ inst_simple "/lib64/libreadline.so.6" "/lib64/libreadline.so.6"
+ inst_simple "/lib64/libncurses.so.6" "/lib64/libncurses.so.6"
+ inst_simple "/usr/lib64/libncursesw.so" "/usr/lib64/libncursesw.so"
+ inst_simple "/usr/lib64/libncursesw.so" "/usr/lib64/libncursesw.so"
+ inst_simple "/usr/lib64/libmagic.so.1" "/usr/lib64/libmagic.so.1"
+ inst_simple "/lib64/libncursesw.so.6" "/lib64/libncursesw.so.6"
+ inst_simple "/lib64/libnss_files.so.2" "/lib64/libnss_files.so.2"
+ inst_simple "/lib64/libattr.so.1" "/lib64/libattr.so.1"
+ inst_simple "/lib64/libacl.so.1" "/lib64/libacl.so.1"
+ inst_simple "/usr/lib64/libpopt.so.0" "/usr/lib64/libpopt.so.0"
+ inst_simple "/lib64/libnss_compat.so.2" "/lib64/libnss_compat.so.2"
+ inst_simple "/lib64/libnsl.so.1" "/lib64/libnsl.so.1"
+ inst_simple "/lib64/libnss_nis.so.2" "/lib64/libnss_nis.so.2"
+ inst_simple "/lib64/libnss_dns.so.2" "/lib64/libnss_dns.so.2"
+ inst_simple "/lib64/libnss_files.so.2" "/lib64/libnss_files.so.2"
+ inst_simple "/lib64/libresolv.so.2" "/lib64/libresolv.so.2"
+ inst_simple "/lib64/ld-linux-x86-64.so.2" "/lib64/ld-linux-x86-64.so.2"
+
+ }
+
+ # Fsck
inst_multiple fsck fsck.ext2 fsck.ext4 fsck.ext3 fsck.ext4dev fsck.vfat e2fsck
- inst_multiple ping6 netstat vi grep ps
- # Install libs for the dns functions
- inst_simple "/lib64/libnss_dns.so.2"
- inst_simple "/lib64/libnss_files.so.2"
- inst_simple "/lib64/ld-linux-x86-64.so.2"
- inst_simple "/lib64/libresolv.so.2"
- inst_simple "/lib64/libc.so.6"
+ # Labels
+ inst_multiple e2label mlabel swaplabel
+
+ # Modules
+ inst_multiple insmod rmmod modprobe lsmod
+ # File systems packages
+ inst_multiple mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.btrfs mkfs.vfat
+
# Create controller directory, rfs, bfs and workdir
- mkdir -m 0755 -p ${initdir}/config.d/fetchdir,confdir}
- mkdir -m 0755 -p ${initdir}/config.d/confdir/{local,keys,jobs}
- mkdir -m 0755 -p ${initdir}/etc/gse
- mkdir -m 0755 -p ${initdir}/usr/local/controller
- mkdir -m 700 -p ${initdir}/root/.ssh
- mkdir -m 0755 -p ${initdir}/mnt/{rfs,bfs}
- mkdir -m 0755 -p ${initdir}/mnt/{etc_tmpfs,tmp_tmpfs,var_tmp_tmpfs,workdir}
- mkdir -m 0755 -p ${initdir}/user-data/persistent/{local,nfs,log,var,etc}
- mkdir -m 0755 -p ${initdir}/user-data/persistent/local/{root,home,data,mnt,media}
+ mkdir -m 0755 -p "${initdir}/config.d/confdir"
+ mkdir -m 0755 -p "${initdir}/usr/local/controller"
+ mkdir -m 700 -p "${initdir}/root/.ssh"
+ mkdir -m 0755 -p "${initdir}/mnt/rfs"
+ mkdir -m 0755 -p "${initdir}/mnt/bfs"
+ mkdir -m 0755 -p "${initdir}/mnt/etc_tmpfs"
+ mkdir -m 0755 -p "${initdir}/mnt/tmp_tmpfs"
+ mkdir -m 0755 -p "${initdir}/mnt/var_tmp_tmpfs"
+ mkdir -m 0755 -p "${initdir}/mnt/workdir"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/local"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/nfs"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/log"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/var"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/etc"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/local/root"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/local/home"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/local/data"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/local/mnt"
+ mkdir -m 0755 -p "${initdir}/user-data/persistent/local/media"
# Install scripts for the controller process
inst_script "$moddir/functions/cchroot.sh" "/usr/local/controller/cchroot.sh"
- inst_script "$moddir/functions/net_script.sh" "/bin/net_script.sh"
- inst_script "$moddir/functions/cbootflags.sh" "/usr/local/controller/cbootflags.sh"
+ inst_script "$moddir/functions/cchroot_functions.sh" "/usr/local/controller/cchroot_functions.sh"
+ inst_script "$moddir/functions/check_con.sh" "/usr/local/controller/check_con.sh"
+ inst_script "$moddir/functions/cnetwork.sh" "/usr/local/controller/cnetwork.sh"
+ inst_script "$moddir/functions/ct_config.sh" "/usr/local/controller/ct_config.sh"
+ inst_script "$moddir/functions/ct_devices.sh" "/usr/local/controller/ct_devices.sh"
+ inst_script "$moddir/functions/ct_fetch.sh" "/usr/local/controller/ct_fetch.sh"
+ inst_script "$moddir/functions/ct_netf.sh" "/usr/local/controller/ct_netf.sh"
+ inst_script "$moddir/functions/ct_newsys.sh" "/usr/local/controller/ct_newsys.sh"
+ inst_script "$moddir/functions/ct_prelim.sh" "/usr/local/controller/ct_prelim.sh"
+ inst_script "$moddir/functions/net_script.sh" "/usr/local/controller/net_script.sh"
+
inst_script "$moddir/functions/cfunctions.sh" "/usr/local/controller/cfunctions.sh"
inst_script "$moddir/functions/chealth.sh" "/usr/local/controller/chealth.sh"
- inst_script "$moddir/functions/cnetwork.sh" "/usr/local/controller/cnetwork.sh"
- inst_script "$moddir/functions/ccrevert_chroot" "/usr/local/controller/ccrevert_chroot"
+
+
+ # Install configuration files for controller
+
+ # SSH Configuration
+ # To enable ssh, please include your priv key at "${CCONFD}/controller/modules/files/ssh/cssh_priv"
+ mkdir -m 0755 -p "${initdir}/usr/local/controller/ssh"
+ # INSTALL SSH
+ inst_simple ssh
+ inst_simple sshd
+
+ # CONFIGURATION FILE
+ inst_simple "$moddir/files/controller_ssh/cssh_config" "/etc/ssh/ssh_config"
+ inst_simple "$moddir/files/controller_ssh/cssh_config" "/usr/local/controller/ssh/ssh_config.backup"
+
+ # KNOWN HOSTS
+ inst_simple "$moddir/files/controller_ssh/cknown_hosts" "/root/.ssh/known_hosts"
+ inst_simple "$moddir/files/controller_ssh/cknown_hosts" "/usr/local/controller/ssh/known_hosts.backup"
+
+ # PRIVATE KEY (CLIENTS -> SERVER)
+ inst_simple "$moddir/files/controller_ssh/cssh_priv" "/root/.ssh/ida_rsa"
+ inst_simple "$moddir/files/controller_ssh/cssh_priv" "/usr/local/controller/ssh/ida_rsa.backup"
+
+ # GPG
+ mkdir -m 0755 -p "${initdir}/usr/local/controller/gpg"
+ inst_simple gpg
+ inst_simple "$moddir/files/controller_gpg/gpg_pub" "/usr/local/controller/gpg/gpg_pub"
- # Install configuration files
- inst_simple "$moddir/sources/sources.conf" "config.d/confdir/sources/sources.conf"
- inst_simple "$moddir/sources/servers" "config.d/confdir/sources/servers"
- inst_simple "$moddir/files/cssh_config" "/etc/ssh/ssh_config"
- inst_simple "$moddir/files/cknown_hosts" "/root/.ssh/known_hosts"
- inst_simple "$moddir/files/cssh_priv" "/root/.ssh/ida_rsa"
- inst_simple "$moddir/files/cgentoo.conf" "/etc/gse/gentoo.conf"
- inst_simple "$moddir/files/csources.conf" "/etc/gse/sources.conf"
- inst_simple "$moddir/files/cservers.conf" "/etc/gse/servers.conf"
- inst_simple "$moddir/files/cfstab" "/etc/fstab"
- inst_simple "$moddir/files/cnet" "/config.d/confdir/net"
- inst_simple "$moddir/files/cconsolefont" "/config.d/confdir/consolefont"
- inst_simple "$moddir/files/crunlevels" "/config.d/confdir/runlevels"
- inst_simple "$moddir/files/cdevname.info" "/config.d/confdir/devname.info"
- inst_simple "$moddir/files/conf.d/cfstab.info" "/config.d/confdir/fstab.info"
- inst_simple "$moddir/files/ccustom_scripts" "/config.d/confdir/ccustom_scripts"
- inst_simple "$moddir/files/cgrub" "/config.d/confdir/grub"
- inst_simple "$moddir/files/ccoptions" "/config.d/confdir/coptions"
- inst_simple "$moddir/files/chostname" "/config.d/confdir/hostname"
- inst_simple "$moddir/files/chosts" "/config.d/confdir/hosts"
- inst_simple "$moddir/files/clocale.gen" "/config.d/confdir/locale.gen"
- inst_simple "$moddir/files/cssh.pub" "/config.d/confdir/ssh.pub"
- inst_simple "$moddir/files/csshd_config" "/config.d/confdir/sshd_config"
- inst_simple "$moddir/files/csystem_links" "/config.d/confdir/system_links"
+ # SUMS
+ inst_multiple md5sum sha224sum sha256sum sha384sum sha512sum
+
+ # FSTAB FILE FOR MOUNTING DRIVES ON INITRAMFS PHASE
+ if [[ -e "$moddir/files/cfstab" ]]; then
+ inst_simple "$moddir/files/cfstab" "/etc/fstab"
+ fi
+
+ # Install configuration files for the system
+ inst_simple "$moddir/files/cdevname.info" "/config.d/cdevname.info"
+ inst_simple "$moddir/sources/sources.conf" "/config.d/sources.conf"
+
+ inst_simple "$moddir/files/system_configs/cnet" "/config.d/confdir/net"
+ inst_simple "$moddir/files/system_configs/cconsolefont" "/config.d/confdir/consolefont"
+ inst_simple "$moddir/files/system_configs/crunlevels" "/config.d/confdir/runlevels"
+ inst_simple "$moddir/files/system_configs/cfstab.info" "/config.d/confdir/fstab.info"
+ inst_simple "$moddir/files/system_configs/cgrub" "/config.d/confdir/grub"
+ inst_simple "$moddir/files/system_configs/chostname" "/config.d/confdir/hostname"
+ inst_simple "$moddir/files/system_configs/chosts" "/config.d/confdir/hosts"
+ inst_simple "$moddir/files/system_configs/clocale.gen" "/config.d/confdir/locale.gen"
+ inst_simple "$moddir/files/system_configs/cssh.pub" "/config.d/confdir/ssh.pub"
+ inst_simple "$moddir/files/system_configs/csshd" "/config.d/confdir/sshd_config"
+ inst_simple "$moddir/files/system_configs/csystem_links" "/config.d/confdir/system_links"
+
+ # NETWORK
+ mkdir -m 0755 -p "${initdir}/usr/local/unet"
+
+ _ct_netmod
+
+ # CUSTOM NETSCRIPT
+ if [[ -e "${moddir}/unet/unet.conf" ]]; then
+ _unetscript="$(cat ${moddir}/unet/unet.conf)"
+ if [[ -e "${moddir}/unet/${_unetscript}" ]]; then
+ inst_hook pre-mount 08 "${moddir}/unet/${_unetscript}"
+ inst_script "${moddir}/unet/${_unetscript}" "/usr/local/unet/unet.sh"
+ fi
+ fi
+
+ # CUSTOM HOOK SCRIPTS
+ mkdir -m 0755 -p "${initdir}/usr/local/uscripts"
+
+ if [[ -e "${moddir}/uscripts/insthook" ]]; then
+ while read s; do
+
+ _tmp_hp="$(echo "$s" | awk -F ' ' '{print $1}')"
+ _tmp_pr="$(echo "$s" | awk -F ' ' '{print $2}')"
+ _tmp_scname="$(echo "$s" | awk -F ' ' '{print $3}')"
+
+ if [[ -e "${moddir}/uscripts/${_tmp_scname}" ]]; then
+ eval inst_hook "${_tmp_hp}" "${_tmp_pr}" "${moddir}/uscripts/${_tmp_scname}"
+ fi
+ done < <(cat "${moddir}/uscripts/insthook")
+ fi
+
+ unset _crpt_cnt
+ unset _tmp_hp
+ unset _tmp_p
+ unset _tmp_scname
+
+ # KERNEL MODULES
+ mkdir -m 0775 -p "${initdir}/etc/modprobe.d"
+
+ if [[ -e "${moddir}/umod/umod.conf" ]]; then
+ _umodname="$(cat "${moddir}/umod/umod.conf")"
+ if [[ -e "${moddir}/umod/${_umodname}" ]]; then
+ inst_simple "${moddir}/umod/${_umodname}" "/etc/modprobe.d/umod.conf"
+ fi
+ fi
# Install the hookpoints for the controller process {here the process is defined}
- inst_hook pre-mount 01 "$moddir/cinit_pre-mount.sh"
- inst_hook mount 01 "$moddir/cinit_mount.sh"
- inst_hook clean 01 "$moddir/cinit_clean.sh"
+ inst_hook pre-mount 02 "$moddir/init_script.sh"
+ inst_hook pre-mount 03 "$moddir/cinit_pre-mount.sh"
+ inst_hook pre-pivot 02 "$moddir/cinit_mount_dev.sh"
+ inst_hook pre-pivot 03 "$moddir/cinit_clean.sh"
}
# called by dracut
installkernel() {
# Include kernel modules
- instmods "=drivers"
- instmods "=arch"
- instmods "=crypto"
- instmods "=fs"
- instmods "=lib"
- instmods "=mm"
- instmods "=net"
- instmods "=sound"
+ # Please note that these modules are for testing
+ # Controller does not require most of them, as it does not require
+ # many of the above installed packages.
+ #
+ # However the development is mostly done inside the initramfs, so that's why these packages and tools
+ # If you wish to do your own testing, please remove the hardware specific modules like radeon and intel for example
+ # and add your own. You can add your own packages above, but dont remove essential packages that are used by the scripts
+ #
+ #
+
+ hostonly='' instmods sr_mod
+ hostonly='' instmods cdrom
+ hostonly='' instmods sr_mod
+ hostonly='' instmods sd_mod
+ hostonly='' instmods radeon
+ hostonly='' instmods ttm
+ hostonly='' instmods drm_kms_helper
+ hostonly='' instmods iTCO_wdt
+ hostonly='' instmods iTCO_vendor_support
+ hostonly='' instmods ppdev
+ hostonly='' instmods snd_hda_codec_realtek
+ hostonly='' instmods snd_hda_codec_generic
+ hostonly='' instmods snd_hda_codec_hdmi
+ hostonly='' instmods coretemp
+ hostonly='' instmods drm
+ hostonly='' instmods radeon
+ hostonly='' instmods kvm_intel
+ hostonly='' instmods snd_hda_intel
+ hostonly='' instmods snd_hda_codec
+ hostonly='' instmods ata_generic
+ hostonly='' instmods pata_acpi
+ hostonly='' instmods kvm_intel
+ hostonly='' instmods snd_hda_core
+ hostonly='' instmods ahci
+ hostonly='' instmods snd_hwdep
+ hostonly='' instmods syscopyarea
+ hostonly='' instmods i2c_i801
+ hostonly='' instmods ata_piix
+ hostonly='' instmods r8169
+ hostonly='' instmods libahci
+ hostonly='' instmods pata_jmicron
+ hostonly='' instmods lpc_ich
+ hostonly='' instmods irqbypass
+ hostonly='' instmods kvm
+ hostonly='' instmods mfd_core
+ hostonly='' instmods mii
+ hostonly='' instmods sysfillrect
+ hostonly='' instmods snd_pcm
+ hostonly='' instmods crc32c_intel
+ hostonly='' instmods snd_timer
+ hostonly='' instmods pcspkr
+ hostonly='' instmods serio_raw
+ hostonly='' instmods snd
+ hostonly='' instmods sysimgblt
+ hostonly='' instmods fb_sys_fops
+ hostonly='' instmods i2c_algo_bit
+ hostonly='' instmods i2c_core
+ hostonly='' instmods parport_pc
+ hostonly='' instmods soundcore
+ hostonly='' instmods parport
+ hostonly='' instmods ppdev
+ hostonly='' instmods dm_multipath
+ hostonly='' instmods sunrpc
+ hostonly='' instmods dm_mirror
+ hostonly='' instmods dm_region_hash
+ hostonly='' instmods dm_log
+ hostonly='' instmods dm_mod
+ hostonly='' instmods dax
+
+ hostonly='' instmods jbd2
+ hostonly='' instmods fscrypto
+ hostonly='' instmods mbcache
+ hostonly='' instmods ext4
+ hostonly='' instmods btrfs
+ hostonly='' instmods vfat
+ hostonly='' instmods fat
+ hostonly='' instmods xor
+
+ #instmods "=drivers"
+ #instmods "=arch"
+ #instmods "=crypto"
+ #instmods "=fs"
+ #instmods "=lib"
+ #instmods "=mm"
+ #instmods "=net"
+ #instmods "=sound"
} \ No newline at end of file