aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--BUGS.REPORT3
-rw-r--r--LICENCE2
-rw-r--r--README.md8
-rw-r--r--TODO75
-rwxr-xr-xbin/gse82
-rwxr-xr-xbin/gse.py255
-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
-rw-r--r--config.d/system/devname.info10
-rw-r--r--config.d/system/fstab22
-rw-r--r--config.d/system/inject_files6
-rw-r--r--docs/Examples-TBU5
-rw-r--r--docs/Guides-TBU9
-rw-r--r--docs/documentations/ctgse.148
-rw-r--r--docs/guides/Guide-Builder16
-rw-r--r--docs/guides/Guide-Controller60
-rw-r--r--etc/gentoo.conf33
-rw-r--r--local/sinprog18
-rwxr-xr-xscripts/controller73
-rwxr-xr-xscripts/functions/drv_interface254
-rwxr-xr-xscripts/functions/local_rbuild36
-rwxr-xr-xscripts/functions/makeconf_ed8
-rwxr-xr-xscripts/functions/men_opt5
-rwxr-xr-xscripts/functions/renew186
-rwxr-xr-xscripts/functions/sinit_functions484
-rw-r--r--scripts/gpyfunctions/__init__.py2
-rw-r--r--scripts/gpyfunctions/controller/__init__.py2
-rwxr-xr-xscripts/gpyfunctions/gseclass.py18
-rw-r--r--scripts/gpyfunctions/menu/__init__.py3
-rw-r--r--scripts/gpyfunctions/menu/portal/__init__.py2
-rwxr-xr-xscripts/gpyfunctions/menu/portal/gportal.py93
-rw-r--r--scripts/gpyfunctions/menu/txmen/__init__.py2
-rwxr-xr-xscripts/gpyfunctions/menu/txmen/gsetxf.py143
-rwxr-xr-xscripts/gpyfunctions/menu/txmen/gsetxmen.py151
-rwxr-xr-xscripts/gpyfunctions/menu/txmen/gsub_men.py574
-rwxr-xr-xscripts/gpyfunctions/preliminary.py187
-rw-r--r--scripts/gpyfunctions/system/__init__.py2
-rw-r--r--scripts/gpyfunctions/tools/__init__.py2
-rwxr-xr-xscripts/gpyfunctions/tools/gseout.py75
-rwxr-xr-xscripts/gpyfunctions/tools/librarium.py503
-rwxr-xr-xscripts/gpyfunctions/tools/warp.py496
-rwxr-xr-xscripts/sinit11
86 files changed, 6073 insertions, 1629 deletions
diff --git a/.gitignore b/.gitignore
index d7c0e65..84ee293 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+__psycache__
trash
s.sh
dist.d
@@ -13,3 +14,7 @@ create_dracut.sh
inprogress
flashit.sh
makeit_go.sh
+tmp
+local/log
+local/gse_list.tar.bz2
+
diff --git a/BUGS.REPORT b/BUGS.REPORT
new file mode 100644
index 0000000..c5580d5
--- /dev/null
+++ b/BUGS.REPORT
@@ -0,0 +1,3 @@
+# If you find a bug, please report it at freedomrfox@gmail.com
+# The mail should contain informations about the bug, for example, what you should expect, what you get instead and how to reproduce it.
+# \ No newline at end of file
diff --git a/LICENCE b/LICENCE
new file mode 100644
index 0000000..23d96f8
--- /dev/null
+++ b/LICENCE
@@ -0,0 +1,2 @@
+# This project was created over GSoC 2017 for Gentoo Fundation.
+# Everything created by this project is distributed under GPL-2 licence
diff --git a/README.md b/README.md
index 902e7d0..9f87394 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,14 @@
+## Before you go on
+Warrning: This project is currently experimental. It's on alpha stage, therefore it is recommended to be used only for testing, on enviroments that shield important data or system areas from the project's actions.
+
+[Project's Wiki](https://wiki.gentoo.org/wiki/User:Ulfox/GSoC-GSE)
+
## Abstract
A stateless environment based on Gentoo, which aims on making the
maintenance of multiple machines easier, improve stability and usability
on environments like Research or University computer labs.
-
## An introduction to the stateless concept
To begin with, a stateless system, as a concept, is an operating system which can boot and operate without requiring to hold a “memory” of its last state. However, even as a concept, this raises many questions, and could make sceptical even someone which has spend a little time reading about the operation of Linux. That is because, such a system would have many operational restrictions. First of all, the system would be “frozen in time”, meaning that every time the system boots, is like booting for the first time, because no inner “advancement” is happening, that is, no previous timeline of changes and configurations exists.
@@ -122,9 +126,9 @@ Create a minimal system (by bootsptrap??? script on /usr/portage/scripts)
Configure the system to be functional and bootable
Configure the system to function as readonly by
-configure /var and /etc
+ - mount /etc as tmpfs on bootup
-tmpfs filesystems for some directories
-using overlays
--using aufs?
Clean as many leftovers and unused files from the above steps
```
#### The system’s tree
diff --git a/TODO b/TODO
index 83e00c8..2aa77d2 100644
--- a/TODO
+++ b/TODO
@@ -1,51 +1,34 @@
# TODO
+Scripts
+ - Rewrite all scripts to POSIX insdead of bash
+ - Remove awk dependency
+ - Split the sinit_functions to multiple sinit_{categ}.sh
+ - Example: All the sinit_functions that are written for the chroot stage,
+ should be moved to a new script: sinit_chroot.sh
+
+End of Script's list
+
System Builder list
- Catalyst
-
- Sinit
- Include localbuild
- Include catalyst
- Include stage selection
- Include stageX check existence
- Include precompiled stage3
-
- Include script to manage catalyst stage1,2,3 builds
- Include script to create a portage custom stateless profile
- Include script to generate the stage1,2,3 spec files
- Include x86, amd64, arm,armx64 stage builds {For the project amd64 will be supported}
- Include the generated stage3 tarball to the rest of the process as it is.
-
- Create Server menu entry
- Create submenu entry for editing trusted hosts
- Create submenu entry to create a new user & group given by the user
- Add the dist.d and config.d directory to that group
- Generate ssh keys for server-client dist
- Add ssh pub.trusted.hosts to that user
- Create bind-mount or symlink of the above directories to the above user dir
- Include those keys to config.d/controller directory
- Include gpg
-
- Include kernel commandline editor
- Include ro autoconf
- Should:
- Create the /proc/mounts symlinks # If /etc is not selected by the user to be mounted as tmpfs from the controller
- Include sys cleaner
- Include version creator
- Include snapshot creator
- Include stage4 tarball create option
-
-End of System Builder list
+ - Create a Makefile
+ - Include ARM build option
+
+End of System's Builder list
Controller list {Initramfs}
-
- Include early netowrking script hooks
- Include option to fetch confs from server
- Include option to define newroot based on the above configurations
- Include HDD interface creator
- Include version checker
- Include rootfs label checker
- Include backupfs label checker
- Include configuration service for the rootfs
-
-End of Controller list
+ - Support a indirect server-client communication function (See, Server list)
+ - Rewrite the cinit_pre-mount.sh script for using only one mount action for the checks
+ - Exception to this would be the case of switch flag or of a setup flag.
+
+End of Controller's list
+
+System list
+ - Support controller requests on gse user:group, insdead of a standard scp method over ssh.
+ - By this, all gpg verifications and hash checks will be generated by the above user:group.
+ - Example: The scripts will create a secret key for the gse user and an ssh key,
+ therefore all controller requests will be handled by this groupd. This will
+ lead to a security boost, since other users will be shielded off from the
+ controller.
+
+End of System's List
+
diff --git a/bin/gse b/bin/gse
index 7e44e65..be300d9 100755
--- a/bin/gse
+++ b/bin/gse
@@ -9,17 +9,12 @@
# #
## ##
-if echo "${_flag_tty}" | grep -q 'sshd'; then
- LC_COLLATE="C"
- LC_ALL="en_US.UTF-8"
- LC_CTYPE="en_US.UTF-8"
-fi
-
# DEFINITION OF CWORKDIR AND IT'S SUBDIRECTORIES
export CWORKDIR="$(dirname ${PWD})"
export CCONFDIR="${CWORKDIR}/config.d"
export CDISTDIR="${CWORKDIR}/dist.d"
export CLOCALLG="${CWORKDIR}/local"
+export CSYSROOT="${CWORKDIR}/sysroot"
export CREL="$(grep ^NAME /etc/*release | awk -F '=' '{ print $2 }')"
# PATH DEFINITION FOR THE SCRIPTS WHICH WILL AID THE PROCESS
@@ -29,25 +24,6 @@ source "${CWORKDIR}/scripts/functions/sinit_functions" || { echo -e "\e[31mMissi
source "${CWORKDIR}/scripts/functions/catalyst_functions" || { echo -e "\e[31mMissing scripts\e[0m" && exit 1; }
source "${CWORKDIR}/etc/gentoo.conf" || { echo -e "\e[31mMissing gentoo.conf\e[0m" && exit 1; }
-# CHECK IF BASH IS THE DEFAULT {CURRENT} SHELL, ISSUE A WARNING OTHERIWSE
-shl_f() {
- SHL=$SHELL
- ISITBASH=$(echo "${SHL}" | awk -F "bin/" '{ print $2}')
- if [[ ${ISITBASH} != "bash" ]]; then
- echo "Seems like you are not using bash"
- echo "Keep in mind that all scripts from this project are written for bash interpretation"
- while true; do
- echo "Do you want to continue?: "
- read -rp "Input :: <= " S
- case ${S} in
- [Yy][eE][sS]|[yY]) clear; break;;
- [Nn][oO]|[nN]) echo "Exiting..."; exit;;
- * ) echo "Select Y/N";;
- esac
- done
- fi
-}
-
# ROOT CHECK FUNCTION, IS NEEDED FOR THE CATALYST AND CHROOT PROCESS
amiroot() {
if [[ "$1" != "0" ]]
@@ -141,21 +117,51 @@ while true; do
done
}
-if echo "$@" | grep -q '\--time-warp' && [[ "$#" != 1 ]]; then
- die "Error: Time Warp must be the only entry"
-fi
+if echo "$@" | grep -q '\--conf'; then
+ if [[ "$#" != 1 ]]; then
+ die "--conf argument has been detected"
+ fi
+
+ if [[ "$1" != *'='* || "${1#*=}" == '' ]]; then
+ die "No target file was given"
+ fi
-if echo "$@" | grep -q '\--edit' && [[ "$#" != 2 ]]; then
- die "Error: Edit must be the only entry"
-fi
+ if [[ ! -e "${1#*=}" ]]; then
+ die "No such file or directory"
+ fi
-lppar=()
-for i in "$@"; do
- lppar+=("$i")
-done
+ if [[ -d "${1#*=}" ]]; then
+ die "Target is a directory, aborting"
+ fi
-if [[ -z "$@" ]] || echo "$@" | grep -q '\-mm'; then
- mainlp_f "MM" "${lppar[@]}" && unset BACKTO && exit 0
+ if _ct_conf; then
+ _make_cimage
+ else
+ die "Exporting arguments from the configuration file has failed"
+ fi
+elif echo "$@" | grep -q '\--build-controller'; then
+ if _controller_args "${@:2}"; then
+ _make_cimage "${@:2}"
+ else
+ die "Given controller arguments could not be exported"
+ fi
else
- warp "$@"
+ if echo "$@" | grep -q '\--time-warp' && [[ "$#" != 1 ]]; then
+ die "Error: Time Warp must be the only entry"
+ fi
+
+ if echo "$@" | grep -q '\--edit' && [[ "$#" != 2 ]]; then
+ die "Error: Edit must be the only entry"
+ fi
+
+ lppar=()
+ for i in "$@"; do
+ lppar+=("$i")
+ done
+
+ if [[ -z "$@" ]] || echo "$@" | grep -q '\-mm'; then
+ mainlp_f "MM" "${lppar[@]}" && unset BACKTO && exit 0
+ else
+ warp "$@"
+ fi
fi \ No newline at end of file
diff --git a/bin/gse.py b/bin/gse.py
new file mode 100755
index 0000000..65fd4be
--- /dev/null
+++ b/bin/gse.py
@@ -0,0 +1,255 @@
+#!/usr/bin/env python3.4
+
+def _call_main(_gpyfunc_):
+ '''
+ Main function
+ This function:
+ Detects the project's directory and exports it with it's sub-dirs
+ Exports the given arguments and options
+ Exports the build sequence
+ Brings up the text/gui menu if given from the arguments
+ Last, enables the exported sequence (build process)
+ '''
+
+ # Simple die function and yellow, green, blue and purple color reports
+ from gpyfunctions.tools.gseout import die, e_report, g_report, b_report, p_report
+
+ # Check target and export args
+ def gse_args():
+ '''
+ Exports the sequence variable
+ Calls _export_args which defines and exports the final arguments based on the sequence
+ '''
+
+ if any('system' in _tmp1 for _tmp1 in argv[1:]):
+ sequence = "system"
+ elif any('controller' in _tmp1 for _tmp1 in argv[1:]):
+ sequence = "controller"
+ elif any('-h' in _tmp1 for _tmp1 in argv[1:]) or any('--help' in _tmp2 for _tmp2 in argv[1:]):
+ # For missing target arguments and given help option. Call general args.
+ sequence = "help"
+ elif any('-V' in _tmp1 for _tmp1 in argv[1:]) or any('--version' in _tmp2 for _tmp2 in argv[1:]):
+ # For missing target arguments and given version option. Print version.
+ sequence = "version"
+ else:
+ # Die for missing target and help opt
+ e_report("You must specify exactly one of: 'system' or 'controller' targets")
+ e_report("See gse -h or gse 5 for more info and gse 1 for options manpage")
+ die('')
+
+ # # Check if base and controller are issues at the same time. If yes, exit with error
+ # if sequence in 'system' or sequence in 'controller':
+ # if any('system' in item1 for item1 in argv[1:]) and ("controller" in item2 for item2 in argv[1:]):
+ # die("Error: System and Controller arguments can not be issued at the same time. " +
+ # "Only one operating at a given time can be supported.")
+
+ if sequence == "system":
+ # Export arguments for system sequence
+ from gpyfunctions.tools.librarium import _export_args
+
+ # Evaluate the arguments
+ p_report("System sequence enabled")
+ args = _export_args(sequence)
+
+ del _export_args
+
+ elif sequence == 'controller':
+ # Export arguments for controller sequence
+ from gpyfunctions.tools.librarium import _export_args
+
+ # Evaluate the arguments
+ p_report("Controller sequence enabled")
+ args = _export_args(sequence)
+
+ del _export_args
+
+ elif sequence == 'help':
+ # Print --help
+ from gpyfunctions.tools.librarium import _export_args
+ args = _export_args(sequence)
+ elif sequence == 'version':
+ # Print --version
+ from gpyfunctions.tools.librarium import _export_args
+ args = _export_args(sequence)
+
+
+ return args, sequence
+
+
+ # Import the returned arguments
+ args, sequence = gse_args()
+
+ del gse_args
+
+ # Import dist check function
+ from gpyfunctions.preliminary import _is_gentoo
+
+ # Check the output. In case of a fail, issue warning and abort
+ if _is_gentoo() == 0:
+ pass
+ else:
+ if args.dev == 0:
+ e_report("Dev is enabled: Ignoring dist check fail")
+ else:
+ e_report("The building process has been developed for Gentoo Linux.")
+ e_report("If you have a compatible system and you wish to run your scripts AT YOUR OWN RISK, ")
+ e_report("then edit " + CWORKDIR + "/bin/gse.py, and remove the die entry from if _is_gentoo statement.")
+ die("Aborting")
+
+ # Clear check function
+ del _is_gentoo
+
+ # Import super user check function
+ from gpyfunctions.preliminary import _is_su
+
+ # Pass if super user, issue warning if not and abort
+ if _is_su() == 0:
+ e_report("Super user privileges found. Proceeding.")
+ else:
+ if args.dev == True:
+ e_report("Dev is enabled: Ignoring su fail")
+ else:
+ die("No super user privileges found. Can not continue.")
+
+
+ del _is_su
+
+ if (args.mm or args.gmm):
+ # Check for mm && gmm conflict
+ if args.mm and args.gmm:
+ die("Error: Use one of [--mm/--gmm]")
+
+ # If args.mm, initiate text menu
+ if args.mm:
+ from gpyfunctions.menu.txmen.gsetxf import _call_menu
+ _ex_stat = _call_menu(CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR)
+
+ del _call_menu
+
+ # if args.gmm, initiate GUI menu
+ if args.gmm:
+ from gpyfunctions.menu.portal.gportal import _gmm
+ _ex_stat = _gmm()
+
+ del _gmm
+
+ return _ex_stat
+
+ elif sequence is "system" or sequence is "controller":
+ from gpyfunctions.tools.warp import warp
+ _ex_stat = warp(sequence, args, CWORKDIR, CCONFDIR, CLOCALLG)
+
+ del warp
+
+ return _ex_stat
+ else:
+ return 9
+
+# EO_call_main
+
+
+# Essential libraries
+from sys import argv, exit
+from os import path as ospath
+from sys import path as syspath
+
+# Append gpyfunctions from /usr/lib64/gse/scripts/
+if ospath.isdir('/usr/lib64/gse/scripts/gpyfunctions'):
+ if ospath.isfile('/usr/lib64/gse/scripts/gpyfunctions/__init__.py'):
+ syspath.append('/usr/lib64/gse/scripts')
+ _gpyfunc_ = "sys"
+
+# Append gpyfunctions from git chase
+elif ospath.isdir('../scripts/gpyfunctions'):
+ if ospath.isfile('../scripts/gpyfunctions/__init__.py'):
+ syspath.append("../scripts")
+ _gpyfunc_ = ".git"
+else:
+ print("Could not locate gpy modules path")
+ exit(1)
+
+def __gse_mod_check():
+ from sys import exit
+
+ try:
+ import gpyfunctions
+ del gpyfunctions
+
+ from gpyfunctions import preliminary
+ del preliminary
+
+ from gpyfunctions.tools import gseout
+ del gseout
+
+ from gpyfunctions.tools import librarium
+ del librarium
+
+ from gpyfunctions.tools import warp
+ del warp
+
+ from gpyfunctions.menu.txmen import gsub_men
+ del gsub_men
+
+ from gpyfunctions.menu.txmen import gsetxmen
+ del gsetxmen
+
+ from gpyfunctions.menu.txmen import gsetxf
+ del gsetxf
+
+ from gpyfunctions.menu.portal import gportal
+ del gportal
+
+ except ImportError:
+ raise
+ exit(1)
+
+ print("\033[1;35mAll gse modules are healthy\033[0;0m\n")
+
+
+# Check gpy modules. This function exists only in the experimental phase.
+__gse_mod_check()
+
+del __gse_mod_check, ospath, syspath
+
+# Import function for exporting CWORDKIR, ... PATHS
+from gpyfunctions.preliminary import _gse_path
+
+# Export the paths from _gse_path()
+CWORKDIR, CGSE, CFUNCTIONS, CCONFDIR, \
+CDISTDIR, CLOCALLG, CLOGLG, CSYSROOT, \
+CLOCALLIB = _gse_path(_gpyfunc_)
+
+del _gse_path
+
+# Main function
+if __name__ == "__main__":
+ try:
+ _ex_stat = _call_main(_gpyfunc_)
+
+ except KeyboardInterrupt:
+ from gpyfunctions.tools.gseout import e_report
+ e_report("\n\nKeyboard interrupt detected.\n")
+ exit(1)
+
+ except EOFError:
+ from gpyfunctions.tools.gseout import b_report
+ b_report("\n\nEOFError. Maybe CTRL-D?\nIf not, please report this bug!\n")
+ exit(1)
+
+ if _ex_stat == 0:
+ print("Success")
+ exit(0)
+
+ elif _ex_stat == 9:
+ print("No valid sequence")
+ exit(9)
+
+ else:
+ print("Fail")
+ exit(1)
+
+else:
+ print("Not Main")
+ exit(1)
+
+
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
diff --git a/config.d/system/devname.info b/config.d/system/devname.info
index a62dfcb..43a55db 100644
--- a/config.d/system/devname.info
+++ b/config.d/system/devname.info
@@ -6,9 +6,7 @@
# 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/sda1 2G btrfs
+SYSFS SDX /dev/sda2 20G ext4
+USERDATAFS SDX /dev/sda4 20G btrfs
+BACKUPFS SDX /dev/sda3 20G ext4
diff --git a/config.d/system/fstab b/config.d/system/fstab
index 600b339..9c6ed34 100644
--- a/config.d/system/fstab
+++ b/config.d/system/fstab
@@ -1,8 +1,8 @@
# /etc/fstab: static file system information.
#
-# noatime turns off atimes for increased performance (atimes normally aren't
-# needed); notail increases performance of ReiserFS (at the expense of storage
-# efficiency). It's safe to drop the noatime options if you want and to
+# noatime turns off atimes for increased performance (atimes normally aren't
+# needed); notail increases performance of ReiserFS (at the expense of storage
+# efficiency). It's safe to drop the noatime options if you want and to
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
@@ -28,22 +28,14 @@
#LABEL=swap none swap sw 0 0
#/dev/cdrom /mnt/cdrom auto noauto,ro 0 0
-# BOOT
-LABEL=BOOT /boot btrfs ro,noatime,subvol=/bootfs 0 0
+# BOOTFS
+LABEL=BOOTFS /boot btrfs ro,noatime,subvol=/bootfs 0 0
# SYSTEM
-LABEL=SYSTEM / btrfs ro,noatime,subvol=/sysfs 0 0
+LABEL=SYSTEM / ro,noatime 0 1
# USER-DATA
-LABEL=USERDATA /user-data btrfs defaults,noatime,subvol=/userdata 0 0
+LABEL=USERDATAFS /user-data btrfs defaults,noatime,subvol=/userdata 0 0
# HOME
/user-data/persistent/home /home/ none rw,bind 0 0
-
-# HOME
-tmpfs /var/tmp tmpfs nodev,nosuid,size=512M 0 0
-
-# HOME
-tmpfs /tmp tmpfs nodev,nosuid,size=512M 0 0
-
-# EOF \ No newline at end of file
diff --git a/config.d/system/inject_files b/config.d/system/inject_files
index 018613d..db42d3e 100644
--- a/config.d/system/inject_files
+++ b/config.d/system/inject_files
@@ -1,8 +1,8 @@
# 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
-
+# Syntax: {rsync/cp} {/path/at/local/file} {/path/to/file}
+# Example: rsync /usr/lib64/foo /usr/lib64/bar -> rsync -aAPhrv /usr/lib64/foo $DISTDIR/stage3/usr/lib64/bar
+#
diff --git a/docs/Examples-TBU b/docs/Examples-TBU
new file mode 100644
index 0000000..3170f4f
--- /dev/null
+++ b/docs/Examples-TBU
@@ -0,0 +1,5 @@
+# Examples TBU
+
+The examples will include extra subparts for the guides
+
+For example setting the arch, defining new distdir, setting controller's modules
diff --git a/docs/Guides-TBU b/docs/Guides-TBU
new file mode 100644
index 0000000..a6e07c3
--- /dev/null
+++ b/docs/Guides-TBU
@@ -0,0 +1,9 @@
+# Guides that will be added soon are:
+ - Guide for configuring system's builder areas
+ Example: - Configuring the minimum space requirement during the checks prior to initiating the builder
+ - Configuring the builder's warp time functions
+ - Configuring the builder's system configuration files
+ - Configuring the controller's configuration files
+ - Using the controller's cmdline arguments
+ - Using the --build-controller arguments
+
diff --git a/docs/documentations/ctgse.1 b/docs/documentations/ctgse.1
new file mode 100644
index 0000000..f3f0688
--- /dev/null
+++ b/docs/documentations/ctgse.1
@@ -0,0 +1,48 @@
+.TH "CTGSE" "1"
+.SH NAME
+CTGSE \- Controller's options for Gentoo Stateless Environment
+.SH SYNOPSIS
+.B gse
+--build-controller
+[\fBOPTIONS\fR]
+.SH "DESCRIPTION"
+.nf
+\fBController\fR lies inside the initramfs image. It's a set of scripts that are sourced on certain dracut
+hook points that aim to fetch,configure,recover the system. The configuration it self, while it is for
+general use, it is aimed mostly to support a stateless boot.
+.fi
+.SH OPTIONS
+.TP
+\fB\-\-force\fR
+.nf
+Forces the build to write over an existing controller image. Dracut itself requires a force option to
+write over pre-existing images.
+.fi
+.TP
+\fB\-\-cmdline\fR \fI\[=options]\fR
+This options enables dracut's cmdline opt. It is used here, since controller requires certain cmdline options to function. Additional cmdline
+are for supporting extra features.
+.fi
+.TP
+\fB\-\-hook\fR \fI[="Hook Points"]\fR \fI[="Hook Points Priority"]\fR
+Installs the script inside the initramfs to be sourced over a specific hook point.
+.fi
+.TP
+\fB\-\-net\fR \fI\[=net_script]\fR
+This requires as argument a script file. The file will be installed and sourced over the pre-mount hook point with a priority of 08.
+This option aims to provide a way of configuring complex network interfaces. Just write your net script and build it with this option
+inside the initramfs image.
+.fi
+.TP
+\fB\-\-modules\fR
+Install a custom file to handle modules under /etc/modprobe.d/ with name umod.conf
+.fi
+.TP
+\fB\-\-dracut_opt\fR
+This option lets you tunnel extra dracut options before building the image.
+.fi
+
+.SH "SEE ALSO"
+.nf
+man 5 gse
+
diff --git a/docs/guides/Guide-Builder b/docs/guides/Guide-Builder
new file mode 100644
index 0000000..1fc1c7f
--- /dev/null
+++ b/docs/guides/Guide-Builder
@@ -0,0 +1,16 @@
+# Guide for System Builder
+The system builder is consisted from a number of scripts that take atvantage of Gentoo features to build a system that is prepared for stateless boot and function.
+
+To read more about the project, read the gse.5 under docs directory
+
+To build a system, run:
+ - cd bin (it's under the projects git directory)
+ 1) ./gse --base=base_arg --option1 --option2 --option3
+ To read more about command line options from gse.1 under docs directory
+ 2) ./gse
+ This option, without any cmdline arguments will bring up the gse text menu for a guide
+
+Whatever the method of build is, at the end you will end up with a stage3 tarball under dist.d inside the project's directory.
+
+The above image will be used by the initramfs functions (controller) to fetch it, extract, configure it and boot it at the end.
+
diff --git a/docs/guides/Guide-Controller b/docs/guides/Guide-Controller
new file mode 100644
index 0000000..d618c36
--- /dev/null
+++ b/docs/guides/Guide-Controller
@@ -0,0 +1,60 @@
+# Guide for controller build
+
+The controller is a set of functions and scripts inside the initramfs image which is a product created by dracut package
+To read more about the controller's concep read man gse.5, while to read more about the controllers options read man ctfse.1
+Both of those man pages are under t he docs directory inside the project's git directory
+
+Note: Before you attempt to build the controller, your system (the one you use for the build) must support (include) the following packages:
+ - sys-apps/pciutils
+ - sys-fs/btrfs-progs
+ - sys-fs/cryptsetup
+ - app-crypt/gnupg
+ - sys-block/open-iscsi
+ - sys-block/nbd
+ - net-fs/nfs-utils
+ - net-nds/rpcbind
+ - dev-libs/openssl
+ - app-admin/syslog-ng
+ - sys-fs/device-mapper
+ - net-misc/dhcp
+ - sys-apps/iproute2
+
+The above packages are required for the dracut modules to function. A guid and detailed list about those can be found at: https://wiki.gentoo.org/wiki/Dracut
+
+
+To build the controller, run
+ - Create a kernel image with the modules and builtins you wish
+ - Build the controller:
+ - cd bin
+ - ./gse --build-controller --opt1 --opt2 --opt3 ...
+
+The created image will be saved inside dist.d directory. To use this image you need to create a bootable device.
+The device can be any physical medium that can be made bootable and support bootloader functions.
+
+The methos based on the drive's interface variate
+You can find a guide about configuring the devices for boot at the Gentoo wiki: https://wiki.gentoo.org/wiki/Handbook:AMD64/Full/Installation#Introduction_to_block_devices
+And you can find more informations about grub(if you choose grub as the bootloader) at: https://www.gnu.org/software/grub/manual/grub.html
+
+When you have a bootable medium there are only 4 steps left.
+ 1) Move the kernel & controller image to the bootable medium
+ 2) Update the grub.cfg entries to link on those images
+ 3) Pass the following parameters at grub.cfg kernels cmdline:
+ - root=LABEL=SYSFS
+ - rd.neednet=1
+ - ip=dhcp
+ - ctetc=1
+ Example: linux /vmlinuz-4.12.5-gentoo root=LABEL=SYSFS rd.neednet=1 ip=dhcp
+ 4) Create 3 partitions on the device/s you want with the following labels: SYSFS BACKUPFS BOOTFS
+ The BOOTFS label must be given to the bootable partition you created.
+ Example, if you wish to use /dev/sdb2 for system, /dev/sdc2 for backup partition
+ and your bootloader is on /dev/sda2 and all those partitions host ext4 filesystem, then:
+ e2label /dev/sda2 BOOTFS && mkfs.ext4 -L SYSFS /dev/sdb2 && mkfs.ext4 -L BACKUPFS /dev/sdc2
+
+ There is 1 more Label that can be created on anextra partition, but it is not essential for the boot process
+
+ This is: USERDATAFS. The USERDATAFS should be given at any drive that you wish to use for storage.
+ The USERDATAFS label provides an extra security layer from the controller, since all controller's actions are shielded on a device with such a label.
+
+When done, plug the bootable medium to a machine and boot it. If everything was done as should, the process should fetch an image, configure it and boot it.
+
+
diff --git a/etc/gentoo.conf b/etc/gentoo.conf
index 48c697c..532fe1c 100644
--- a/etc/gentoo.conf
+++ b/etc/gentoo.conf
@@ -1,23 +1,28 @@
#!/bin/bash
-### Gentoo related configuration file. TBU
+### Gentoo related configuration file.
#
-#
-#
-#
-#
-#
-###
-# Gentoo
-export GSEVER='alpha'
-export ARCH=amd64
-export DIST="http://distfiles.gentoo.org/releases/${ARCH}/autobuilds"
-export SIGNING_KEY="https://www.gentoo.org/downloads/signatures"
+GSEVER='alpha'
+ARCH=amd64
+DIST="http://distfiles.gentoo.org/releases/${ARCH}/autobuilds"
+SIGNING_KEY="https://www.gentoo.org/downloads/signatures"
+
+export GSEVER
+export ARCH
+export DIST
+export SIGNING_KEY
-# Catalyst
-export GSE_VER="GSE_${GSEVER}"
+git_par="https://github.com/ulfox/GSE.git"
+export git_par
+
+# Catalyst stage3 target name
+GSE_VER="GSE_${GSEVER}"
+export GSE_VER
GSE_BACKUP="/usr/share/gse/backup/gse_${GSEVER}.tar.bz2"
KEEP_VAR="/var/tmp/gse/"
+export GSE_BACKUP
+export KEEP_VAR
+
# Example: /var/tmp/gse/workdir-${_base_flag}_${_date}.tar.bz2" \ No newline at end of file
diff --git a/local/sinprog b/local/sinprog
index 631a7a8..d42fd0f 100644
--- a/local/sinprog
+++ b/local/sinprog
@@ -1,11 +1,13 @@
# Don't edit this file manually. It controls the flow of builder's process
# If you want to start again, please select START NEW when prompted during
# the PartA: Fundamentals
-PARTA=1
-CHECK=1
-RDEP=1
-SEED=1
-CATALYST=1
-PRECOMP=1
-EXTRACTION=1
-PARTB=1
+PARTA=0
+CHECK=0
+RDEP=0
+SEED=0
+CATALYST=0
+PRECOMP=0
+EXTRACTION=0
+PARTB=0
+CONTROLLER=0
+STAGE4=0
diff --git a/scripts/controller b/scripts/controller
deleted file mode 100755
index 95f140a..0000000
--- a/scripts/controller
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/bin/bash
-
-# directory structure
-echo "Creating initramfs directories"
-mkdir -p initramfs/mnt/{root,boot}
-
-# root filesystem & backup filesystem
-echo "Creating /mnt/bfs, mnt/rfs"
-mkdir -p initramfs/mnt/bfs
-mkdir -p initramfs/mnt/rfs
-mkdir -p initramfs/usr/lib64/locale
-
-# version will lie in data
-echo "Creating /var/data"
-mkdir -p initramfs/var/data/
-mkdir -p initramfs/var/data/
-mkdir -p initramfs/config.d
-mkdir -p initramfs/config.d/{controller,sources,system}
-mkdir -p initramfs/config.d/controller/{examples,server,services}
-mkdir -p initramfs/config.d/controller/services/default-runlevel
-mkdir -p initramfs/config.d/system/examples
-
-dracut --force --show-modules --printsize --nostrip --early-microcode --bzip2 \
---fscks "fsck.btrfs fsck.ext4 fsck.fat fsck.hfs fsck.hfsplus fsck.jfs fsck.minix fsck.reiser4 fsck.reiserfs fsck.vfat fsck.xfs" \
---filesystems "btrfs ext4 fat hfs hfsplus jfs minix reiser4 reiserfs vfat xfs" \
---install /bin/busybox \
---install /bin/tar \
---include initramfs / \
---add kernel-network-modules \
---install /lib64/libmount.so.1 initramfs/lib64/ \
---install /lib64/libblkid.so.1 initramfs/lib64/ \
---install /lib64/libc.so.6 initramfs/lib64/ \
---install /lib64/libuuid.so.1 initramfs/lib64/ \
---install /lib64/ld-linux-x86-64.so.2 initramfs/lib64/ \
---install /lib64/libext2fs.so.2 initramfs/lib64/libext2fs.so.2 \
---install /lib64/libcom_err.so.2 initramfs/lib64/libcom_err.so.2 \
---install /lib64/libe2p.so.2 initramfs/lib64/libe2p.so.2 \
---install /lib64/libpthread.so.0 initramfs/lib64/libpthread.so.0 \
---install /lib64/libdl.so.2 initramfs/lib64/libdl.so.2 \
---install /sbin/mkfs.btrfs initramfs/sbin/mkfs.btrfs \
---install /lib64/libz.so.1 initramfs/lib64/libz.so.1 \
---install /lib64/liblzo2.so.2 initramfs/usr/lib64/liblzo2.so.2 \
---install /usr/lib64/libfdisk.so.1.1.0 initramfs/usr/lib64/libfdisk.so.1 \
---install /lib64/libsmartcols.so.1 initramfs/lib64/ \
---install /lib64/libreadline.so.6 initramfs/lib64/libreadline.so.6 \
---install /lib64/libncurses.so.6 initramfs/lib64/libncurses.so.6 \
---install /usr/lib64/libncursesw.so initramfs/usr/lib64/libncursesw.so \
---install /usr/lib64/libncursesw.so initramfs/usr/lib64/libncursesw.so.5 \
---install /usr/lib64/libmagic.so.1 initramfs/usr/lib64/libmagic.so.1 \
---install /lib64/libncursesw.so.6 initramfs/lib64/libncursesw.so.6 \
---install /lib64/libnss_files.so.2 initramfs/lib64/libnss_files.so.2 \
---install /lib64/libattr.so.1 initramfs/lib64/libattr.so.1 \
---install /lib64/libacl.so.1 initramfs/lib64/libacl.so.1 \
---install /usr/lib64/libpopt.so.0 initramfs/usr/lib64/libpopt.so.0 \
---install /lib64/libnss_compat.so.2 initramfs/lib64/libnss_compat.so.2 \
---install /lib64/libnsl.so.1 initramfs/lib64/libnsl.so.1 \
---install /lib64/libnss_nis.so.2 initramfs/lib64/libnss_nis.so.2 \
---install /lib64/libnss_dns.so.2 initramfs/lib64/ \
---install /lib64/libnss_files.so.2 initramfs/lib64/ \
---install /lib64/libresolv.so.2 initramfs/lib64/ \
---install /lib64/ld-linux-x86-64.so.2 initramfs/lib64/ \
-/boot/"initramfs-${GSEVER}-4.9.16-gentoo"
-
-#--install /sbin/btrfs initramfs/sbin/btrfs \
-#--install /sbin/btrfs-convert initramfs/sbin/btrfs-convert \
-#--install /sbin/btrfs-debug-tree initramfs/sbin/btrfs-debug-tree \
-#--install /sbin/btrfs-find-root initramfs/sbin/btrfs-find-root \
-#--install /sbin/btrfs-image initramfs/sbin/btrfs-image \
-#--install /sbin/btrfs-map-logical initramfs/sbin/btrfs-map-logical \
-#--install /sbin/btrfs-show-super initramfs/sbin/btrfs-show-super \
-#--install /sbin/btrfs-zero-log initramfs/sbin/btrfs-zero-log \
-#--install /sbin/btrfsck initramfs/sbin/btrfsck \
-#--install /sbin/btrfstune initramfs/sbin/btrfstune \ \ No newline at end of file
diff --git a/scripts/functions/drv_interface b/scripts/functions/drv_interface
index d83e55a..b9e3ef5 100755
--- a/scripts/functions/drv_interface
+++ b/scripts/functions/drv_interface
@@ -26,7 +26,7 @@ fs_opt() {
esac
}
-FS_OPTS=(BOOT SYS USERDATA)
+FS_OPTS=(BOOTFS SYSFS USERDATAFS)
for i in "${FS_OPTS[@]}"; do
clear; fs_opt 1
@@ -46,14 +46,29 @@ for i in "${FS_OPTS[@]}"; do
esac
done
-[[ $BOOT == btrfs ]] && { FBOPTIONS='ro,noatime,subvol=/bootfs'; BDPPS='0 0'; } \
-|| { FBOPTIONS='ro,noatime'; BDPPS='0 2'; }
+if [[ "${BOOTFS}" == 'btrfs' ]]; then
+ FBOPTIONS='ro,noatime,subvol=/bootfs'
+ BDPPS='0 0'
+else
+ FBOPTIONS='ro,noatime'
+ BDPPS='0 2'
+fi
-[[ $SYS == btrfs ]] && { FSOPTIONS='ro,noatime,subvol=/sysfs'; SDPPS='0 0'; } \
-|| { FSOPTIONS="ro,noatime"; SDPPS="0 1"; }
+if [[ "${SYSFS}" == 'btrfs' ]]; then
+ FSOPTIONS='ro,noatime,subvol=/sysfs'
+ SDPPS='0 0'
+else
+ FSOPTIONS="ro,noatime"
+ SDPPS="0 1"
+fi
-[[ $USERDATA == btrfs ]] && { FUOPTIONS='defaults,noatime,subvol=/userdata'; UDPPS='0 0'; } \
-|| { FUOPTIONS='defaults,noatime'; UDPPS='0 1'; }
+if [[ "${USERDATAFS}" == 'btrfs' ]]; then
+ FUOPTIONS='defaults,noatime,subvol=/userdatafs'
+ UDPPS='0 0'
+else
+ FUOPTIONS='defaults,noatime'
+ UDPPS='0 1'
+fi
cat >"${CCONFDIR}/system/fstab" <<\EOF
# /etc/fstab: static file system information.
@@ -87,100 +102,185 @@ cat >"${CCONFDIR}/system/fstab" <<\EOF
#/dev/cdrom /mnt/cdrom auto noauto,ro 0 0
EOF
-# Boot
+# BOOT
echo >> "${CCONFDIR}/system/fstab"
-echo "# BOOT" >> "${CCONFDIR}/system/fstab"
-echo "LABEL=BOOT /boot ${BOOT} ${FBOPTIONS} ${BDPPS}" >>"${CCONFDIR}/system/fstab"
+echo "# BOOTFS" >> "${CCONFDIR}/system/fstab"
+echo "LABEL=BOOTFS /boot ${BOOTFS} ${FBOPTIONS} ${BDPPS}" >>"${CCONFDIR}/system/fstab"
-# System
+# SYSTEM
echo >> "${CCONFDIR}/system/fstab"
echo "# SYSTEM" >> "${CCONFDIR}/system/fstab"
echo "LABEL=SYSTEM / ${SYS} ${FSOPTIONS} ${SDPPS}" >>"${CCONFDIR}/system/fstab"
-# User-data
+# USERDATA
echo >> "${CCONFDIR}/system/fstab"
echo "# USER-DATA" >> "${CCONFDIR}/system/fstab"
-echo "LABEL=USERDATA /user-data ${USERDATA} ${FUOPTIONS} ${UDPPS}" >>"${CCONFDIR}/system/fstab"
+echo "LABEL=USERDATAFS /user-data ${USERDATAFS} ${FUOPTIONS} ${UDPPS}" >>"${CCONFDIR}/system/fstab"
-# Home
+# HOME
echo >> "${CCONFDIR}/system/fstab"
echo "# HOME" >> "${CCONFDIR}/system/fstab"
echo "/user-data/persistent/home /home/ none rw,bind 0 0" >>"${CCONFDIR}/system/fstab"
-# var/tmp
-echo >> "${CCONFDIR}/system/fstab"
-echo "# HOME" >> "${CCONFDIR}/system/fstab"
-echo "tmpfs /var/tmp tmpfs nodev,nosuid,size=512M 0 0" >>"${CCONFDIR}/system/fstab"
+_BOOTFSTYPE="${BOOTFS}"
+_SYSFSTYPE="${SYSFS}"
+_BACKUPFSTYPE="${SYSFS}"
+_USERDATAFSTYPE="${USERDATAFS}"
-# tmp
-echo >> "${CCONFDIR}/system/fstab"
-echo "# HOME" >> "${CCONFDIR}/system/fstab"
-echo "tmpfs /tmp tmpfs nodev,nosuid,size=512M 0 0" >>"${CCONFDIR}/system/fstab"
+unset BOOTFS
+unset SYSFS
+unset USERDATAFS
+unset FS_OPTSS
-echo "BOOT ${BOOT}" > "${CCONFDIR}/system/fstab.info"
-echo "SYS ${SYS}" >> "${CCONFDIR}/system/fstab.info"
-echo "USERDATA ${USERDATA}" >> "${CCONFDIR}/system/fstab.info"
+dev_fs=(BOOTFS SYSFS BACKUPFS USERDATAFS)
-unset BOOT
-unset SYS
-unset USERDATA
-unset FS_OPTSS
+_dev_opts() {
+ echo -e "################ \e[94m~~Device ID~~\e[39m #################"
+ echo "## ##"
+ echo -e "## [ \e[32mI\e[39m ] BY-ID ##"
+ echo -e "## [ \e[32mII\e[39m ] UUID ##"
+ echo -e "## [ \e[32mIII\e[39m] SDX ##"
+ echo "## ##"
+ echo "###################################################"
+}
+
+_dev_id() {
+ case "$1" in
+ BOOTFS)
+ _BOOTID="$2";;
+ SYSFS)
+ _SYSID="$2";;
+ BACKUPFS)
+ _BACKUPID="$2";;
+ USERDATAFS)
+ _USERDATAID="$2";;
+ esac
+}
+
+_dev_size() {
+ case "$1" in
+ BOOTFS)
+ _BOOTSIZE="$2";;
+ SYSFS)
+ _SYSSIZE="$2";;
+ BACKUPFS)
+ _BACKUPSIZE="$2";;
+ USERDATAFS)
+ _USERDATASIZE="$2";;
+ esac
+}
-FS_OPTS=(BOOT SYS USERDATA)
-echo "${FS_OPTS[@]}"
-
-while true; do
- for i in "${FS_OPTS[@]}"; do
- clear; echo "Please give the device name of $i"
- echo "Example: sda1"
- echo "This device, on creation, will inherit the $i label"
- read -rp "$i device name: /dev/" DEVNAME
- while true; do
- echo "Your input was: /dev/${DEVNAME}"
- read -rp "Are you sure? " SELCT
- case ${SELCT:-1} in
- [Yy][eE][sS]|[yY])
- eval "$i"="/dev/$DEVNAME"; break;;
- [nN][oO]|[nN])
- echo "Give a new value: "
- read -rp "$i device name: /dev/" DEVNAME;;
- *)
- clear; echo "Wrong option";;
- esac
- done
+_ask_dev_size() {
+ while true; do
+ echo "Please give the device $2 for $1"
+ echo "$3"
+ read -rp "Device $2: " _DSIZE
+ echo "Your input was:"
+ echo "${_DSIZE}"
+ read -rp "Are you sure? Y/N " _ANS1
+ case "${_ANS1}" in
+ [yY])
+ if [[ "${_DSIZE:0:1}" == [0-9] ]]; then
+ _dev_size "$1" "${_DSIZE}"
+ break
+ else
+ echo "Size must start with a number, followed by the magnitude of bytes it represents"
+ fi
+ ;;
+
+ [nN])
+ ;;
+
+ * )
+ clear
+ echo "Wrong Answer"
+ echo;;
+ esac
done
+ unset _ANS1
+ unset _DSIZE
+}
-if [[ -n "${BOOT}" && -n "${SYS}" && -n "${USERDATA}" ]]; then
-if [[ "${BOOT}" == "${SYS}" || "${BOOT}" == "${USERDATA}" ]]; then
-case "${BOOT}" in
- "${SYS}")
- echo "BOOT partition can not be the same with SYSTEM partition";;
- *)
- echo "BOOT partition can not be the same with USERDATA partition";;
-esac
-echo "Resetting the process"
-sleep 5
-else
-if [[ "${SYS}" == "${USERDATA}" ]]; then
- echo "SYSTEM partition can not be the same with USERDATA partition"
- echo "Resetting the process"
- sleep 5
-else
- break
-fi
-fi
-fi
+_ask_opts() {
+ while true; do
+ echo "Please give the device $2 for $1"
+ echo "$3"
+ read -rp "Device $2: " _DID
+ echo "Your input was:"
+ echo "${_DID}"
+ read -rp "Are you sure? Y/N " _ANS
+ case "${_ANS}" in
+ [yY])
+ _dev_id "$1" "${_DID}"
+ _ask_dev_size "$1" "size" "Number-G/M"
+ break;;
+
+ [nN])
+ ;;
+ * )
+ clear
+ echo "Wrong Answer"
+ echo;;
+ esac
+ done
+ unset _ANS
+ unset _DID
+}
+
+clear
+for i in "${dev_fs[@]}"; do
+ while true; do
+ _dev_opts
+ echo "Please select the device ID method for $i"
+ echo
+ echo
+ echo "Warning: SDX is not a safe method, because switch between sdaX and sdbX can happen."
+ echo "Note: UUID and SDX most probably will change when the controller creates the new driver's interface"
+ echo "The most safe way is to give device name by-id."
+ echo "This ensures that controller will always target the device you wish."
+ echo "This device, when configured, will inherit the $i label"
+ read -rp "Input :: <= " ANS
+ case "${ANS}" in
+ [iI]|1 )
+ eval "$i"="BY-ID"
+ _ask_opts "$i" "ID" "Example ID: ata-Corsair_Force_LE_SSD16388018000104170290:0"
+ break
+ ;;
+ [II]|[ii]|2 )
+ eval "$i"="UUID"
+ _ask_opts "$i" "UUID" "Example UUID: 85bcc799-d907-4db7-87fb-8773ca1b9a76"
+ break
+ ;;
+ [III]|[iii]|3 )
+ eval "$i"="SDX"
+ _ask_opts "$i" "SDX" "Example SDX: /dev/sda3"
+ break
+ ;;
+ * )
+ clear;;
+ esac
+ done
done
-echo "BOOT ${BOOT}" > "${CCONFDIR}/system/devname.info"
-echo "SYS ${SYS}" >> "${CCONFDIR}/system/devname.info"
-echo "USERDATA ${USERDATA}" >> "${CCONFDIR}/system/devname.info"
+cat >"${CCONFDIR}/system/devname.info" <<\EOF
+# 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} {DEVID} {IDTYPE} {size{M,G}/all} {FSTYPE}
+EOF
+
+echo "BOOTFS ${BOOTFS} ${_BOOTID} ${_BOOTSIZE} ${_BOOTFSTYPE}" >> "${CCONFDIR}/system/devname.info"
+echo "SYSFS ${SYSFS} ${_SYSID} ${_SYSSIZE} ${_SYSFSTYPE}" >> "${CCONFDIR}/system/devname.info"
+echo "USERDATAFS ${USERDATAFS} ${_USERDATAID} ${_USERDATASIZE} ${_USERDATAFSTYPE}" >> "${CCONFDIR}/system/devname.info"
+echo "BACKUPFS ${BACKUPFS} ${_BACKUPID} ${_BACKUPSIZE} ${_BACKUPFSTYPE}" >> "${CCONFDIR}/system/devname.info"
+
+echo "Please check the devname.info at ${CCONFDIR}/system and verify that the entries are those you wish to use"
+echo "Keep in mind that controller will use these entries during the intiramfs phase and configure the drives based on those options"
unset DEVNAME
-unset BOOT
-unset SYS
-unset USERDATA
+unset BOOTFS
+unset SYSFS
+unset USERDATAFS
unset FBOPTIONS
unset FSOPTIONS
unset FUOPTIONS
diff --git a/scripts/functions/local_rbuild b/scripts/functions/local_rbuild
deleted file mode 100755
index 7e44631..0000000
--- a/scripts/functions/local_rbuild
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-
-mkdir -p "${CDISTDIR}/workdir"
-MKCORES=$(( $(grep -c ^processor /proc/cpuinfo) + 1 ))
-source "${CCONFDIR}/system/coptions"
-mkdir -p "${CDISTDIR}/workdir/usr/portage"
-mkdir -p "${CDISTDIR}/workdir/etc/portage"
-mkdir -p "${CDISTDIR}/workdir/etc/portage/repos.conf"
-
-rsync -aAXPrh --exclude="-*" --include={"bin","make.conf.catalyst","postsync.d","repo.postsync.d","savedconfig","package.mask"} \
-"/etc/portage/" "${CDISTDIR}/workdir/etc/portage/" >/dev/null 2>&1
-rsync -aAXPrh "/usr/portage/profiles/" "${CDISTDIR}/workdir/usr/portage/profiles" >/dev/null 2>&1
-
-cp "${CCONFDIR}/system/portage/makeconf.backup" "${CDISTDIR}/workdir/etc/portage/make.conf"
-cp "/usr/share/portage/config/repos.conf" "${CDISTDIR}/workdir/etc/portage/repos.conf/gentoo.conf"
-
-ln -s "${CDISTDIR}/workdir/usr/portage/profiles/default/linux/amd64/13.0" "${CDISTDIR}/workdir/etc/portage/make.profile"
-
-declare -a ARRAYCBASE
-
-ARRAYCBASE=("sys-apps/baselayout" "app-arch/bzip2" "app-arch/gzip" "app-arch/tar" "app-arch/xz-utils" "app-shells/bash:0" \
-"net-misc/iputils" "net-misc/rsync" "net-misc/wget" "sys-apps/coreutils" "sys-apps/diffutils" "sys-apps/file" ">=sys-apps/findutils-4.4" \
-"sys-apps/gawk" "sys-apps/grep" "sys-apps/kbd" "sys-apps/less" "sys-apps/openrc" "sys-process/procps" "sys-process/psmisc" "sys-apps/sed" \
-"sys-apps/which" "sys-devel/binutils" "sys-devel/gcc" "sys-devel/gnuconfig" "sys-devel/make" ">=sys-devel/patch-2.7" "sys-fs/e2fsprogs" \
-"sys-fs/e2fsprogs" "virtual/dev-manager" "virtual/editor" "virtual/libc" "virtual/man" "virtual/modutils" "virtual/os-headers" "virtual/package-manager" \
-"virtual/pager" "virtual/pager" "virtual/service-manager" "virtual/service-manager" "virtual/shadow" "virtual/ssh")
-echo -e "\e[34mBasic system\e[0m"
-
-for i in "${ARRAYCBASE[@]}"; do
-PORTAGE_CONFIGROOT="${CDISTDIR}/workdir" MAKEOPTS="-j${MKCORES}" FEATURES="${FEATURES} ${CHFEATURES}" \
-CFLAGS="-O2 -pipe" ROOT="${CDISTDIR}/workdir" emerge -q --deep --update "$i"
-done \
-&& echo -e "\e[35mUpdating @system set\e[0m" \
-&& MAKEOPTS="-j${MKCORES}" FEATURES="${FEATURES} ${CHFEATURES}" CFLAGS="-O2 -pipe" ROOT="${CDISTDIR}/workdir" emerge -q --deep --update @system \
-&& print_inf 1 || { print_inf 2 ** exit 1; }
-unset ARRAYCBASE \ No newline at end of file
diff --git a/scripts/functions/makeconf_ed b/scripts/functions/makeconf_ed
index 66b8747..64979a0 100755
--- a/scripts/functions/makeconf_ed
+++ b/scripts/functions/makeconf_ed
@@ -279,14 +279,14 @@ optim
cpuflagsx86
if [[ ! -e "${CCONFDIR}/system/portage/usef" ]]; then
-cat >"${CCONFDIR}/system/portage/usef" <<\EOF
-USE=""
+ cat >"${CCONFDIR}/system/portage/usef" <<\EOF
+ USE=""
EOF
fi
if [[ ! -e "${CCONFDIR}/system/portage/emdefopt" ]]; then
-cat >"${CCONFDIR}/system/portage/emdefopt" <<\EOF
-EMERGE_DEFAULT_OPTS=""
+ cat >"${CCONFDIR}/system/portage/emdefopt" <<\EOF
+ EMERGE_DEFAULT_OPTS=""
EOF
fi
diff --git a/scripts/functions/men_opt b/scripts/functions/men_opt
index 73ed839..5d3bcf3 100755
--- a/scripts/functions/men_opt
+++ b/scripts/functions/men_opt
@@ -181,8 +181,9 @@
fi
echo "## ##"
echo -e "## [ \e[32mI\e[39m ] \e[33mRenew ALL\e[0m ##"
- echo -e "## [ \e[32mII\e[39m ] \e[33mVersion Check\e[0m ##"
- echo -e "## [ \e[32mIII\e[39m] \e[33mReturn back\e[0m ##"
+ echo -e "## [ \e[32mII\e[39m ] \e[33mRenew Scripts\e[0m ##"
+ echo -e "## [ \e[32mIII\e[39m] \e[33mVersion Check\e[0m ##"
+ echo -e "## [ \e[32mIV\e[39m ] \e[33mReturn back\e[0m ##"
echo "## ##"
echo -e "## [ \e[32mT\e[39m ] \e[32mTerminal\e[0m ##"
echo "## ##"
diff --git a/scripts/functions/renew b/scripts/functions/renew
index 7d2a978..6fda20d 100755
--- a/scripts/functions/renew
+++ b/scripts/functions/renew
@@ -1,70 +1,140 @@
#!/bin/bash
-echo "Creating GSE md5sums"
-#(cd "${CWORKDIR}"; find . -path ./dist.d -prune -o -type f -exec md5sum "{}" + | sed 's_\./_STFLAG\/_g' > gse_list.md5sum
-#cat gse_list.md5sum | sed -e 's_STFLAG_'"$PWD"'_g' >gse_list.md5sums; cd - >/dev/null)
+_not_used() {
+ echo "Creating GSE md5sums"
+ #(cd "${CWORKDIR}"; find . -path ./dist.d -prune -o -type f -exec md5sum "{}" + | sed 's_\./_STFLAG\/_g' > gse_list.md5sum
+ #cat gse_list.md5sum | sed -e 's_STFLAG_'"$PWD"'_g' >gse_list.md5sums; cd - >/dev/null)
-CWORKDIR="$(dirname "$PWD")"
+ CWORKDIR="$(dirname "$PWD")"
-# FUNCTION FOR GENERATING THE MD5SUM FILE AND THE BACKUP TARBALL
-_gse_backup() {
-(cd "${CWORKDIR}"
-[[ -z "${CWORKDIR}" ]] && exit
+ # FUNCTION FOR GENERATING THE MD5SUM FILE AND THE BACKUP TARBALL
+ _gse_backup() {
+ (cd "${CWORKDIR}"
+ [[ -z "${CWORKDIR}" ]] && exit
-# USED TO MAKE THE LISTS
-if [[ ! -e "${CWORKDIR}/tmp/.gse_list0" ]]; then
- rm -rf "tmp/.gselist"
- mkdir -p "tmp/.gselist"
+ # USED TO MAKE THE LISTS
+ if [[ ! -e "${CWORKDIR}/tmp/.gse_list0" ]]; then
+ rm -rf "tmp/.gselist"
+ mkdir -p "tmp/.gselist"
- # CREATES THE BASE FOR THE LIST ENTRIES
- cp -r "${CWORKDIR}"/{bin,config.d,docs,scripts,local,README.md,TODO,etc} "tmp/.gselist"
+ # CREATES THE BASE FOR THE LIST ENTRIES
+ cp -r "${CWORKDIR}"/{bin,config.d,docs,scripts,local,README.md,TODO,etc} "tmp/.gselist"
- # GENERATE LIST0, THIS ONE IS USED FOR THE ARCHIVES CREATION
- find "tmp/.gselist" -type f | sed 's_tmp/.gselist_STFLAG_g'> "${CWORKDIR}/tmp/.gse_list0"
+ # GENERATE LIST0, THIS ONE IS USED FOR THE ARCHIVES CREATION
+ find "tmp/.gselist" -type f | sed 's_tmp/.gselist_STFLAG_g'> "${CWORKDIR}/tmp/.gse_list0"
- # GENERATE LIST, THIS ONE IS USED FOR THE MD5SUM LIST
- find "tmp/.gselist" -type f | sed -e 's_tmp/.gselist_'"$PWD"'_g' > "${CWORKDIR}/tmp/.gse_list"
-
- # PURGE GSELIST
- rm -rf "tmp/.gselist"
-fi
-
-# READ LIST0 AND CREATE THE ARCHIVES
-while read -r i; do
- rsync -aAXRrq "$i" "tmp/TheArchives"
-done < <(cat "${CWORKDIR}/tmp/.gse_list0" | sed -e 's_STFLAG/__g')
-
-# CREATE THE BACKUP
-tar cvzf "tmp/gse_list.tar.bz2" "tmp/TheArchives/" >/dev/null
-
-# GENERATE THE MD5SUMS CHECKLIST
-while read -r i; do
- md5sum "$i" >> "${CWORKDIR}/tmp/.gse_list.md5sum0"
-done < <(cat "${CWORKDIR}/tmp/.gse_list" | sed -e 's_\./_\/_g')
-
-# INJECT STFLAG STRING TO EXTRACT IT LATER
-cat "${CWORKDIR}/tmp/.gse_list.md5sum0" | sed -e 's_'"${CWORKDIR}"'_STFLAG_g' > "${CWORKDIR}/tmp/.gse_list.md5sum"
-
-# DELETE MD5SUM0
-rm "${CWORKDIR}/tmp/.gse_list.md5sum0"
-cd "${CWORKDIR}/tmp"
-rm -rf "TheArchives")
+ # GENERATE LIST, THIS ONE IS USED FOR THE MD5SUM LIST
+ find "tmp/.gselist" -type f | sed -e 's_tmp/.gselist_'"$PWD"'_g' > "${CWORKDIR}/tmp/.gse_list"
+
+ # PURGE GSELIST
+ rm -rf "tmp/.gselist"
+ fi
+
+ # READ LIST0 AND CREATE THE ARCHIVES
+ while read -r i; do
+ rsync -aAXRrq "$i" "tmp/TheArchives"
+ done < <(cat "${CWORKDIR}/tmp/.gse_list0" | sed -e 's_STFLAG/__g')
+
+ # CREATE THE BACKUP
+ tar cvzf "tmp/gse_list.tar.bz2" "tmp/TheArchives/" >/dev/null
+
+ # GENERATE THE MD5SUMS CHECKLIST
+ while read -r i; do
+ md5sum "$i" >> "${CWORKDIR}/tmp/.gse_list.md5sum0"
+ done < <(cat "${CWORKDIR}/tmp/.gse_list" | sed -e 's_\./_\/_g')
+
+ # INJECT STFLAG STRING TO EXTRACT IT LATER
+ cat "${CWORKDIR}/tmp/.gse_list.md5sum0" | sed -e 's_'"${CWORKDIR}"'_STFLAG_g' > "${CWORKDIR}/tmp/.gse_list.md5sum"
+
+ # DELETE MD5SUM0
+ rm "${CWORKDIR}/tmp/.gse_list.md5sum0"
+ cd "${CWORKDIR}/tmp"
+ rm -rf "TheArchives")
+ }
+
+ # DO NOT UNCOMMENT THIS. THE FUNCTIONS WILL BREAK, OR WILL WONT REPLACE THE SCRIPTS THEY WAY IT SHOULD BE.
+ if [[ ! -e "${CWORKDIR}/tmp/.gse_list.md5sum" ]]; then
+ : #_gse_backup
+ fi
+
+ # THIS IS THE REPLACE RENEW PART
+ (rm -f "${CWORKDIR}/tmp/.MODLIST" >/dev/null
+ md5sum -c < <(cat "${CWORKDIR}/tmp/.gse_list.md5sum" | sed -e 's_STFLAG_'"${CWORKDIR}"'_g') \
+ | grep FAILED | awk -F ':' '{ print $1 }' | sed -e 's_'"${CWORKDIR}/"'__g' >> "${CWORKDIR}/tmp/.MODLIST"
+
+ cd "${CWORKDIR}"
+ tar xvf "tmp/gse_list.tar.bz2" -C "tmp/" >/dev/null 2>&1)
+
+ while read -r i; do
+ #rsync -aAXrhv
+ echo "${CWORKDIR}/tmp/tmp/TheArchives/$i" "${CWORKDIR}/$i"
+ done < <(cat "${CWORKDIR}/tmp/.MODLIST")
}
-# DO NOT UNCOMMENT THIS. THE FUNCTIONS WILL BREAK, OR WILL WONT REPLACE THE SCRIPTS THEY WAY IT SHOULD BE.
-if [[ ! -e "${CWORKDIR}/tmp/.gse_list.md5sum" ]]; then
- : #_gse_backup
-fi
-
-# THIS IS THE REPLACE RENEW PART
-(rm -f "${CWORKDIR}/tmp/.MODLIST" >/dev/null
-md5sum -c < <(cat "${CWORKDIR}/tmp/.gse_list.md5sum" | sed -e 's_STFLAG_'"${CWORKDIR}"'_g') \
-| grep FAILED | awk -F ':' '{ print $1 }' | sed -e 's_'"${CWORKDIR}/"'__g' >> "${CWORKDIR}/tmp/.MODLIST"
-
+_tmp_location="(echo $PWD)"
cd "${CWORKDIR}"
-tar xvf "tmp/gse_list.tar.bz2" -C "tmp/" >/dev/null 2>&1)
-while read -r i; do
- #rsync -aAXrhv
- echo "${CWORKDIR}/tmp/tmp/TheArchives/$i" "${CWORKDIR}/$i"
-done < <(cat "${CWORKDIR}/tmp/.MODLIST")
+case "$1" in
+ hard)
+ echo "Resetting whole project"
+ echo "Creating backup for config.d to ${CWORKDIR}/local/tmp/gse"
+
+ if [[ ! -e "${CWORKDIR}/local/tmp/gse" ]]; then
+ mkdir -p "${CWORKDIR}/local/tmp/gse"
+ fi
+
+ if tar cvzf "${CWORKDIR}/local/tmp/gse/old.config.d.tar.bz2" "${CWORKDIR}/config.d"; then
+ echo "Backup created"
+ else
+ echo "Failed to create backup"
+ while true; do
+ echo "Continue?"
+ read -rp "Answer Y/N: " ANS
+ case "${ANS}" in
+ [yY])
+ break;;
+ [nN])
+ return 1;;
+ *)
+ clear;;
+ esac
+ done
+ fi
+
+ echo "Hard resetting..."
+ if git reset --hard; then
+ cd "${_tmp_location}"
+ return 0
+ else
+ cd "${_tmp_location}"
+ return 1
+ fi
+ ;;
+
+ soft)
+ echo "Initiating soft reset"
+ echo "Only the project's scripts will be altered"
+
+ _gse_scripts=("scripts/sinit" "scripts/controller" "scripts/functions/men_opt" "scripts/functions/catalyst_functions" \
+ "scripts/functions/drv_interface" "scripts/functions/init_stage3_seq" "scripts/functions/local_rbuild" \
+ "scripts/functions/local_rbuild" "scripts/functions/makeconf_ed" "scripts/functions/renew" "scripts/functions/sinit_functions" \
+ "scripts/chroot_scripts/cfunctions" "scripts/chroot_scripts/chinit.conf" "scripts/chroot_scripts/chroot_init" \
+ "scripts/chroot_scripts/chsinprog" "bin/gse" "etc/gentoo.conf" "local/loc_req" "local/nogloc_req" "local/sinprog")
+
+ for i in "${_gse_scripts[@]}"; do
+ _err_check=0
+ if git checkout -- "${CWORKDIR}/${i}"; then
+ echo "$i has been set to default"
+ else
+ echo "Failed setting $i to default"
+ _err_check=1
+ fi
+ done
+
+ if [[ "${_err_check}" == 0 ]]; then
+ return 0
+ else
+ return 1
+ fi
+ ;;
+esac
diff --git a/scripts/functions/sinit_functions b/scripts/functions/sinit_functions
index eddfa2f..7e96985 100755
--- a/scripts/functions/sinit_functions
+++ b/scripts/functions/sinit_functions
@@ -644,7 +644,7 @@ _lcreq() {
if _am_i_root_sub "$UID"; then
echo -e "[\e[32m*\e[0m] Root privileges found"
emerge -aq eix && echo -e "[\e[33m*\e[0m] \e[35mUpdating database\e[0m"
- eval eix-sync -a "${_flag_silence}"
+ eval eix-sync -a >/dev/null
else
echo -e "[\e[31m*\e[0m] Could not get root privileges"
die "Please resolve this issue and start again"
@@ -655,7 +655,7 @@ _lcreq() {
for i in "${lreq[@]}"; do
sleep 0.1
- if eval eix --installed "$i" "${_flag_silence}"; then
+ if eval eix --installed "$i" >/dev/null; then
echo -e "[\e[32m*\e[0m] Searching for \e[32m$i\e[0m"
else
echo -e "[\e[31m*\e[0m] Searching for $i"
@@ -860,6 +860,353 @@ _edit_configs() {
esac
}
+# THE CONTROLLER MENU
+controller_f() {
+ clear; amiroot "$UID"; echo "You selected: build the controller image"; echo
+ _make_cimage "$@"
+ _PARENT=0
+}
+
+_make_cimage() {
+ _KVER_="$(uname -r)"
+
+ _dracut_f() {
+ echo "$@"
+ dracut "$@" --show-modules \
+ --fscks "fsck.btrfs fsck.ext4 fsck.fat fsck.vfat fsck.ext2 fsck.ext3 fsck.ext4dev" \
+ --add "btrfs crypt bash controller network kernel-network-modules" \
+ --add "img-lib fs-lib base shutdown usrmount syslog" \
+ --add "udev-rules terminfo ssh-client rootfs-block" \
+ --add "resume nfs nbd iscsi crypt-gpg crypt-loop" \
+ --add "kernel-modules dm bash convertfs drm"
+ }
+
+ if echo "${_flag_dopt_entries}" | grep -q "\--kver"; then
+ _e_report_back "Please do not use --kver, since the scripts are written to read specific image files"
+ _e_report_back "To use your image, please rename the file to initramfs-${GSEVER}-${_KVER_} and place it under ${CDISTDIR}"
+ die
+ fi
+
+ _check_dr_mods() {
+ if ! [[ $(command -v eix) ]]; then
+ echo -e "[\e[33m*\e[0m] \e[35mPlease install eix to proceed!\e[0m"
+ if _am_i_root_sub "$UID"; then
+ echo -e "[\e[32m*\e[0m] Root privileges found"
+ emerge -aq eix && echo -e "[\e[33m*\e[0m] \e[35mUpdating database\e[0m"
+ eval eix-sync -a >/dev/null
+ else
+ echo -e "[\e[31m*\e[0m] Could not get root privileges"
+ die "Please resolve this issue and start again"
+ fi
+ fi
+
+ _ct_dr_req=("sys-apps/pciutils" "sys-fs/btrfs-progs" "sys-fs/cryptsetup" "app-crypt/gnupg" \
+ "sys-block/open-iscsi" "sys-block/nbd" "net-fs/nfs-utils" "net-nds/rpcbind" "sys-kernel/dracut" \
+ "dev-libs/openssl" "app-admin/syslog-ng" "sys-fs/device-mapper" "net-misc/dhcp" "sys-apps/iproute2")
+
+ for i in "${_ct_dr_req[@]}"; do
+ sleep 0.1
+ if eval eix --installed "$i" >/dev/null; then
+ echo -e "[\e[32m*\e[0m] Searching for \e[32m$i\e[0m"
+ else
+ echo -e "[\e[31m*\e[0m] Searching for $i"
+ echo -e "[\e[33m*\e[0m] Attempting to resolve the missing dependency"
+ if _am_i_root $UID && echo -e "[\e[32m*\e[0m] Root privileges found"; then
+ emerge -aq "$i"
+ else
+ echo -e "[\e[31m*\e[0m] Could not get root privileges"
+ die "Please resolve this issue and start again"
+ fi
+ fi
+ done
+ }
+
+ _e_report_back "Checking for controller dependencies"
+
+ _check_dr_mods
+
+ if [[ ! -e "/usr/lib64/dracut/modules.d/01controller" ]]; then
+ mkdir -p "/usr/lib64/dracut/modules.d/01controller"
+ else
+ rm -rf "/usr/lib64/dracut/modules.d/01controller"
+ mkdir -p "/usr/lib64/dracut/modules.d/01controller"
+ fi
+
+ cp -r "${CCONFDIR}/controller/modules"/* "/usr/lib64/dracut/modules.d/01controller/"
+
+ if [[ "${_flag_keep}" == 0 && "${_flag_darg_force}" == '-f' ]]; then
+ if [[ -e "${CDISTDIR}/initramfs-${GSEVER}-${_KVER_}" ]]; then
+ cp "${CDISTDIR}/initramfs-${GSEVER}-${_KVER_}" "${CDISTDIR}/initramfs-${GSEVER}-${_KVER_}.old"
+ fi
+ fi
+
+ eval _dracut_f "${_flag_darg_force}" "${CDISTDIR}/initramfs-${GSEVER}-${_KVER_}" \
+ "${_flag_dinclude_entries}" "${_flag_dcmdl_entries}" "${_flag_dopt_entries}"
+
+ echo "${GSEVER}" > "${CDISTDIR}/latest_stage"
+ unset _KVER_
+}
+
+_ct_conf() {
+ _ct_arg_ar=("include" "cmdline" "hook" "net" "module-probe" \
+ "module-insmod" "module-auto" "module-blacklist" "dracut_opt")
+
+ if [[ -n "$(grep "force" "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d')" ]]; then
+ _controller_args '--force'
+ fi
+
+ for i in "${_ct_arg_ar[@]}"; do
+ if [[ -n "$(grep "$i" "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F '=' '{ print $2 }')" ]]; then
+ _TMPR099="$(grep "$i" "${CTCONFDIR}/confdir/cdevname.info" | sed '/^#/ d' | sed '/^\s*$/d' | awk -F '=' '{ print $2 }')"
+ _controller_args "--$i=${_TMPR099}"
+ fi
+ done
+
+ unset _TMPR099
+ unset _ct_arg_ar
+}
+
+
+# FLAGS AND ARGUMENTS
+_controller_args() {
+ [[ -z "$*" ]] && return 0
+ while [[ -n "$*" ]]; do
+ case "$1" in
+ --force )
+ _flag_darg_force='-f'
+ export _flag_darg_force
+ _e_report_back "Dracut force flag has been enabled"
+ ;;
+
+ --include* )
+ if [[ "$1" == *'='* ]]; then
+ _flag_dinclude=0
+ export _flag_dinclude
+ _e_report_back "Dracut include flag has been enabled with arguments: "
+ _flag_dinclude_entries="--include ${1#*=}"
+ export _flag_dinclude_entries
+ _o_report_back "${1#*=}"
+ else
+ _e_report_back "Missing arguments from --include, argument will be ignored"
+ fi
+ ;;
+
+ --cmdline* )
+ if [[ "$1" == *'='* ]]; then
+ _flag_dcmdl=0
+ export _flag_dcmdl
+ _e_report_back "Dracut command line flag has been enabled with arguments: "
+ _flag_dcmdl_entries="--kernel-cmdline ${1#*=}"
+ export _flag_dcmdl_entries
+ _o_report_back "${1#*=}"
+ fi
+ ;;
+
+ --hook* )
+ if [[ "$1" == *'='* ]]; then
+ if [[ "${1#*=}" == '' ]]; then
+ die "No arguments after hook were given"
+ else
+ if [[ "$2" != '-hp'* ]]; then
+ die "No hook points {-hp=...} were given"
+ else
+ if [[ "$2" != *'='* || "${2#*=}" == '' ]]; then
+ die "No hook point argument where given"
+ fi
+ fi
+
+ if [[ "$3" != '-prio'* ]]; then
+ die "Priority -prio could not be detected"
+ else
+ if [[ "$2" != *'='* || "${2#*=}" == '' ]]; then
+ die "No -prio entries were given"
+ fi
+ fi
+
+ _flag_dhook=0
+ export _flag_dhook
+
+ _flag_dhook_entries="${1#*=}"
+ export _flag_dhook_entries
+
+ _flag_dhook_hp="${2#*=}"
+ export _flag_dhook_hp
+
+ _flag_dhook_prio="${3#*=}"
+ export _flag_dhook_prio
+
+ _dhook_ar=()
+ _dhook_hp=()
+ _dhook_prio=()
+
+ for i in ${_flag_dhook_entries}; do
+ if [[ ! -e "$i" ]]; then
+ if [[ -e "/$i" ]]; then
+ if [[ "${i:0:1}" != "/" ]]; then
+ if ! file "$i" | grep -q "script"; then
+ die "The given file does not appear to be a script"
+ else
+ _dhook_ar+=("/${i}")
+ fi
+ fi
+ else
+ die "No such file or directory: $i"
+ fi
+ else
+ if ! file "$i" | grep -q "script"; then
+ die "The given file does not appear to be a script"
+ else
+ _dhook_ar+=("${i}")
+ fi
+ fi
+ done
+
+ _case_hp() {
+ case "$1" in
+ 'cmdline'|'pre-udev'|'pre-trigger'|'initqueue'|'initqueue/settled'|'initqueue/timeout'|'initqueue/finished'\
+ |'pre-mount'|'mount'|'pre-pivot'|'cleanup')
+ return 0;;
+ *)
+ return 1;;
+ esac
+ }
+
+ for i in ${_flag_dhook_hp}; do
+ if _case_hp "$i"; then
+ _dhook_hp+=("${i}")
+ else
+ die "There is no such a hook-point: $i"
+ fi
+ done
+
+ for i in ${_flag_dhook_prio}; do
+ if [[ "$i" =~ ^[0-9]+$ ]]; then
+ _dhook_prio+=("${i}")
+ else
+ die "Priority $i is not a integer"
+ fi
+ done
+
+ _hook_final=()
+ _var_count="$((${#_dhook_ar[@]} - 1))"
+
+ mkdir -p "${CCONFDIR}/controller/modules/uscripts"
+ rm -f "${CCONFDIR}/controller/modules/uscripts/insthook"
+ for i in $(eval echo "{0..${_var_count}}"); do
+ if [[ -n "${_dhook_hp[$i]}" && -n "${_dhook_prio[$i]}" ]]; then
+ _scriptname="$(basename ${_dhook_ar[$i]})"
+ echo "${_dhook_hp[$i]} ${_dhook_prio[$i]} ${_scriptname}" >> "${CCONFDIR}/controller/modules/uscripts/insthook"
+ cp "${_dhook_ar[$i]}" "${CCONFDIR}/controller/modules/uscripts"
+ else
+ if [[ -z "${_dhook_hp[$i]}" ]]; then
+ die "Hook point for ${_dhook_ar[$i]} is missing"
+ elif [[ -z "${_dhook_prio[$i]}" ]]; then
+ die "Priority for ${_dhook_ar[$i]} is missing"
+ fi
+ fi
+ done
+
+ _e_report_back "Dracut hook flag has been enabled with hooks: "
+ _o_report_back "$(cat "${CCONFDIR}/controller/modules/uscripts/insthook")"
+
+ shift 2
+ unset _var_count
+ unset _dhook_ar
+ unset _dhook_prio
+ unset _dhook_hp
+ unset _flag_dhook_hp
+ unset _flag_dhook_prio
+ unset _flag_dhook_entries
+ fi
+ elif [[ "$1" != *'='* ]]; then
+ die "No arguments after hook were given"
+ fi
+ ;;
+
+ --net* )
+ if [[ "$1" != *'='* || "${1#*=}" == '' ]]; then
+ die "No arguments after net were given"
+ else
+ _flag_drnet="${1#*=}"
+
+ if [[ ! -e "${_flag_drnet}" ]]; then
+ if [[ -e "/${_flag_drnet}" ]]; then
+ if [[ "${_flag_drnet:0:1}" != "/" ]]; then
+ _flag_drnet="/${_flag_drnet}"
+ if ! file "${_flag_drnet}" | grep -q "script"; then
+ die "The given file does not appear to be a script"
+ else
+ _e_report_back "Net script ${_flag_drnet} has been set"
+ _flag_dracut_net=0
+ export _flag_drnet
+ export _flag_dracut_net
+ fi
+ fi
+ else
+ echo "No such file or directory: ${_flag_drnet}"
+ die
+ fi
+ else
+ if ! file "${_flag_drnet}" | grep -q "script"; then
+ die "The given file does not appear to be a script"
+ else
+ _flag_drnet="${_flag_drnet}"
+ _e_report_back "Net script ${_flag_drnet} has been set"
+ export _flag_drnet
+ _flag_dracut_net=0
+ export _flag_dracut_net
+ fi
+ fi
+ fi
+
+ mkdir -p "${CCONFDIR}/controller/modules/unet"
+ rm -f "${CCONFDIR}/controller/modules/unet/unet.conf"
+ _unetscript="$(basename "${_flag_drnet}")"
+ echo "${_unetscript}" >> "${CCONFDIR}/controller/modules/unet/unet.conf"
+ cp "${_flag_drnet}" "${CCONFDIR}/controller/modules/unet/"
+ ;;
+
+ --modules* )
+ if [[ "$1" != *'='* || "${1#*=}" == '' ]]; then
+ die "No arguments after --modules were given"
+ else
+ _flag_mods=0
+ if [[ -e "${1:10}" ]]; then
+ _e_report_back "Cusom module file: ${1:10}, located"
+ _mod_ar="${1:10}"
+ else
+ die "${1:10} does not exist"
+ fi
+ fi
+
+ mkdir -p "${CCONFDIR}/controller/modules/umod"
+ rm -f "${CCONFDIR}/controller/modules/umod/umod.conf"
+ _umodscript="$(basename "${_mod_ar}")"
+ echo "${_umodscript}" >> "${CCONFDIR}/controller/modules/umod/umod.conf"
+ cp "${_mod_ar}" "${CCONFDIR}/controller/modules/umod/"
+ ;;
+
+ --dracut_opt* )
+ if [[ "$1" != *'='* || "${1#*=}" == '' ]]; then
+ die "No arguments after --dracut_opt were given"
+ else
+ _flag_dopt=0
+ export _flag_dopt
+ _e_report_back "Dracut options flag has been set, with arguments: "
+ _flag_dopt_entries="${1#*=}"
+ export _flag_dopt_entries
+ _o_report_back "${_flag_dopt_entries}"
+ fi
+ ;;
+
+ * )
+ die "Unknown $1 operation"
+ ;;
+ esac
+ shift
+ done
+}
+
# FLAGS AND ARGUMENTS
librarium() {
_e_report_back "===================================================================================================================="
@@ -871,7 +1218,6 @@ librarium() {
_flag_keep=''
_flag_initrd=''
_flag_minimal=''
- _flag_controller=''
_flag_enforce=''
_flag_lawful=''
_flag_verbose=''
@@ -1042,31 +1388,7 @@ librarium() {
esac
exit;;
-
- --build-controller*|-bc* )
- if [[ "$1" != *'='* ]]; then
- die "Missing argument for controller's path"
- else
- _flag_controller_path="${1#*=}"
-
- if [[ ${_flag_controller_path:0:1} != "/" ]]; then
- _flag_controller_path="/${_flag_controller_path}"
- fi
-
- if [[ "${_flag_controller_path}" == '/' ]]; then
- die "Root is not allowed to be set as moddir path. Aborting..."
- else
- if [[ -d "${_flag_controller_path}" ]]; then
- _flag_controller=0
- export _flag_controller
- export _flag_controller_path
- _e_report_back "Controller flag enabled"
- else
- die "Error: moddir's target is not a directory"
- fi
- fi
- fi
- ;;
+
--auto* )
if [[ "$1" != *'='* ]]; then
die "Missing = for --auto"
@@ -1374,7 +1696,9 @@ witch_hunt() {
_tmp_catdir=$(df -h "$CATDIR" | awk -F ' ' '{ print $4 }' | tail -n +2)
_tmp_distdir=$(df -h "$CDISTDIR" | awk -F ' ' '{ print $4 }' | tail -n +2)
- _free_space "${_tmp_catdir}" "50" "Catalysts storedir" "catalyst will use for a stage3 tarball will be around 50G"
+ if [[ "${_flag_base}" == 'catalyst' ]]; then
+ _free_space "${_tmp_catdir}" "50" "Catalysts storedir" "catalyst will use for a stage3 tarball will be around 50G"
+ fi
_free_space "${_tmp_distdir}" "15" "Dist.d dir" "dist.d will use is at least 15G"
unset CATDIR
unset _tmp_distdir
@@ -1774,7 +2098,9 @@ _clean_target() {
_archive_() {
_o_report_back "Preparing to archive the system"
_e_report_back "Unbinding..."
-
+ mkdir -p "$1/var/lib/gse"
+ echo "${GSEVER}" > "$1/var/lib/gse/version"
+
_unmount "${_flag_base}"
TARGETSTAMP="$(grep 'version_stamp' "${CCONFDIR}/system/catalyst/stage3.spec" \
@@ -1806,7 +2132,15 @@ _archive_() {
while true; do
if ! ls "${CDISTDIR}/stage3-amd64-${GVEX}.tar.bz2" >/dev/null 2>&1; then
(cd "$1"
- _o_report_back "Creating the stage4 tarball"
+
+ if [[ ! -e "/var/lib/gse" ]]; then
+ mkdir -p "var/lib/gse"
+ fi
+
+ _o_report_back "Importing version to new system"
+ echo "${GVEX}" > "var/lib/gse/version"
+
+ _o_report_back "Creating the stage3 tarball"
if [[ "${_flag_base}" == 'catalyst' ]]; then
eval tar -cjpP --ignore-failed-read "${EXCLUDE}" -f "${CDISTDIR}/stage3-amd64-${TARGETSTAMP}-${GVEX}.tar.bz2" . "${_flag_silence}"
elif [[ "${_flag_base}" == 'precomp' ]]; then
@@ -1817,6 +2151,10 @@ _archive_() {
echo -e "\e[34mWith version extension: ${GVEX}\e[0m"; } \
|| die "Failed"
break
+
+ (cd "${CDISTDIR}"
+ md5sum stage3-amd64-prc-${GVEX}.tar.bz2 > stage3-amd64-prc-${GVEX}.tar.bz2.md5sum
+ )
else
GVEX="${GSEVER}.${SUBBUILD}"
((++SUBBUILD))
@@ -2017,13 +2355,32 @@ _prepare_chroot() {
echo -e "[\e[32m*\e[0m] Copying requested files"
if [[ -n $(cat ${CCONFDIR}/system/inject_files | sed '/^#/ d' | sed '/^\s*$/d') ]]; then
+ INJFLERR=()
while read -r INJFL; do
- f1="$(echo $INJFL | awk -F ' ' '{ print $1 }')"
- f2="${BWORKDIR}/(echo $INJFL | awk -F ' ' '{ print $2 }')"
- echo "Copying $f1 to $f2"
- eval rsync -aAXPhrv "$f1" "$f2" "${_flag_silence}" \
- && pass || { mapfile -t INJFLERR < <($INJFL | awk -F ' ' '{ print $1 }'); }
+ _case_var="$(echo ${INJFL} | awk -F ' ' '{print $1}')"
+ f1="$(echo "${INJFL}" | awk -F ' ' '{ print $2 }')"
+ f2="${BWORKDIR}/$(echo "${INJFL}" | awk -F ' ' '{ print $3 }')"
+
+ case "${_case_var}" in
+ rsync)
+ echo "Syncing ${f1} to ${f2}"
+ if eval rsync -aAPhrv "${f1}" "${f2}" "${_flag_silence}"; then
+ pass
+ else
+ INJFLERR+=("${f1}")
+ fi;;
+ cp)
+ if eval cp -r "${f1}" "${f2}" "${_flag_silence}"; then
+ pass
+ else
+ INJFLERR+=("${f1}")
+ fi
+ ;;
+ *)
+ echo "Unknown ${_case_var} entry"
+ esac
+
done < <(cat "${CCONFDIR}/system/inject_files" | sed '/^#/ d' | sed '/^\s*$/d')
unset INJFL
@@ -2034,26 +2391,30 @@ _prepare_chroot() {
echo "You can list the failed files again, continue, request terminal or exit"
echo "Please choose: LIST/CONTINUE/TERMINAL/EXIT"
read -rp "Input :: <= " INJFLANS
- case "$INJFLANS" in
+ case "${INJFLANS}" in
LIST)
- clear; echo "${INJFLERR[@]}";;
+ clear; echo "${INJFLERR[@]}"
+ ;;
CONTINUE)
while true; do
echo "Are you sure? Y/N "
- read -p "Input :: <= " YN
- case $YN in
+ read -rp "Input :: <= " YN
+ case "${YN}" in
[yY])
echo "Proceeding"
INJFLESC=0
- break;;
+ break
+ ;;
[nN])
INJFLESC=1
;;
esac
- done;;
+ done
+ ;;
TERMINAL)
_subshell
- INJFLESC=0;;
+ INJFLESC=0
+ ;;
EXIT)
while true; do
echo "Are you sure? Y/N "
@@ -2061,12 +2422,15 @@ _prepare_chroot() {
case $YN in
[yY])
echo "Aborting..."
- exit 0;;
+ exit 0
+ ;;
[nN])
INJFLESC=1
- break;;
+ break
+ ;;
esac
- done;;
+ done
+ ;;
esac
[[ "$INJFLESC" == 0 ]] && break
done
@@ -2202,17 +2566,27 @@ main_f() {
gse_t() {
read -rp "Input :: <= " SELCT
- case ${SELCT:-6} in
+ case ${SELCT} in
I|i|1 )
- # RENEW ALL MODIFIED ITEMS
- # THE LIST WILL INCLUDE ONLY THE MAIN SCRIPTS IN THE END
- #./"${CWORKDIR}/functions/renew" &
+ if renew "hard"; then
+ echo "All scripts and configuration files have been hard resetted"
+ else
+ echo "Failed resetting the project. Please report this issue"
+ fi
exit 0;;
II|ii|2 )
+ if renew "soft"; then
+ echo "Project's scripts have been resetted"
+ else
+ echo "The process could not roll back all project's scripts"
+ echo "Please report this issue"
+ fi
+ exit 0;;
+ III|iii|3 )
# VERSION CHECK
source "${CWORKDIR}/functions/gse_sources"
_STAY=0;;
- III|iii|3 )
+ V|v|5 )
_PARENT=0;;
[tT] )
subterm_f "${lppar[@]}"
@@ -2363,6 +2737,7 @@ config_f() {
read -rp "Input :: <= " SELCT
case ${SELCT} in
I|i|1 )
+ # MARKED FOR REMOVAL
# GUIDED FSTAB EDITOR
drv_interface
_STAY=0;;
@@ -2448,13 +2823,6 @@ selectdef_f() {
esac
}
-# THE CONTROLLER MENU
-controller_f() {
- clear; amiroot "$UID"; echo "You selected: build the controller image"; echo
- # source "${CWORKDIR}/scripts/controller"
- _PARENT=0
-}
-
# DOCUMENTATIONS MENU
doc_f(){
read -rp "Choose a document you wish to read: " SELCT
diff --git a/scripts/gpyfunctions/__init__.py b/scripts/gpyfunctions/__init__.py
new file mode 100644
index 0000000..125607d
--- /dev/null
+++ b/scripts/gpyfunctions/__init__.py
@@ -0,0 +1,2 @@
+#__all__=[]
+#__path__=["menu", "tools", "system", "controller"]
diff --git a/scripts/gpyfunctions/controller/__init__.py b/scripts/gpyfunctions/controller/__init__.py
new file mode 100644
index 0000000..28180ed
--- /dev/null
+++ b/scripts/gpyfunctions/controller/__init__.py
@@ -0,0 +1,2 @@
+#__all__=[]
+#__path__=[]
diff --git a/scripts/gpyfunctions/gseclass.py b/scripts/gpyfunctions/gseclass.py
new file mode 100755
index 0000000..4a86d4a
--- /dev/null
+++ b/scripts/gpyfunctions/gseclass.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3.6
+
+# Images
+class image(object):
+ # Image products, with type
+
+ # Attributes:
+ # name: A string with the image's name
+ # date: A string with the image's creation date
+
+ def __init__(img, name):
+ # Return the image's name
+ img.name = name
+
+ def set_date(img, date):
+ # Return the image's date of creation
+ img.date = date
+
diff --git a/scripts/gpyfunctions/menu/__init__.py b/scripts/gpyfunctions/menu/__init__.py
new file mode 100644
index 0000000..7f01649
--- /dev/null
+++ b/scripts/gpyfunctions/menu/__init__.py
@@ -0,0 +1,3 @@
+#__all__=[]
+#__path__=[]
+
diff --git a/scripts/gpyfunctions/menu/portal/__init__.py b/scripts/gpyfunctions/menu/portal/__init__.py
new file mode 100644
index 0000000..2464e76
--- /dev/null
+++ b/scripts/gpyfunctions/menu/portal/__init__.py
@@ -0,0 +1,2 @@
+__all__=["gportal"]
+#__path__=[]
diff --git a/scripts/gpyfunctions/menu/portal/gportal.py b/scripts/gpyfunctions/menu/portal/gportal.py
new file mode 100755
index 0000000..dfa98cf
--- /dev/null
+++ b/scripts/gpyfunctions/menu/portal/gportal.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python3.4
+
+def _gmm():
+ '''
+ Definition of the project's GUI menu
+ '''
+
+ import tkinter
+ from tkinter import Tk, Toplevel, Button, Menu
+
+ def donothing():
+ filewin = Toplevel(portal)
+ button = Button(filewin, text="Do nothing button")
+ button.pack()
+
+ # Define portal as Tk
+ portal = Tk()
+
+ # Title
+ portal.title("Portal Menu")
+ # Window Geometry
+ portal.geometry("1200x1024")
+
+ # Define portal menu as portmen
+ portmen = Menu(portal)
+
+ def _portfile():
+ '''
+ Definition of "file tab"
+ '''
+
+ # Create file tab
+ portfile = Menu(portmen, tearoff=0)
+ # Label the tab as File
+ portmen.add_cascade(label="File", menu=portfile)
+
+ # File's sub-menu
+ portfile.add_command(label="New", command=donothing)
+ portfile.add_command(label="Open", command=donothing)
+ portfile.add_command(label="Save", command=donothing)
+ portfile.add_command(label="Save as...", command=donothing)
+ portfile.add_command(label="Close", command=donothing)
+ portfile.add_separator()
+ portfile.add_command(label="Exit", command=portal.quit)
+
+ return portfile
+
+
+ def _portedit():
+ '''
+ Definition of edit tab
+ '''
+
+ # Create edit tab
+ portedit = Menu(portmen, tearoff=0)
+ # Label the tab as edit
+ portmen.add_cascade(label="Edit", menu=portedit)
+
+ portedit.add_command(label="Undo", command=donothing)
+ portedit.add_separator()
+
+ portedit.add_command(label="Cut", command=donothing)
+ portedit.add_command(label="Copy", command=donothing)
+ portedit.add_command(label="Paste", command=donothing)
+ portedit.add_command(label="Delete", command=donothing)
+ portedit.add_command(label="Select All", command=donothing)
+
+ return portedit
+
+
+ def _porthelp():
+ '''
+ Definition of help tab
+ '''
+
+ porthelp = Menu(portmen, tearoff=0)
+ portmen.add_cascade(label="Help", menu=porthelp)
+
+ porthelp.add_command(label="Help Index", command=donothing)
+ porthelp.add_command(label="About...", command=donothing)
+
+ return porthelp
+
+ portfile = _portfile()
+ portedit = _portedit()
+ porthelp = _porthelp()
+
+ portal.config(menu=portmen)
+ portal.mainloop()
+
+ return 0
+
+
diff --git a/scripts/gpyfunctions/menu/txmen/__init__.py b/scripts/gpyfunctions/menu/txmen/__init__.py
new file mode 100644
index 0000000..28180ed
--- /dev/null
+++ b/scripts/gpyfunctions/menu/txmen/__init__.py
@@ -0,0 +1,2 @@
+#__all__=[]
+#__path__=[]
diff --git a/scripts/gpyfunctions/menu/txmen/gsetxf.py b/scripts/gpyfunctions/menu/txmen/gsetxf.py
new file mode 100755
index 0000000..cbcd7b8
--- /dev/null
+++ b/scripts/gpyfunctions/menu/txmen/gsetxf.py
@@ -0,0 +1,143 @@
+#!/usr/bin/env python3.4
+
+# Initiates the text main menu loop
+def _call_menu(CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR):
+ '''
+ Imports important porject's directories and initiates the text's menu loop
+ '''
+
+ from gpyfunctions.menu.txmen.gsub_men import _call_sub
+ from gpyfunctions.menu.txmen.gsetxmen import _men_opt
+ from gpyfunctions.preliminary import _clear
+
+ # _init_sub initiated the requested sub_menu and its functions
+ def _init_sub(men, bpar, spar, ccal, *args):
+ '''
+ _init_sub initiated the requested sub_menu and its functions
+ men: menu entry to be printed
+ bpar: which is the parent of men
+ spar: relates men with case (if conditions) about the current men
+ ccal: the function that will be executed after the menu has been printed
+ *args: additional arguments for the functions that are called.
+ '''
+
+ try:
+ del _sub_call
+
+ c = [_PARENT, _CHILD, _STAY]
+
+ for i in c[:]:
+ del i
+
+ except NameError:
+ pass
+
+ while True:
+ # Clear screen then print the related menu
+ _clear()
+ _men_opt(men)
+
+ try:
+ # Call the related function
+ _sub_call = _call_sub(ccal, *args)
+
+ except KeyboardInterrupt:
+ from gpyfunctions.tools.gseout import e_report
+ e_report("\n\nKeyboard interrupt detected.\n")
+ exit(1)
+
+ except EOFError:
+ from gpyfunctions.tools.gseout import b_report
+ b_report("\n\nEOFError. Maybe CTRL-D?\nIf not, please report this bug!\n")
+ exit(1)
+
+ # Check if the menu entry was a valid one
+ if _sub_call is "err":
+ pass
+
+ else:
+ # For valid entry, set _PARENT, _CHILD OR _STAY
+ # _PARR requests the parent menu of the sub-menu
+ # _CHILD calls for a child = {NAME} sub-menu
+ # _STAY requests the same menu
+ for k, v in _sub_call.items():
+ if k is "_PARENT" and v == 0:
+ BACKTO = bpar
+
+ elif k is "_CHILD":
+ BACKTO = v
+
+ elif k is "_STAY" and v == 0:
+ BACKTO = spar
+
+ return BACKTO
+
+ # Main menu loop function
+ def _main_loop(minit, CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR):
+ '''
+ Main menu loop function
+ This function simply reads the BACKTO from the _init_sub function and executes
+ the return menu.
+ See _init_sub above for the given variables.
+ '''
+
+ BACKTO = minit
+
+ while True:
+ # Main menu
+ if BACKTO is "MM":
+ BACKTO = _init_sub("1", "Q", "MM", "main_f", CWORKDIR)
+
+ elif BACKTO is "DOC":
+ # Documentation menu
+ BACKTO = _init_sub("2", "MM", "DOC", "doc_f", CWORKDIR)
+
+ elif BACKTO is "AB":
+ # About menu
+ BACKTO = _init_sub("3", "MM", "AB", "about_f", CWORKDIR)
+
+ elif BACKTO is "PORT_M":
+ # Portage menu
+ BACKTO = _init_sub("7", "SM", "PORT_M", "portage_men_f", CCONFDIR)
+
+ elif BACKTO is "CATA_M":
+ # Catalyst menu
+ BACKTO = _init_sub("10", "SM", "CATA_M", "catalyst_f", CCONFDIR)
+
+ elif BACKTO is "SM":
+ # Builder menu
+ BACKTO = _init_sub("6", "BSM", "SM", "bs_f", CWORKDIR)
+
+ elif BACKTO is "BSM":
+ # System menu
+ BACKTO = _init_sub("5", "MM", "BSM", "bs_menu_f", CWORKDIR)
+
+ elif BACKTO is "CO_F":
+ # Controller menu
+ BACKTO = _init_sub("8", "BSM", "CO_F", "config_f", CCONFDIR)
+
+ elif BACKTO is "SELDEF":
+ # Select defaults menu
+ BACKTO = _init_sub("9", "BSM", "SELDEF", "selectdef_f", CWORKDIR)
+
+ elif BACKTO is "GSET":
+ # GSE tools menu
+ BACKTO = _init_sub("11", "MM", "GSET", "gse_t", CWORKDIR)
+
+ elif BACKTO is "CONTR":
+ # Controller
+ BACKTO = _init_sub('', "MM", "CONTR", "controller_f", CWORKDIR)
+
+ elif BACKTO is "Q":
+ break
+ else:
+ _parameter_error()
+
+
+ _main_loop("MM", CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR)
+
+ return 0
+
+
+
+
diff --git a/scripts/gpyfunctions/menu/txmen/gsetxmen.py b/scripts/gpyfunctions/menu/txmen/gsetxmen.py
new file mode 100755
index 0000000..bf42637
--- /dev/null
+++ b/scripts/gpyfunctions/menu/txmen/gsetxmen.py
@@ -0,0 +1,151 @@
+#!/usr/bin/env python3.4
+
+def _men_opt(_men_call):
+ '''
+ GSE text menu output.
+ For a given function that is called, this function prints the entries / options of that function.
+ '''
+
+ from gpyfunctions.tools.gseout import report_colors
+
+ if _men_call is '1':
+ print("##################### " + report_colors.CYAN + "~~Main Menu~~" + report_colors.RESET + " ######################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " System Menu " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Build the controller image " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III " + report_colors.RESET + "]" + report_colors.YELLOW + " GSE Tools " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Documentations " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " About the project " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "VI " + report_colors.RESET + "]" + report_colors.YELLOW + " I shouldn't be here, please let me leave! " + report_colors.RESET + "##")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##")
+ print("############################################################")
+
+ elif _men_call is "2":
+ print("################### " + report_colors.CYAN + "~~Documentations~~" + report_colors.RESET + " ####################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Introduction to GSE Directory " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " The Controller " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III " + report_colors.RESET + "]" + report_colors.YELLOW + " The Config.d Directory " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " The script's Directory " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.GREEN + " Main Menu " + report_colors.RESET + "##")
+ print("## ##")
+ print("##############################################################")
+
+ elif _men_call is "3":
+ print("####################### " + report_colors.CYAN + "~~About~~" + report_colors.RESET + " ########################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " About the project " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Linux, Gentoo and the birth of an Idea " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III " + report_colors.RESET + "]" + report_colors.YELLOW + " Open Source To The End and Beyond " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.GREEN + " Main Menu " + report_colors.RESET + "##")
+ print("## ##")
+ print("#############################################################")
+
+ elif _men_call is "5":
+ print("#################### " + report_colors.CYAN + "~~System Menu~~" + report_colors.RESET + " ###################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Built a System " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure built variables " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Select default system for distribution " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Create a stage4 tarball " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##")
+ print("## ##")
+ print("###########################################################")
+
+ elif _men_call is "6":
+ print("################### " + report_colors.CYAN + "~~Builder~~" + report_colors.RESET + " ##################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Portage " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Catalyst " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Precompiled " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##")
+ print("## ##")
+ print("#####################################################")
+
+ elif _men_call is "7":
+ print("###################### " + report_colors.CYAN + "~~Portage~~ " + report_colors.RESET + " #####################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Guided/Automatic make.conf " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Manually edit make.conf (Reset) " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Features & ccashe " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit distcc " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit packages.use " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "VI " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##")
+ print("## ##")
+ print("###########################################################")
+
+ elif _men_call is "8":
+ print("################## " + report_colors.CYAN + "~~Configurations~~" + report_colors.RESET + " ##################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure fstab/drives " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Manually edit fstab " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III " + report_colors.RESET + "]" + report_colors.YELLOW + " Manually edit drive names " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit Hostname " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit /etc/conf.d/net " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "VI " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit Locales " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "VII " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit Consolefont " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "VIII " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit sshd " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IX " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit sshkey " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "X " + report_colors.RESET + "]" + report_colors.YELLOW + " Symlink, bind, overlay and tmpfs " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "XI " + report_colors.RESET + "]" + report_colors.YELLOW + " Add Scripts " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "XII " + report_colors.RESET + "]" + report_colors.YELLOW + " Install Packages " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "XIII " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit Default Grub " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "XIV " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit runlevels*** " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "XV " + report_colors.RESET + "]" + report_colors.YELLOW + " Inject files " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "XVI " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + " T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##")
+ print("## ##")
+ print("###########################################################")
+
+ elif _men_call is "9":
+ print("################## " + report_colors.CYAN + "~~Select Default~~" + report_colors.RESET + " ##################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " List systems " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit default " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##")
+ print("## ##")
+ print("###########################################################")
+
+ elif _men_call is "10":
+ print("################### " + report_colors.CYAN + "~~Catalyst~~" + report_colors.RESET + " #################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure catalyst.conf " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure catalystrc " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Configure stage1 " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure stage2 " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure stage3 " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "VI " + report_colors.RESET + "]" + report_colors.PURPLE + " Initiate Build " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "VII" + report_colors.RESET + "]" + report_colors.YELLOW + " Return " + report_colors.RESET + "##")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##")
+ print("## ##")
+ print("#####################################################")
+
+ elif _men_call is "11":
+ print("#################### " + report_colors.CYAN + "~~GSE Tools~~" + report_colors.RESET + " #####################")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Renew ALL " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Renew Scripts " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Version Check " + report_colors.RESET + "##")
+ print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##")
+ print("## ##")
+ print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##")
+ print("## ##")
+ print("###########################################################")
+
+
+ del _men_call, report_colors
+
+
+
+
diff --git a/scripts/gpyfunctions/menu/txmen/gsub_men.py b/scripts/gpyfunctions/menu/txmen/gsub_men.py
new file mode 100755
index 0000000..31583f5
--- /dev/null
+++ b/scripts/gpyfunctions/menu/txmen/gsub_men.py
@@ -0,0 +1,574 @@
+#!/usr/bin/env python3.4
+
+# Define all menu functions
+def _call_sub(ccal, *args):
+ '''
+ Here are defined all the function that consist the project's text menu
+ For example:
+ main_f() is the top layer function from the text menu
+ gse_t() appears as an entry on main_f options and calls a new sub-menu
+ '''
+
+ from gpyfunctions.tools.gseout import report_colors, e_report, b_report
+ from sys import exit
+ from gpyfunctions.preliminary import portalin
+
+ def main_f(*args):
+ '''
+ Main menu function
+ '''
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ # Call builder submenu
+ _sub_call = {"_CHILD": "BSM"}
+
+ elif SELCT in ['II', 'ii', '2']:
+ # Call controller submenu
+ _sub_call = {"_CHILD": "CONTR"}
+
+ elif SELCT in ['III', 'iii', '3']:
+ # GSE renew submenu
+ _sub_call = {"_CHILD": "GSET"}
+
+ elif SELCT in ['IV', 'iv', '4']:
+ # Call documentation submenu
+ _sub_call = {"_CHILD": "DOC"}
+
+ elif SELCT in ['V', 'v', '5']:
+ # Call about submenu
+ _sub_call = {"_CHILD": "AB"}
+
+ elif SELCT in ['VI', 'vi', '6', 'q', 'Q']:
+ # Go to parrent
+ e_report("Exiting...")
+ _sub_call = {"_PARENT": 0}
+
+ elif SELCT in ['t', 'T']:
+ # Call shell function
+ from gpyfunctions.preliminary import _shell
+ _shell()
+
+ _sub_call = {"_STAY": 0}
+
+ del _shell
+
+ else:
+ _sub_call="err"
+
+ del SELCT
+
+ return _sub_call
+
+
+ def gse_t(*args):
+ '''
+ GSE tools menu function
+ '''
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ pass
+ exit(0)
+
+ elif SELCT in ['II', 'ii', '2']:
+ pass
+ exit(0)
+
+ elif SELCT in ['III', 'iii', '3']:
+ # Version check
+ # import version check function here
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['IV', 'iv', '4']:
+ # Go to parrent
+ _sub_call = {"_PARENT": 0}
+
+ elif SELCT in ['t', 'T']:
+ # Call shell function
+ from gpyfunctions.preliminary import _shell
+ _shell()
+
+ _sub_call = {"_STAY": 0}
+
+ del _shell
+
+ else:
+ _sub_call="err"
+
+ del SELCT
+
+ return _sub_call
+
+ def bs_menu_f(*args):
+ '''
+ Systen's menu function
+ '''
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ # Call build system submenu
+ _sub_call = {"_CHILD": "SM"}
+
+ elif SELCT in ['II', 'ii', '2']:
+ # Call configuration submenu
+ _sub_call = {"_CHILD": "CO_F"}
+
+ elif SELCT in ['III', 'iii', '3']:
+ # CALL SELECT DEFAULT SYSTEM SUBMENU
+ _sub_call = {"_CHILD": "SELDEF"}
+
+ elif SELCT in ['IV', 'iv', '4']:
+ # TBU: WILL INCLUDE A STAGE4 TARBALL CREATION
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['V', 'v', '5']:
+ # Go to parrent
+ _sub_call = {"_PARENT": 0}
+
+ elif SELCT in ['t', 'T']:
+ # Call shell function
+ from gpyfunctions.preliminary import _shell
+ _shell()
+
+ _sub_call = {"_STAY": 0}
+
+ del _shell
+
+ else:
+ _sub_call="err"
+
+ del SELCT
+
+ return _sub_call
+
+
+ def bs_f(*args):
+ '''
+ Builders's menu function
+ '''
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ # CALL PORTAGE SUBMENU)
+ _sub_call = {"_CHILD": "PORT_M"}
+
+ elif SELCT in ['II', 'ii', '2']:
+ # CALL CATALYST SUBMENU
+ _sub_call = {"_CHILD": "CATA_M"}
+
+ elif SELCT in ['III', 'iii', '3']:
+ # START PRE PRECOMPILED
+ # import warp "--base=precomp" "args" here
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['IV', 'iv', '4']:
+ # Go to parrent
+ _sub_call = {"_PARENT": 0}
+
+ elif SELCT in ['t', 'T']:
+ # Call shell function
+ from gpyfunctions.preliminary import _shell
+ _shell()
+
+ _sub_call = {"_STAY": 0}
+
+ del _shell
+
+ else:
+ _sub_call="err"
+
+ del SELCT
+
+ return _sub_call
+
+
+ def portage_men_f(CCONFDIR, *args):
+ '''
+ Portage's menu function
+ '''
+
+ from subprocess import call
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ exit(0)
+ # Make make.conf: Automatic or guided configuration
+ _ex_stat = makeconf_ed
+
+ if _ex_stat == 0:
+ print(report_colors.YELLOW + "[ * ]" + report_colors.RESET + "Configuration was successful")
+ else:
+ print(report_colors.SRED + "[ * ]" + report_colors.RESET + "Something went wrong")
+
+ del _ex_stat
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['II', 'ii', '2']:
+ # Edit of make.conf
+ call(["vim", CCONFDIR + "/system/portage/make.conf"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['III', 'iii', '3']:
+ # Edit features
+ call(["vim", CCONFDIR + "/system/coptions"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['IV', 'iv', '4']:
+ # Edit distcc's hosts
+ call(["vim", CCONFDIR + "/system/hosts"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['V', 'v', '5']:
+ # Edit USEFLAGS
+ call(["vim", CCONFDIR + "/system/portage/package.use/sysbuild"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['VI', 'vi', '6']:
+ # Go to parrent
+ _sub_call = {"_PARENT": 0}
+
+ elif SELCT in ['t', 'T']:
+ # Call shell function
+ from gpyfunctions.preliminary import _shell
+ _shell()
+
+ _sub_call = {"_STAY": 0}
+
+ del _shell
+
+ else:
+ _sub_call="err"
+
+ del SELCT, call
+
+ return _sub_call
+
+
+ def catalyst_f(CCONFDIR, args):
+ '''
+ Catalyst's menu function
+ '''
+
+ from subprocess import call
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ # Edit catalyst.conf
+ call(["vim", CCONFDIR + "/system/catalyst/catalyst.conf"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['II', 'ii', '2']:
+ # Edit catalystrc
+ call(["vim", CCONFDIR + "/system/catalyst/catalystrc"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['III', 'iii', '3']:
+ # Edit stage1.spec
+ call(["vim", CCONFDIR + "/system/catalyst/stage1.spec"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['IV', 'iv', '4']:
+ # Edit stage2.spec
+ call(["vim", CCONFDIR + "/system/catalyst/stage2.spec"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['V', 'v', '5']:
+ # Edit stage3.spec
+ call(["vim", CCONFDIR + "/system/catalyst/stage3.spec"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['VI', 'vi', '6']:
+ # Initiate system build
+ #warp "--base=catalyst" "${lppar[@]}"
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['VII', 'vii', '7']:
+ # Go to parrent
+ _sub_call = {"_PARENT": 0}
+
+ elif SELCT in ['t', 'T']:
+ # Call shell function
+ from gpyfunctions.preliminary import _shell
+ _shell()
+
+ _sub_call = {"_STAY": 0}
+
+ del _shell
+
+ else:
+ _sub_call="err"
+
+ del SELCT, call
+
+ return _sub_call
+
+
+ def config_f(CCONFDIR, *args):
+ '''
+ Configuration's menu function
+ '''
+
+ from subprocess import call
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ # Marked for removal
+ #drv_interface
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['II', 'ii', '2']:
+ # Edit fstab
+ call(["vim", CCONFDIR + "/system/fstab"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['III', 'iii', '3']:
+ # Edit devname.info
+ call(["vim", CCONFDIR + "/system/devname.info"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['IV', 'iv', '4']:
+ # Edit hostname
+ call(["vim", CCONFDIR + "/system/hostname"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['V', 'v', '5']:
+ # Edit conf.d/net
+ call(["vim", CCONFDIR + "/system/net"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['VI', 'vi', '6']:
+ # Edit locale
+ call(["vim", CCONFDIR + "/system/locale.gen"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['VII', 'vii', '7']:
+ # Edit consolefont
+ call(["vim", CCONFDIR + "/system/consolefont"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['VIII', 'viii', '8']:
+ # Edit sshd_config
+ call(["vim", CCONFDIR + "/system/sshd"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['IX', 'ix', '9']:
+ # Edit id_rsa.pub
+ call(["vim", CCONFDIR + "/system/ssh.pub"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['X', 'x', "10"]:
+ # Edit system links
+ call(["vim", CCONFDIR + "/system/system_links"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['XI', 'xi', '11']:
+ # Edit custom scripts
+ call(["vim", CCONFDIR + "/system/custom_scripts"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['XII', 'xii', '12']:
+ # Edit custom package list
+ call(["vim", CCONFDIR + "/system/custom_pacl"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['XIII', 'xiii', '13']:
+ # Edit /etc/default/grub
+ call(["vim", CCONFDIR + "/system/grub"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['XIV', 'xiv', '14']:
+ # Edit runlevels
+ call(["vim", CCONFDIR + "/system/runlevels"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['XV', 'xv', '15']:
+ # Edit files
+ call(["vim", CCONFDIR + "/system/inject_files"], stdout=None, stderr=None)
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['XVI', 'xvi', '16']:
+ # Go to parrent
+ _sub_call = {"_PARENT": 0}
+
+ elif SELCT in ['t', 'T']:
+ # Call shell function
+ from pgpyfunctions.reliminary import _shell
+ _shell()
+
+ _sub_call = {"_STAY": 0}
+
+ del _shell
+
+ else:
+ _sub_call="err"
+
+ del SELCT, call
+
+ return _sub_call
+
+
+ def selectdef_f(*args):
+ '''
+ Select default menu function
+ '''
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['II', 'ii', '2']:
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['III', 'iii', '3']:
+ # Go to parrent
+ _sub_call = {"_PARENT": 0}
+
+ elif SELCT in ['t', 'T']:
+ # Call shell function
+ from gpyfunctions.preliminary import _shell
+ _shell()
+
+ _sub_call = {"_STAY": 0}
+
+ del _shell
+
+ else:
+ _sub_call="err"
+
+ del SELCT
+
+ return _sub_call
+
+
+ def doc_f(CWORKDIR, *args):
+ '''
+ Documentetion's menu function
+ '''
+
+ from subprocess import call
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ call(["man", CWORKDIR + "/docs/documentations/overview_gse.5"])
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['II', 'ii', '2']:
+ call(["man", CWORKDIR + "/docs/documentations/overview_controller.5"])
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['III', 'iii', '3']:
+ call(["man", CWORKDIR + "/docs/documentations/overview_config.d.5"])
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['IV', 'iv', '4']:
+ call(["man", CWORKDIR + "/docs/documentations/overview_scripts.5"])
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['V', 'v', '5']:
+ # Go to parrent
+ _sub_call = {"_PARENT": 0}
+
+ else:
+ _sub_call="err"
+
+ del SELCT, call
+
+ return _sub_call
+
+ def about_f(CWORKDIR, *args):
+ '''
+ About menu function
+ '''
+
+ SELCT = portalin("_input")
+
+ if SELCT in ['I', 'i', '1']:
+ e_report("About submenu option a)")
+ portalin("_key")
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['II', 'ii', '2']:
+ e_report("About submenu option b)")
+ portalin("_key")
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['III', 'iii', '3']:
+ e_report("About submenu option c)")
+ portalin("_key")
+
+ _sub_call = {"_STAY": 0}
+
+ elif SELCT in ['IV', 'iv', '4']:
+ # Go to parrent
+ _sub_call = {"_PARENT": 0}
+
+ else:
+ _sub_call="err"
+
+ del SELCT
+
+ return _sub_call
+
+
+ def controller_f(*args):
+ '''
+ Controller's menu function
+ '''
+
+ e_report("Initiating controller build")
+
+ _sub_call = {"_PARENT": 0}
+
+ return _sub_call
+
+
+ # Get the return value from the evaluated function
+ _sub_call = eval(ccal+'(args[0], args[1:])')
+
+ # Clear return
+ del portalin, report_colors, e_report, b_report, exit
+
+ return _sub_call
+
+
+
diff --git a/scripts/gpyfunctions/preliminary.py b/scripts/gpyfunctions/preliminary.py
new file mode 100755
index 0000000..6f40533
--- /dev/null
+++ b/scripts/gpyfunctions/preliminary.py
@@ -0,0 +1,187 @@
+#!/usr/bin/env python3.4
+
+# Gentoo check function
+def _is_gentoo():
+ '''
+ Check if the project has been initiated from a Gentoo system
+ '''
+
+ from subprocess import call
+
+ # Grep Gentoo from the releases file.
+ _dist_check = call("grep ^NAME= /etc/*release | awk -F '=' '{print $2}' | grep -q Gentoo", stdout=None, stderr=None, shell=True)
+
+ del call
+
+ # Return 0 in case grep was successful, or 1 otherwise.
+ if _dist_check == 0:
+ del _dist_check
+ return 0
+ else:
+ return 1
+
+# Check for superuser privileges
+def _is_su():
+ '''
+ Check if the project has been initiated with super user permissions
+ '''
+
+ from subprocess import call
+
+ # The check is very simple. It checks if the $UID is equal to 0. In case it is not, it returns a value of 1
+ _super_u = call("if [[ $(echo $UID) == 0 ]]; then exit 0; else exit 1; fi", stdout=None, stderr=None, shell=True)
+
+ del call
+
+ # Test the return value and return either 0 or 1
+ if _super_u == 0:
+ del _super_u
+ return 0
+ else:
+ return 1
+
+# Simple input call
+def portalin(_input):
+ '''
+ Calls for a user input.
+ There are two calls for input
+ I ) The first one requests an input and returns it to the function that requested it
+ II ) The second asks for a user input and does nothing. This one is for visual purpose like (press any key)
+ '''
+
+ from gpyfunctions.tools.gseout import report_colors
+
+ # Ask for user input
+ if _input is "_input":
+ portin = input(report_colors.YELLOW + "Input :: <= " + report_colors.RESET)
+ return portin
+
+ # Asks for an input to continue the process.
+ # The main difference of this one from the above, apart from the stdout text is that it does not return anything.
+ elif _input is "_key":
+ portin = input(report_colors.BLUE + "Press any key to continue" + report_colors.RESET)
+
+ del report_colors
+
+
+# Simple shell call
+def _shell():
+ '''
+ Shell function that:
+ Exports the current $SHELL of the system
+ Initiates a call subprocess on the given $SHELL
+ Resumes the process when the call shell subprocess finishes
+ '''
+
+ from gpyfunctions.tools.gseout import e_report
+ from os import environ
+
+ # Export $SHELL
+ active_shell = environ['SHELL']
+
+ e_report("Calling " + active_shell + ", please exit to resume script")
+
+ # Import time and wait 3 seconds before initiating a shell
+ import time
+ time.sleep(1.5)
+
+ from subprocess import call
+
+ # Open shell terminal with as $SHELL
+ call([active_shell], stdout=None, stderr=None, shell=True)
+ e_report("Proceeding")
+
+ # Clear and exit
+ del e_report, time, call, active_shell, environ
+
+# Simple clear screen function
+def _clear():
+ '''
+ Very simply screen clear function.
+ When called, it executes system("clear") for os module
+ This function exists only to aid the text menu functions.
+ '''
+
+ from os import system
+ system("clear")
+
+# Parameter error function
+def _parameter_error():
+ '''
+ Parameter miss match error
+ This error will be printed before key point actions.
+ Example: All actions that request write access in the system.
+ '''
+
+ from gpyfunctions.tools.gseout import die
+ from os import system
+ die("""
+ [ FATAL ]
+
+ If this message is printed while using the Maim Menu
+ That means essential files are altered or something bad is happening.
+
+ Please run a health-check from the ~Main Menu~ and a Version check first.
+ If you see this again after the health/version check, please submit a bug report
+ and stop using the program, or data loss may occur.
+
+ Exiting...
+ """)
+
+
+# Export important project's sub-directories
+def _gse_path(_gpyfunc_):
+ '''
+ The purpose of this function is to read the given _gpygunc_ variable and export
+ the all important project's sub-directories
+ The subdirectories are:
+ CCGSE
+ CCONFDIR
+ CDISTDIR
+ CLOCALLG
+ CLOGLG
+ CSYSROOT
+ CLOCALLIB
+ CFUNCTIONS
+ '''
+
+ from os import getcwd, path
+ from sys import exit
+
+ # Export current working category
+ CWORKDIR = getcwd()
+
+ if _gpyfunc_ == 'sys':
+ CWORKDIR = '/usr/lib64/gse'
+ CGSE = CWORKDIR + '/gse.py'
+ CCONFDIR = CWORKDIR + '/config.d'
+ CDISTDIR = '/var/tmp/gse/dist.d'
+ CLOCALLG = CWORKDIR + '/local'
+ CLOGLG = '/var/log/gse'
+ CSYSROOT = '/home/gse'
+ CLOCALLIB = '/var/lib/gse'
+ CFUNCTIONS = CWORKDIR + 'scripts/pyfunctions'
+
+ elif _gpyfunc_ == '.git':
+ # If the project has been git cloned or simply copied to a location
+ CWORKDIR = path.dirname(CWORKDIR)
+ CFUNCTIONS = CWORKDIR+'/scripts/pyfunctions'
+ CGSE = CWORKDIR + '/gse.py'
+ CCONFDIR = CWORKDIR+'/config.d'
+ CDISTDIR = CWORKDIR+'/dist.d'
+ CLOCALLG = CWORKDIR+'/local'
+ CLOGLG = CWORKDIR+'/var/log'
+ CSYSROOT = CWORKDIR+'/sysroot'
+ CLOCALLIB = CWORKDIR+'/var/lib'
+
+ else:
+ print("\033[0;31m Could not find project's directory \033[0;0m")
+ exit(1)
+
+ del getcwd, path, exit
+
+ return CWORKDIR, CGSE, CFUNCTIONS, CCONFDIR, CDISTDIR, CLOCALLG, CLOGLG, CSYSROOT, CLOCALLIB
+
+
+
+
diff --git a/scripts/gpyfunctions/system/__init__.py b/scripts/gpyfunctions/system/__init__.py
new file mode 100644
index 0000000..2a1545b
--- /dev/null
+++ b/scripts/gpyfunctions/system/__init__.py
@@ -0,0 +1,2 @@
+#__all__=[]
+#__path__=[
diff --git a/scripts/gpyfunctions/tools/__init__.py b/scripts/gpyfunctions/tools/__init__.py
new file mode 100644
index 0000000..95843cb
--- /dev/null
+++ b/scripts/gpyfunctions/tools/__init__.py
@@ -0,0 +1,2 @@
+__all__=["gseout"]
+#__path__=[]
diff --git a/scripts/gpyfunctions/tools/gseout.py b/scripts/gpyfunctions/tools/gseout.py
new file mode 100755
index 0000000..a8b7bcd
--- /dev/null
+++ b/scripts/gpyfunctions/tools/gseout.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3.4
+
+from sys import exit
+
+# Output colors
+class report_colors:
+ '''
+ Class that defines and saves various color formats
+ '''
+
+ SRED = "\033[0;31m"
+ LRED = "\033[1;31m"
+ BLUE = "\033[0;34m"
+ YELLOW = "\033[0;33m"
+ CYAN = "\033[1;36m"
+ GREEN = "\033[0;32m"
+ PURPLE = "\033[2;35m"
+ RESET = "\033[0;0m"
+
+# Die function
+def die(error):
+ '''
+ Print red error and kill the process
+ '''
+
+ print(report_colors.SRED + error + report_colors.RESET)
+ exit(1)
+
+# Red report function
+def lr_report(report):
+ '''
+ Print a light red warning
+ '''
+
+ print(report_colors.LRED + report + report_colors.RESET)
+
+# Yellow report function
+def e_report(report):
+ '''
+ Print a yellow warning
+ '''
+
+ print(report_colors.YELLOW + report + report_colors.RESET)
+
+# Blue report function
+def b_report(report):
+ '''
+ Print a blue warning
+ '''
+
+ print(report_colors.BLUE + report + report_colors.RESET)
+
+# Green report function
+def g_report(report):
+ '''
+ Print a green warning
+ '''
+
+ print(report_colors.GREEN + report + report_colors.RESET)
+
+# Purpule report function
+def p_report(report):
+ '''
+ Print a purple warning
+ '''
+
+ print(report_colors.PURPLE + report + report_colors.RESET)
+
+
+
+
+
+
+
+
diff --git a/scripts/gpyfunctions/tools/librarium.py b/scripts/gpyfunctions/tools/librarium.py
new file mode 100755
index 0000000..dd491b1
--- /dev/null
+++ b/scripts/gpyfunctions/tools/librarium.py
@@ -0,0 +1,503 @@
+#!/usr/bin/env python3.4
+
+gse_des = '''\
+ -----------------------------------------------------------------
+
+ GSE: This project was built under GSoC 2017 for Gentoo Fundation.
+ For more informations see man gse.5 or the project's wiki at:
+ https://wiki.gentoo.org/wiki/User:Ulfox/GSoC-GSE
+
+ -----------------------------------------------------------------
+
+ System: For system menu, run: gse system -h
+ Controller: For controller menu, run: gse controller -h
+ '''
+gse_usage="%(prog)s system --base=[precomp/catalyst] [options] / controller [options] / [-h/--help]"
+
+gse_ver = '%(prog)s Experimental'
+
+# System arguments
+def _export_args(sequence):
+ '''
+ Here all project's arguments and options are defined.
+
+ The definition has 4 phases.
+ On phase 1 the general project's arguments and options are defined.
+ On phase 2 the special arguments and options are defined, based on the sequence that is given.
+ On phase 3 special sub-options are defined. Those options are enabled only from some special options.
+ Last, on phase 4, everything is evaluated and returned back the the parent function.
+ '''
+
+ # Library for arguments and options parse
+ import argparse
+ from sys import argv
+
+ # Definition of name, usage and description for the options menu
+ parser = argparse.ArgumentParser(prog="gse",
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ description=gse_des,
+ usage=gse_usage,
+ epilog="For more information about each option, please see man gse.1 " +
+ "This program is distributed under GPL-2 license",
+ add_help=True)
+
+ # Dev opt
+ parser.add_argument('--dev',
+ help="Marked for removal. Removes all kind of checks. Never run this with super user privileges. It exists only for the experimental developing phase.",
+ action="store_true",
+ default=False)
+
+ parser.add_argument("target",
+ help="Initiate either system or controller scripts. [system/controller] ",
+ action="store",
+ default=None)
+
+ parser.add_argument("--gmm",
+ help="GUI Menu",
+ action="store_true",
+ default=False)
+
+ parser.add_argument("--mm",
+ help="Text Menu",
+ action="store_true",
+ default=False)
+
+ # Time-warp option
+ parser.add_argument('--timewarp', '--time-warp',
+ help="Load and execute a saved state. A state is the set of configuration files and arguments that were saved at a given time.",
+ action="store",
+ type=int)
+
+ # Time-state option
+ parser.add_argument('--timestate', '--time-state',
+ help="Create, list, set, save and delete configuration states. \
+ Syntax: --time-state [save/list/set/delete] [name/-/N/N]",
+ action="store",
+ default='no',
+ nargs='+',
+ type=str)
+
+ # No check option
+ parser.add_argument('--nochecks', '--no-checks',
+ help="Disable all \"simple\" checks. The process will be enabled without requesting a return 0 from the system check function.",
+ action="store_true",
+ default=False)
+
+ # Keep optional argument.
+ parser.add_argument('-k', '--keep',
+ help='''Save to backup old work, instead of purging / reconfiguring an old entry. This option does not work with force.''',
+ action="store_true",
+ default=False)
+
+ # Health check argument
+ parser.add_argument('-hc', '--healthcheck', '--health-check',
+ help='''Run integrity check for the project's scripts and essential configuration files''',
+ action="store_true",
+ default=False)
+
+ # Replace new argument
+ parser.add_argument('-rpn', '--replacenew', '--replace-new',
+ help='''Refresh all the project's scripts and configuration files.
+ Warning: All user configuration files will be lost''',
+ action="store_true")
+
+ # Minimal build
+ parser.add_argument('-bm', '--minimal', '--build-minimal',
+ help="""Enable minimal build. This option removes and disables many features. All images under this flag are configured for size.""",
+ action="store_true",
+ default=False)
+
+ # Verbose option
+ parser.add_argument('-v', '--verbose',
+ help="Enable verbose output for all actions.",
+ action='count')
+
+ # Quiet option
+ parser.add_argument('-q', '--quiet',
+ help="Enable quiet global flag. This flag suppresses all output with a simple text entry regarding the action.",
+ action="store_true",
+ default=False)
+
+ # Version
+ parser.add_argument('-V', '--version',
+ help="Show project's version and exit.",
+ action='version',
+ version=gse_ver)
+
+ if sequence == 'system':
+ # Base definition. While base appears to be optional, it is not, since it's always required to initiate the building sequence
+ parser.add_argument('-b', '--base',
+ help='''Set the system's fundation. See man gse.1 for more.''',
+ action="store",
+ type=str,
+ default='catalyst')
+
+ # Force new optional argument
+ parser.add_argument('-fcn', '--forcenew', '--force-new',
+ help='''Enable force to all project's actions. This option purges all previous work done. Not recommended!''',
+ action="store_true",
+ default=False)
+
+ # Fetch new optional argument
+ parser.add_argument('-fn', '--fetchnew', '--fetch-new',
+ help="Enable fetch option. Will always download requested files, even if they exist and are up to date.",
+ action="store_true",
+ default=False)
+
+ # Script's check argument
+ parser.add_argument("--sdir",
+ help="Give the directory that hosts the scripts. See man gse.1 for more informations.",
+ action="store",
+ default=None,
+ type=str)
+
+ for _tmp1 in argv[:]:
+ if '--sdir' in str(_tmp1):
+ parser.add_argument("--do",
+ help="Scripts to be sourced. For the same hook the given order applies to priority.",
+ action="store",
+ default=None,
+ type=str)
+
+ parser.add_argument("--ghook",
+ help="Hooks with priority for given scripts.",
+ action="store",
+ default=None,
+ type=str)
+
+ # Disable kernel build optional argument
+ parser.add_argument('-ke', '--kernel',
+ help='''Enable kernel build action inside the chroot phase''',
+ action="store_true",
+ default=False)
+
+ # Disable initramfs build optional argument
+ parser.add_argument('-i', '--initrd',
+ help='''Enable initramfs build action inside the chroot phase''',
+ action="store_true",
+ default=False)
+
+ # Enable automatic mode.
+ parser.add_argument('--auto',
+ help="Enable automatic mode. All prompt actions will turn to yes/continue.",
+ action="store_true",
+ default=False)
+
+ # Enforce arguments
+ parser.add_argument('--enforce',
+ help="Enforce (force) a specific Part of the process. More about stages and parts at man gse.5",
+ action="store",
+ default=None,
+ type=str)
+
+ # Lawful-good arguments
+ parser.add_argument('--lawfulgood', '--lawful-good',
+ help="Lawful good (pass) a specific Part of the process. More about stages and parts at man gse.5",
+ action="store",
+ default=None,
+ type=str)
+
+ # Distcc
+ parser.add_argument('--distcc',
+ help="Enable distcc mode for the system build process. For pump, give --distcc=pump. See man 5 gse for more informations.",
+ action="store",
+ default=None,
+ type=str)
+
+ # Ccache
+ parser.add_argument('--ccache',
+ help="Enable ccache for the system build process.",
+ action="store_true",
+ default=False)
+
+ # Edit configs option
+ parser.add_argument('-e', '--edit',
+ help='''Edit X:Y config. Where X is the category and Y is the file. See man gse.1 for more informations''',
+ action="store",
+ type=str)
+
+ elif sequence == 'controller':
+ # Build the controller option
+ parser.add_argument('-bc', '--controller', '--build-controller',
+ help='''Request the initramfs-controller image. Not to confuse with the --initrd. See man gse.1 for more informations.''',
+ action="store_true",
+ default=False)
+
+ # Force option
+ parser.add_argument('--force',
+ help="Enable Dracut's force flag. The option is for simplicity over --dracut_opt=-f",
+ action="store_true",
+ default=False)
+
+ # Hook script option
+ parser.add_argument('--hook',
+ help="Add custom scripts to Dracut hook points. Use this for simple scripts instead of creating new modules.",
+ action="store",
+ default=None,
+ type=str)
+
+ # Net script option
+ parser.add_argument('--net',
+ help="Import a custom net script to be sourced before initiating the controller scripts. That is after udev has finished.",
+ action="store",
+ default=None,
+ type=str)
+
+ # Module config
+ parser.add_argument('--modules',
+ help="Import a custom module config file under /etc/modprobe.d with name umod.conf.",
+ action="store",
+ default=None,
+ type=str)
+
+ # Dracut's option cmdline
+ parser.add_argument('--dracut_opt',
+ help="Include extra options for dracut. For more info see man dracut",
+ action="store",
+ default=None,
+ type=str)
+
+ args = parser.parse_args()
+
+ del parser
+ del argparse
+
+ return args
+
+
+# Check system's arguments
+def _check_args(args):
+ '''
+ This function is directly related to the _export_args function.
+ The purpose of this function is to check given options and arguments and either give a pass or kill the process.
+ The pass/kill is defined from conditions that are not allowed to be executed simultaneously or they are either
+ missing or holding an invalid entry.
+
+ Example 1: for --enforce gccat. This will kill the process, since gccat is not defined as one of the building hooks.
+ Example 2: for --sdir ~/my_scripts --do sc1:sc2:sc3 --ghook -gseed:+gportage:. Here the scripts are more than the hooks.
+ '''
+
+ # Libraries for
+ import os
+ from sys import argv
+ from gpyfunctions.tools.gseout import die, e_report, b_report
+
+ # Opt conditions
+ def _opt_cond(args):
+ '''
+ Check if there are enabled options that "collide" with each other.
+ If yes, issue a warning or die if the "collision" is significant.
+ '''
+
+ if args.quiet and not args.verbose == None:
+ die("Error: Quiet and Verbose can not be used at the same time")
+
+ if args.forcenew and args.keep:
+ die("Error: Force new can not be used with keep")
+
+ if args.edit and not len(argv[1:]) == 2:
+ die("Invalid options for --edit. Edit can only be used alone as option. Please give only the related XY number.")
+
+ if args.forcenew and not args.lawfulgood == None:
+ die("Warning: --force-new suppresses --lawful-good")
+
+ if not args.lawfulgood == None and not args.enforce == None:
+ e_report("Warning: --lawful-good suppresses --enforce")
+
+ if args.healthcheck and not len(argv[1:]) == 1:
+ die("Warning: --health-check unknown parameters")
+
+ if args.replacenew and not len(argv[1:]) == 1:
+ die("Warning: --replace-new unknown parameters")
+
+ # Issue warning if minimal and enforce with ginst or gkernel or gintrid are enabled simultaneously
+ if args.minimal:
+ _minimal_exclude = [ "ginst", "gkernel", "gintrid"]
+
+ for i in _minimal_exclude[:]:
+ if i in args.enforce[:] and args.minimal:
+ e_report("Warning: --build-minimal suppresses " + i)
+
+ del _minimal_exclude
+
+ # Call opt conditions
+ _opt_cond(args)
+
+ del _opt_cond
+
+ def _hook_set():
+ '''
+ Here are defined the hooks of the system build process.
+ '''
+
+ # Create set with valid hook entries
+ __set = {"gfund", "gseed", "gcat", "gextr", "gprec", "gparta", "gupdate", "gportage", "grebuild", "gsnap"}
+ __set.add("gconfigure")
+ __set.add("ginst")
+ __set.add("grun")
+ __set.add("gkernel")
+ __set.add("ginitrd")
+ __set.add("gdes")
+ __set.add("gpartb")
+ __set.add("gclean")
+
+ return __set
+
+ # Check if --base=[catalyst/precomp]
+ if args.base == 'catalyst' or args.base == 'precomp':
+ e_report("System base set to: " + args.base)
+ else:
+ die("Wrong base entry. Please give either 'catalyst' or 'precomp'")
+
+ # Export enforce hook point entries
+ if not args.enforce == None:
+ en_args = args.enforce
+
+ args.enforce = []
+ args.enforce = [x.strip() for x in en_args.split(':')]
+
+ del en_args
+
+ # Export default hook entries
+ _args_set = _hook_set()
+
+ for _tmp1 in args.enforce[:]:
+ if not _tmp1 in _args_set:
+ die("Enforce: " + _tmp1 + " is not a valid hook point")
+
+ del _args_set, _tmp1
+
+ # Print enforce hooks
+ e_report("Enforce enabled")
+ print("\033[0;34m Hooks:", "\033[0;33m", end='')
+ print(*args.enforce)
+ print("\033[0;0m")
+
+
+ # Export lawful-good hook point entries
+ if not args.lawfulgood == None:
+ lg_args = args.lawfulgood
+
+ args.lawfulgood = []
+ args.lawfulgood = [x.strip() for x in lg_args.split(':')]
+
+ del lg_args
+
+ # Export default hook entries
+ _args_set = _hook_set()
+
+ for _tmp1 in args.lawfulgood[:]:
+ if not _tmp1 in _args_set:
+ die("Lawful-good: " + _tmp1 + " is not a valid hook point")
+
+ del _args_set, _tmp1
+
+ # Print lawful-good hooks
+ e_report("Lawful enabled")
+ print("\033[0;34m Hooks:", "\033[0;33m", end='')
+ print(*args.lawfulgood)
+ print("\033[0;0m")
+
+ # Script's --sdir checks
+ if not args.sdir == None:
+ if not os.path.isdir(args.sdir):
+ die("Sdir's location is not a directory")
+
+ # Check if --do option has been given.
+ if not args.do == None:
+ do_args = args.do
+
+ args.do = []
+ args.do = [x.strip() for x in do_args.split(':')]
+
+ del do_args
+
+ # Check if given scripts exist
+ for i in args.do:
+ __sdir= (args.sdir + '/')
+ __is_file = (__sdir + i)
+
+ if not os.path.isfile(__is_file):
+ die("The file " + i + " does not exist. " + "Please be sure that " + args.sdir + " is the correct directory that hosts the scripts.")
+
+ del __is_file, __sdir
+
+ # Count the number of scripts to compare them with the number of hook points later
+ do_nargs = len(args.do[:])
+
+ else:
+ # Issue error for missing --do
+ die("Scripts: --do script1:script2:...:scriptN are missing")
+
+ # Check if --ghook option has been given
+ if not args.ghook == None:
+ ghook_args = args.ghook
+
+ args.ghook = []
+ args.ghook = [x.strip() for x in ghook_args.split(':')]
+
+ del ghook_args
+
+ # Check if given hook entries have a priority mark, issue warning and die otherwise
+ for _tmp1 in args.ghook[:]:
+ if _tmp1[0] != '-' and _tmp1[0] != '+':
+ die("Please give - or + at the beginning of each hook. See gse.1 and gse.5 for more informations and examples.")
+
+ del _tmp1
+
+ # Export default hook entries
+ _args_set = _hook_set()
+
+ # Check if the given entries are valid entries
+ for _tmp1 in args.ghook[:]:
+ if not _tmp1[1:] in _args_set:
+ die("Enforce: " + _tmp1 + " is not a valid hook point")
+
+ del _tmp1, _args_set
+
+ # Count ghook entries
+ ghook_nargs = len(args.ghook[:])
+
+ # Compare if scripts have equal hook points
+ if do_nargs == ghook_nargs:
+ del ghook_nargs, do_nargs
+
+ else:
+ # Die if scripts are not equal to hook points and vice versa
+ die("Number of hook point entries does not match the number of given scripts")
+
+ else:
+ # Die for missing
+ die("Hook points are missing: --ghook [+-]hook1:[+-]hook2:...:[+-]hookN:")
+
+
+ # Print the args.sdir, *args.do and *args.ghook
+ e_report("Scripts enabled")
+ print("\033[0;34m Directory: ", "\033[0;33m", end='')
+ print(args.sdir)
+ print("\033[0;34m Scripts: ", "\033[0;33m", end='')
+ print(*args.do)
+ print("\033[0;34m Hooks: ", "\033[0;33m", end='')
+ print(*args.ghook)
+ print("\033[0;0m")
+
+ del die, argv, e_report, b_report
+
+
+# Check controller's arguments
+def _ct_check_args(args):
+ '''
+ This function checks the controller arguments.
+
+ Compared to the _export_args, while similar, this is more simple, since
+ Most of the controller flags are true/false entries and those that are not, are simple
+ input file entries.
+ '''
+
+ pass
+
+
+
+
+
+
diff --git a/scripts/gpyfunctions/tools/warp.py b/scripts/gpyfunctions/tools/warp.py
new file mode 100755
index 0000000..44589c7
--- /dev/null
+++ b/scripts/gpyfunctions/tools/warp.py
@@ -0,0 +1,496 @@
+#!/usr/bin/env python3.4
+
+# Time state function
+def time_state(args, CWORKDIR, CCONFDIR, CLOCALLG):
+ '''
+ Time sate function.
+ Saves a state of configuration files + options + arguments for later use
+ Lists the saved states
+ Sets a state as a default state. The state must exist before this option is used
+ Deletes a saved state from the list
+ '''
+
+ import os
+ import datetime
+ from gpyfunctions.tools.gseout import die, e_report, b_report, lr_report
+
+ # Create state directory, for hosting the state entries
+ if not os.path.exists(CLOCALLG + "/states"):
+ os.makedirs(CLOCALLG + "/states")
+
+ # Save a state
+ if args.timestate[0] == "save":
+
+ # Check if state name has been given, die if not
+ try:
+ if args.timestate[1]:
+ pass
+
+ # Counter for the states mark
+ k = 1
+ # Export directory's contents to a state list
+ _tmp_state_list =os.listdir(CLOCALLG + "/states/")
+
+ # Define state's mark (k) value
+ for _tmp1 in _tmp_state_list[:]:
+ try:
+ if k < 10:
+ if str(k) == _tmp1[0:1]:
+ k += 1
+
+ elif k >= 10:
+ if str(k) == _tmp1[0:2]:
+ k += 1
+
+ except IndexError:
+ break
+
+ del _tmp_state_list
+
+ try:
+ del _tmp1
+
+ except NameError:
+ pass
+
+ # Date and time
+ _state_date = str(datetime.datetime.today().strftime("date-%Y-%m-%d-time-%H-%M"))
+
+ del datetime
+
+ # Check if the state directory is indeed missing then create it. Issue warning and die otherwise
+ if not os.path.exists(CLOCALLG + "/states/" + str(k) + "_" + args.timestate[1] + "-" + _state_date):
+ os.makedirs(CLOCALLG + "/states/" + str(k) + "_" + args.timestate[1] + "-" + _state_date)
+ # Text report
+ print("\033[0;33mCreated state entry:", "\033[0;33m", end='')
+ print("\033[0;34m" + str(k) + "_" + args.timestate[1] + "-" + _state_date)
+
+ else:
+ die("Can not create state: " + args.timestate[1] + ", because the state already exists")
+
+ except IndexError:
+ # Name has not been given, since 1 gives an index error
+ die("Missing name for --time-state save")
+
+
+ # Full path and state name
+ _abs_state_name = (CLOCALLG + "/states/" + str(k) + "_" + args.timestate[1] + "-" + _state_date)
+ _state_name = (str(k) + "_" + args.timestate[1] + "-" + _state_date)
+
+ # Function for copying config.d/system directory
+ def _copy_config_target(CCONFDIR, target, _abs_state_name):
+ '''
+ Copy either .../config.d/system or .../config.d/controller to the newly created state.
+ The decision is based on the nature of the saved state. If it was called under the sequence=system variable,
+ then system is copied and if it was called under the sequence=controller variable, then controller is copied.
+ '''
+
+ # Import shutil for enabling copy functionality
+ import shutil
+
+ try:
+ # Copy the system directory
+ shutil.copytree(CCONFDIR + '/' + target, _abs_state_name + '/' + target)
+
+ # Text report
+ print("\033[0;33m Saving:", "\033[0;33m", end='')
+ b_report("config.d/" + target + " to state")
+
+ except FileNotFoundError:
+ die(" File not found error. If config.d/system exists, please report this bug.")
+
+ except FileExistsError:
+ die(" File exists error. Please report the bug!")
+
+ del shutil
+
+ # System case
+ if args.target == 'system':
+ # Create main_flags file under state directory and make it writable
+ with open(_abs_state_name + '/main_flags', 'w') as _s_entry:
+ _system_entries = {}
+ _system_entries["State name: "] = _state_name
+ _system_entries["State target : "] = args.target
+ _system_entries["System target: "] = args.base
+ _system_entries["Auto: "] = args.auto
+ _system_entries["Ccache: "] = args.ccache
+ _system_entries["Dev: "] = args.dev
+ _system_entries["Distcc: "] = args.distcc
+
+ if args.enforce == None:
+ _system_entries["Enforce: "] = args.enforce
+ else:
+ _system_entries["Enforce: "] = "Enabled"
+
+ if args.lawfulgood == None:
+ _system_entries["Lawful-good: "] = args.lawfulgood
+ else:
+ _system_entries["Lawful-good: "] = "Enabled"
+
+ if args.sdir == None:
+ _system_entries["Sdir :"] = args.sdir
+ _system_entries["Do scripts :"] = "None"
+ _system_entries["GHooks :"] = "None"
+ else:
+ _system_entries["Sdir : "] = "Enabled"
+ _system_entries["Do scripts :"] = "Enabled"
+ _system_entries["GHooks :"] = "Enabled"
+
+ _system_entries["Fetch new: "] = args.fetchnew
+ _system_entries["Force new: "] = args.forcenew
+ _system_entries["Initrd: "] = args.initrd
+ _system_entries["Keep: "] = args.keep
+ _system_entries["Kernel: "] = args.kernel
+ _system_entries["Minimal build: "] = args.minimal
+ _system_entries["No checks: "] = args.nochecks
+ _system_entries["Quiet :"] = args.quiet
+ _system_entries["Verbose : "] = args.verbose
+
+ # Write system enabled/disabled options
+ for key, value in _system_entries.items():
+ _s_entry.write(str(key) + str(value) + '\n')
+
+ # Text report
+ print("\033[0;33m Saving:", "\033[0;33m", end='')
+ b_report("Main options")
+
+ if _s_entry.closed:
+ del _s_entry
+ else:
+ _s_entry.close()
+ del _s_entry
+
+ # Write enforce entries
+ if args.enforce != None:
+ with open(_abs_state_name + '/enforce_hooks', 'w') as _e_entry:
+ for i in range(len(args.enforce[:])):
+ _e_entry.write("Hook " + str(i) + " : " + args.enforce[i] + '\n')
+
+ if _e_entry.closed:
+ del _e_entry
+ else:
+ _e_entry.close()
+ del _e_entry
+
+ del i
+
+ # Text report
+ print("\033[0;33m Saving:", "\033[0;33m", end='')
+ b_report("Enforce arguments")
+
+ # Write lawful-good entries
+ if args.lawfulgood != None:
+ with open(_abs_state_name + '/lawfulgood_hooks', 'w') as _l_entry:
+ for i in range(len(args.lawfulgood[:])):
+ _l_entry.write("Hook " + str(i) + " : " + args.lawfulgood[i] + '\n')
+
+
+ if _l_entry.closed:
+ del _l_entry
+ else:
+ _l_entry.close()
+ del _l_entry
+
+ del i
+
+ # Text report
+ print("\033[0;33m Saving:", "\033[0;33m", end='')
+ b_report("Lawful-good arguments")
+
+ # Write do scripts
+ if args.sdir != None:
+ # Import shutil for enabling copy functionality
+ import shutil
+
+ # Create doscripts file with write permissions
+ with open(_abs_state_name + '/doscripts', 'w') as _do_entry:
+ # Text report
+ print("\033[0;33m Configuring:", "\033[0;33m", end='')
+ b_report("Do scripts")
+
+ # Write the directory path
+ _do_entry.write("Do scripts : Enabled" + '\n')
+ _do_entry.write("Path : " + args.sdir +'\n')
+
+ # Write the total number of scripts
+ _do_entry.write('\n')
+ _do_entry.write("Script's Num : " + str(len(args.do)) + '\n')
+
+ # Create do_scripts directory to host the requested do scripts
+ os.makedirs(_abs_state_name + '/do_scripts')
+
+ # Write the requested scripts entries and copy the script files at do_scripts
+ for i in range(len(args.do[:])):
+ _do_entry.write("Requested Script " + str(i) + " : " + args.do[i] + '\n')
+
+ try:
+ shutil.copy2(args.sdir + '/' + args.do[i], _abs_state_name + '/do_scripts', follow_symlinks=True)
+
+ except FileNotFoundError:
+ die("File not found error. If the scripts exist, please report this bug.")
+
+ except FileExistsError:
+ die("File exists error. Please report the bug!")
+
+ # Text report
+ print("\033[0;33m Saving:", "\033[0;33m", end='')
+ b_report("Scripts to state")
+
+ # Write the total hook's number. Must be equal to total script's number
+ _do_entry.write('\n')
+ _do_entry.write("Hook's Num : " + str(len(args.ghook)) + '\n')
+
+ # Write the requested scripts entries and copy the script files at do_scripts
+ for j in range(len(args.ghook[:])):
+ _do_entry.write("Requested Hook-Point " + str(i) + " : " + args.ghook[j] + '\n')
+
+ # Text report
+ print("\033[0;33m Saving:", "\033[0;33m", end='')
+ b_report("Hooks to state")
+
+ del i, j, shutil
+
+ if _do_entry.closed:
+ del _do_entry
+ else:
+ _do_entry.close()
+ del _do_entry
+
+ # Call system copy function
+ _copy_config_target(CCONFDIR, "system", _abs_state_name)
+
+ del _copy_config_target
+
+ elif args.target == 'controller':
+ # Create main_flags file under state directory and make it writable
+ with open(_abs_state_name + '/main_flags', 'w') as _s_entry:
+ _controller_entries = {}
+ _controller_entries["State name: "] = _state_name
+ _controller_entries["State target : "] = args.target
+ _controller_entries["System target: "] = "None"
+ _controller_entries["Build Controller: "] = args.controller
+ _controller_entries["Force: "] = args.force
+ _controller_entries["Dev: "] = args.dev
+ _controller_entries["Keep: "] = args.keep
+ _controller_entries["Minimal build: "] = args.minimal
+ _controller_entries["No checks: "] = args.nochecks
+ _controller_entries["Quiet :"] = args.quiet
+ _controller_entries["Verbose : "] = args.verbose
+
+ if args.hook == None:
+ _controller_entries["Hook scripts: "] = "None"
+ else:
+ _controller_entries["Hook scripts: "] = "Enabled"
+
+ if args.net == None:
+ _controller_entries["Net script: "] = "None"
+ else:
+ _controller_entries["Net script: "] = "Enabled"
+
+ if args.modules == None:
+ _controller_entries["Custom modules config: "] = "None"
+ else:
+ _controller_entries["Custom modules config: "] = "Enabled"
+
+ if args.dracut_opt == None:
+ _controller_entries["Dracut options: "] = "None"
+ else:
+ _controller_entries["Dracut options: "] = "Enabled"
+
+ # Write system enabled/disabled options
+ for key, value in _controller_entries.items():
+ _s_entry.write(str(key) + str(value) + '\n')
+
+ del _controller_entries, key, value
+
+ if _s_entry.closed:
+ del _s_entry
+ else:
+ _s_entry.close()
+ del _s_entry
+
+ # Call system copy function
+ _copy_config_target(CCONFDIR, "controller", _abs_state_name)
+
+ e_report("===========================================================================================")
+ e_report("State has been saved. To refer at this state in the future, use --time-warp=[state's mark]")
+ e_report("===========================================================================================")
+
+ # List states
+ elif args.timestate[0] == "list":
+ try:
+ if args.timestate[1]:
+ print("\033[0;33mTime state:", "\033[0;33m")
+ die(" Unknown " + args.timestate[1] + " option.")
+
+ except IndexError:
+ if os.path.isdir(CLOCALLG + "/states"):
+ _list_states = os.listdir(CLOCALLG + "/states/")
+
+ print("\033[0;33mStates list:", "\033[0;33m")
+ for i in _list_states[:]:
+ b_report(" " + i)
+
+ del _list_states, i
+
+ else:
+ print("\033[0;33mTime state:", "\033[0;33m")
+ b_report(" Nothing to show. No state has been saved!")
+
+ elif args.timestate[0] == 'set':
+ try:
+ if args.timestate[1]:
+ pass
+
+ if args.timestate[1] != '-':
+ if os.path.isdir(CLOCALLG + "/states"):
+ _list_states = os.listdir(CLOCALLG + "/states/")
+
+ _list_marks = []
+ for i in _list_states[:]:
+ _list_marks.append(i[0])
+
+ del _list_states, i
+
+ for j in _list_marks[:]:
+ if args.timestate[1] == j:
+ _set_state = str(j)
+ break
+ else:
+ _set_state = None
+
+ del _list_marks, j
+
+ if _set_state == None:
+ print("\033[0;33mTime state:", "\033[0;33m")
+ die(" No such a state mark.")
+ else:
+ try:
+ os.remove(CLOCALLG + "/states/default")
+ except FileNotFoundError:
+ pass
+
+ with open(CLOCALLG + "/states/default", 'w') as _set_default:
+ _set_default.write("Default : " + _set_state + '\n')
+
+ if _set_default.closed:
+ del _set_default
+ else:
+ _set_default.close()
+ del _set_default
+
+ print("\033[0;33mTime state:", "\033[0;33m")
+ b_report(" Default state has been set to: " + _set_state)
+ del _set_state
+ else:
+ print("\033[0;33mTime state:", "\033[0;33m")
+ die(" No state has been configured, hence none can be set.")
+
+ elif args.timestate[1] == '-':
+ if os.path.isfile(CLOCALLG + "/states/default"):
+ os.remove(CLOCALLG + "/states/default")
+
+ with open(CLOCALLG + "/states/default", 'w') as _set_default:
+ _set_default.write("Default : None" + '\n')
+
+ print("\033[0;33mTime state:", "\033[0;33m")
+ b_report(" Default state has been unset")
+
+ if _set_default.closed:
+ del _set_default
+ else:
+ _set_default.close()
+ del _set_default
+
+ except IndexError:
+ print("\033[0;33mTime state:", "\033[0;33m")
+ die(" Error: missing mark [M]. To unset a default entry give \'-\' instead of mark. See man 1 gse.")
+
+ elif args.timestate[0] == 'del':
+ try:
+ if args.timestate[1]:
+ pass
+
+ if os.path.isdir(CLOCALLG + "/states"):
+ _list_states = os.listdir(CLOCALLG + "/states/")
+
+ for i in _list_states[:]:
+ if args.timestate[1] == i[0]:
+ _del_state = str(i)
+ break
+ else:
+ _del_state = None
+
+ del _list_states, i
+
+ if _del_state == None:
+ print("\033[0;33mTime state:", "\033[0;33m")
+ die(" State does not exist.")
+ else:
+ import shutil
+ try:
+ shutil.rmtree(CLOCALLG + "/states/" + _del_state, ignore_errors=False, onerror=None)
+ print("\033[0;33mTime state:", "\033[0;33m")
+ b_report(" State: " + _del_state + " has been deleted")
+ del shutil
+
+ except FileNotFoundError:
+ print("\033[0;33mTime state:", "\033[0;33m")
+ die(" Error file not found. If the state exists, please report this bug.")
+
+ del _del_state
+
+ else:
+ print("\033[0;33mTime state:", "\033[0;33m")
+ die(" No state has been configured, hence none can be deleted.")
+
+ except IndexError:
+ die("Time-state: Error no state mark [M] was given")
+
+ else:
+ print("\033[0;33mTime state:", "\033[0;33m")
+ die(" No valid option. Please give --time-state [save/list/set/del] [sstate_name/-/M/M]")
+
+
+def warp(target, args, CWORKDIR, CCONFDIR, CLOCALLG):
+ '''
+ Warp function.
+ This is function is the function that controls all actions that are made after a sequence has been set and enabled.
+ Simply put, the _call_main function, which is the one initiated under the __init__ == __main__ condition, is only
+ checking / exporting environmental variables before calling this warp.
+ '''
+
+ # Check the arguments
+ if target is "system":
+ # system arguments
+ from gpyfunctions.tools.librarium import _check_args
+ _check_args(args)
+
+ del _check_args
+
+ elif target is "controller":
+ # controller arguments
+ from gpyfunctions.tools.librarium import _ct_check_args
+ _ct_check_args(args)
+
+ del _ct_check_args
+
+ # Call time state
+ if args.timestate is not 'no':
+ time_state(args, CWORKDIR, CCONFDIR, CLOCALLG)
+
+ exit(1)
+ return 0
+
+# _auto_def_silence_def "$@"
+
+# _flags_stagea+=("${_flag_base}")
+
+# if [[ -n "${_flag_base}" ]]; then
+# source "${CWORKDIR}/scripts/sinit" "${_flags_stagea[@]}"
+# elif [[ -z "${_flag_base}" && -n "${_flag_fetch}" ]]; then
+# _call_fetch_new "$@"
+# fi
+
+# # STAGE C
+# } \ No newline at end of file
diff --git a/scripts/sinit b/scripts/sinit
index 869f2ec..b025052 100755
--- a/scripts/sinit
+++ b/scripts/sinit
@@ -173,11 +173,13 @@ _part_b() {
# PART B BEGINS
_do_hs '\-gpartb' "before" "Part: B"
+
if _call_hook_points 'PARTB' "gpartb" 'Part: B' "_part_b" "${BWORKDIR}" "$@"; then
sinit_flow_monitor "PARTB"
else
die "Part: B FAILED"
fi
+
_do_hs '\+gpartb' "after" "Part: B"
if echo "${_flag_base}" | grep -q 'catalyst'; then
@@ -185,12 +187,3 @@ if echo "${_flag_base}" | grep -q 'catalyst'; then
elif echo "${_flag_base}" | grep -q 'precomp'; then
_archive_ "${BWORKDIR}" "precomp"
fi
-
-exit 1
-
-gpg --armor --export email > "${FINALDIST}/key.asc" # THIS WILL BE ADDED TO THE HOSTS
-gpg --detach-sign -o "${GSE_VER}".gpg "${FINALDIST}/${IMAGE}"
-#rm -rf "$1/sinit.d"
-unset CATDIR
-unset TARGETPATH
-unset TARGETSTAMP \ No newline at end of file