aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos.K <freedomrfox@gmail.com>2017-07-06 21:35:04 +0300
committerChristos.K <freedomrfox@gmail.com>2017-07-06 21:35:04 +0300
commit188ebd3c7b148220ea556348ac4a48329ee8d845 (patch)
treea94af65972d57d9b993550ea9b044fab01c70998
parentIncluded controller modules (diff)
downloadGSE-188ebd3c7b148220ea556348ac4a48329ee8d845.tar.gz
GSE-188ebd3c7b148220ea556348ac4a48329ee8d845.tar.bz2
GSE-188ebd3c7b148220ea556348ac4a48329ee8d845.zip
Updated controller modules (still very unstable)
-rw-r--r--config.d/controller/modules/cfunctions.sh207
-rw-r--r--config.d/controller/modules/cinit_pre-mount.sh57
-rw-r--r--config.d/controller/modules/cnetwork.sh31
-rwxr-xr-xconfig.d/controller/modules/module-setup.sh18
4 files changed, 242 insertions, 71 deletions
diff --git a/config.d/controller/modules/cfunctions.sh b/config.d/controller/modules/cfunctions.sh
index f91dfd4..ae50300 100644
--- a/config.d/controller/modules/cfunctions.sh
+++ b/config.d/controller/modules/cfunctions.sh
@@ -1,42 +1,223 @@
#!/bin/bash
+die() {
+ echo "$@" 1>&2 ; exit 1
+}
+
_bsu_dfs() {
# EXPORT BOOT DEVICE
- BOOTDEV="$(cat devname.info | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $2 }')"
+ BOOTDEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $2 }')"
export BOOTDEV
# EXPORT SYSTEM DEVICE
- SYSDEV="$(cat devname.info | sed '/^#/ d' | sed '/^\s*$/d' | grep SYS | awk -F ' ' '{ print $2 }')"
+ 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 devname.info | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $2 }')"
+ USERDATADEV="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $2 }')"
export USERDATADEV
- # SOURCE THE SOURCES CONFIGURATION FILES FOR EXPORTING THE SERVER INFORMATIONS
- source "${CTCONFDIR}/sources/sources.conf"
-
# EXPORT THE BOOT FILE SYSTEM TYPE
- BOOTFS="$(cat fstab.info | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $2 }')"
+ 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 fstab.info | sed '/^#/ d' | sed '/^\s*$/d' | grep SYS | awk -F ' ' '{ print $2 }')"
+ 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 fstab.info | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $2 }')"
+ USERDATAFS="$(cat "${CTCONFDIR}/confdir/fstab.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $2 }')"
export USERDATAFS
# EXPORT BOOT SIZE
- BOOTSFS="$(cat devname.info | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $3 }')"
+ BOOTSFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep BOOT | awk -F ' ' '{ print $3 }')"
export BOOTSFS
# EXPORT SYSTEM SIZE
- SYSSFS="$(cat devname.info | sed '/^#/ d' | sed '/^\s*$/d' | grep SYS | awk -F ' ' '{ print $3 }')"
+ 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 devname.info | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $3 }')"
+ USERDATASFS="$(cat "${CTCONFDIR}/confdir/devname.info" | sed '/^#/ d' | sed '/^\s*$/d' | grep USERDATA | awk -F ' ' '{ print $3 }')"
export USERDATASFS
-} \ No newline at end of file
+
+ _sources_exp
+}
+
+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 mount -t "${SYSFS}" -o rw "${SYSDEV}" "/mnt/workdir"; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+_call_backup_switch() {
+ _ctflag_active_system="BACKUPDEV"
+ export _ctflag_active_system
+}
+
+_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}/${_conf_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 [[ -z "${_ctflag_nohuman}" ]]; 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
+ export _ctflag_sysfetch
+ else
+ _ctflag_sysfetch=0
+ export _ctflag_sysfetch
+ fi
+ else
+ echo "Remote version matches the local"
+ fi
+}
+
+_remake_sysfs() {
+ if umount "/mnt/workdir"; then
+ if [[ "${SYSFS}" == 'btrfs' ]]; then
+ if eval "mkfs.${SYSFS}" -L ROOTFS -f "${SYSDEV}"; then
+ echo "File system created"
+ else
+ echo "Failed creating new filesystem"
+ _call_backup_switch
+ fi
+ else
+ if eval "mkfs.${SYSFS}" -L ROOTFS "${SYSDEV}"; then
+ echo "File system created"
+ else
+ echo "Failed creating new filesystem"
+ _call_backup_switch
+ fi
+ fi
+ else
+ echo "Failed unmounting workdir"
+ _call_backup_switch
+ fi
+}
+
+_fetch_new_sys() {
+ if _mount_sysfs; then
+ if sync -aAXhq "${_M_SERVER}/dist.d/stage3-amd64-${_server_version}.tar.bz2" "${CTCONFDIR}/version"; then
+ echo "New system was fetched successfully"
+ _ctflag_active_system="SYSDEV"
+ else
+ echo "Fetching new system FAILED"
+ _call_backup_switch
+ fi
+ else
+ echo "Failed mounting ${SYSDEV} to /mnt/workdir"
+ _call_backup_switch
+ fi
+}
diff --git a/config.d/controller/modules/cinit_pre-mount.sh b/config.d/controller/modules/cinit_pre-mount.sh
index 41b1b60..0457a9b 100644
--- a/config.d/controller/modules/cinit_pre-mount.sh
+++ b/config.d/controller/modules/cinit_pre-mount.sh
@@ -16,58 +16,9 @@ source "${CTSCRIPTS}/cfunctions.sh"
source "${CTSCRIPTS}/cnetwork.sh"
-if [[ "${_ctflag_net}" ]]; then
- # SYNC CONF.D DIRECTORY FROM SERVER TO LOCAL
- rsync -aAXhrq "${_M_SERVER}/config.d/controller/" "${CTCONFDIR}/confdir/"
-
- # EXPORT NEW CONFIGS
- _bsu_dfs
-
- # COPY VERSION REGISTERED AS DEFAULT FROM THE SERVER
- if rsync -aAXhq "${_M_SERVER}/local/version" "${CTCONFDIR}/version"; then
- if mount -t "${SYSFS}" -o rw "${SYSDEV}" "/mnt/workdir"; then
- _local_version="$(cat "/mnt/workdir/var/lib/version")"
- _server_version="$(cat "${CTCONFDIR}/version")"
- if [[ "${_local_version}" != "${_server_version}" ]]; then
- if [[ -z "${_ctflag_nohuman}" ]]; then
- echo "A new system version is present on the server"
- echo "Do you wish to fetch the new system?"
- while true; do
- echo "Answer: Y/N "
- read -rp "Input :: <= " ANS
- case "${ANS}" in
- [yY])
- if umount "/mnt/workdir"; then
- if [[ "${SYSFS}" == 'btrfs' ]]; then
- eval "mkfs.${SYSFS}" -L ROOTFS -f "${SYSDEV}"
- else
- eval "mkfs.${SYSFS}" -L ROOTFS "${SYSDEV}"
- fi
- else
- _rescue_shell "Could not umount ${SYSDEV} from /mnt/workdir"
- fi
-
- if mount -t "${SYSFS}" -o rw "${SYSDEV}" "/mnt/workdir"; then
- if sync -aAXhq "${_M_SERVER}/dist.d/stage3-amd64-${_server_version}.tar.bz2" "${CTCONFDIR}/version"; then
- echo "New system was fetched successfully"
- else
- echo "Fetching new system FAILED"
- fi
-
- else
- _rescue_shell "Could not mount ${ROOTFS} to /mnt/workdir"
+# WIPE OLD FS, CREATE NEW FS & FETCH NEW SYSTEM
+if [[ "${_ctflag_sysfetch}" == 0 ]]; then
+ _remake_sysfs
+ _fetch_new_sys
fi
-# IF NETWORKING IS ESTABLISHED
-# CHECK IF THERE ARE ANY CHANGES IN THE CONFIG.D DIRECTORY
-# IF CHANGES EXIST
-# FETCH CONFIG.D DIRECTORY
-# EXPORT NEW CONFIG.D CONFIGURATIONS
-# ASK FOR VERSION
-
-# COMPARE LOCAL VERSION WITH THE FETCHED ONE
-# IF THEY DONT MATCH OR IF THE LOCAL ONE IS MISSING
-# PROMPT TO WIPE SYSFS
-# CREATE NEW SYSFS
-# FETCH NEW IMAGE FROM THE SERVER
-# EXPORT THE IMAGE
diff --git a/config.d/controller/modules/cnetwork.sh b/config.d/controller/modules/cnetwork.sh
index 84c6573..7588f57 100644
--- a/config.d/controller/modules/cnetwork.sh
+++ b/config.d/controller/modules/cnetwork.sh
@@ -1,4 +1,31 @@
#!/bin/bash
-ifconfig eth0 up
-udhcpc -t 5 -q -s "/bin/net_script.sh"
+# SIMPLE DHCP NETWORKING
+if _call_net; then
+ _ctflag_net=0
+ export _ctflag_net
+fi
+
+# CONFIG.D LOCATION
+# DIST.D LOCATION
+
+# CHECK NETWORK FLAG AND FETCH VERSION AND CONFIG.D DIRECTORY
+if [[ "${_ctflag_net}" ]]; then
+ # DEFINE BEST ACTIVE SERVER
+ _server_exp
+
+ # SOURCES EXP
+ _sources_exp
+
+ # FETCH CONFIG.D
+ _fetch_confd
+ if [[ "$_ctflag_confd}" == 0 ]]; then
+ # EXPORT NEW CONFIGS
+ _bsu_dfs
+ fi
+
+ # MOUNT SYSFS AS RO
+ _mount_sysfs
+ # CHECK LOCAL VERSION OF SYSFS WITH SERVERS VERSION
+ _check_version
+fi \ No newline at end of file
diff --git a/config.d/controller/modules/module-setup.sh b/config.d/controller/modules/module-setup.sh
index 8af87a5..98eba63 100755
--- a/config.d/controller/modules/module-setup.sh
+++ b/config.d/controller/modules/module-setup.sh
@@ -20,7 +20,7 @@ install() {
cp mv busybox rsync ssh gpg bash rmmod dmesg modprobe findmnt \
tar bzip2 ping clear mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.btrfs mkfs.vfat \
e2label mlabel swaplabel scp md5sum sha512sum lsblk tee sed awk arping \
- dhclient
+ dhclient ifconfig
inst_simple "/lib64/libnss_dns.so.2"
inst_simple "/lib64/libnss_files.so.2"
@@ -68,7 +68,19 @@ install() {
inst_simple "${CHDIR}/controller/csystem_links" "/config.d/confdir/system_links"
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 mount 01 "$moddir/cinit_mount.sh"
+ inst_hook clean 01 "$moddir/cinit_clean.sh"
}
+
+# called by dracut
+installkernel() {
+ instmods "=drivers"
+ instmods "=arch"
+ instmods "=crypto"
+ instmods "=fs"
+ instmods "=lib"
+ instmods "=mm"
+ instmods "=net"
+ instmods "=sound"
+} \ No newline at end of file