diff options
author | Christos.K <freedomrfox@gmail.com> | 2017-08-28 16:00:36 +0300 |
---|---|---|
committer | Christos.K <freedomrfox@gmail.com> | 2017-08-28 16:00:36 +0300 |
commit | 021a104842669863549e88c28336c7038aa6abfc (patch) | |
tree | 9463ee5c6601f33fd2370b0df7e63548eee73c20 | |
parent | Final chroot scripts for the configuration phase (diff) | |
download | GSE-021a104842669863549e88c28336c7038aa6abfc.tar.gz GSE-021a104842669863549e88c28336c7038aa6abfc.tar.bz2 GSE-021a104842669863549e88c28336c7038aa6abfc.zip |
Minor visual changes
-rwxr-xr-x | config.d/controller/modules/functions/ct_config.sh | 47 | ||||
-rwxr-xr-x | config.d/controller/modules/functions/ct_fetch.sh | 77 | ||||
-rwxr-xr-x | config.d/controller/modules/functions/ct_netf.sh | 25 | ||||
-rwxr-xr-x | config.d/controller/modules/functions/ct_newsys.sh | 5 | ||||
-rwxr-xr-x | config.d/controller/modules/functions/ct_prelim.sh | 109 |
5 files changed, 175 insertions, 88 deletions
diff --git a/config.d/controller/modules/functions/ct_config.sh b/config.d/controller/modules/functions/ct_config.sh index 7ae0c73..6ebdee2 100755 --- a/config.d/controller/modules/functions/ct_config.sh +++ b/config.d/controller/modules/functions/ct_config.sh @@ -1,27 +1,23 @@ #!/bin/bash _chroot_config(){ - _revert_chroot() { - if chroot "$1" "$2"; then - return 0 - else - return 1 - fi - } - _init_chroot() { - if chroot "$1" "$2"; then - echo "Configuration was successful" + if chroot "$1" "$2/cchroot.sh" "chroot"; then + echo -e "[\e[32m*\e[0m] 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" + 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 - echo "Failed reverting changes" - echo "Calling backup system" + _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 @@ -29,20 +25,19 @@ _chroot_config(){ _prep_chroot() { if _mount_sysfs "$1" && _mount_pseudos "$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" + 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 } - if _unmount "$1"; then - _prep_chroot "$@" - else - _sys_config=1 - export _sys_config - fi -}
\ No newline at end of file + echo -e "[\e[34m*\e[0m] Initiating chroot" + _prep_chroot "$@" +} diff --git a/config.d/controller/modules/functions/ct_fetch.sh b/config.d/controller/modules/functions/ct_fetch.sh index 631ea9d..fcdf6cb 100755 --- a/config.d/controller/modules/functions/ct_fetch.sh +++ b/config.d/controller/modules/functions/ct_fetch.sh @@ -7,18 +7,18 @@ _mount_sysfs() { _unmount "$1" fi - echo "Using fsck on ${SYSDEV}" + echo -e "[\e[34m*\e[0m] Using fsck on ${SYSDEV}" if fsck -y "${SYSDEV}" >/dev/null 2>&1; then - echo "Filesystem looks healthy" + echo -e "[\e[32m*\e[0m] Filesystem looks healthy" _fscheck=0 else - echo "Filesystem appears corrupted" - echo "Attempting to repair" + echo -e "[\e[33m*\e[0m] Filesystem appears corrupted" + echo -e "[\e[34m*\e[0m] Attempting to repair" if fsck -yf "${SYSDEV}"; then - echo "Repair was successful" + echo -e "[\e[32m*\e[0m] Repair was successful" _fscheck=0 else - echo "Automatic repair failed" + echo -e "[\e[31m*\e[0m] Automatic repair failed" _fscheck=1 fi fi @@ -29,12 +29,12 @@ _mount_sysfs() { unset _fscheck - echo "Attempting to mount ${SYSDEV} at $1" + echo -e "[\e[34m*\e[0m] Attempting to mount ${SYSDEV} at $1" if eval mount -t "${SYSFS}" -o rw -L "SYSFS" "$1"; then - echo "Mounted successfully" + echo -e "[\e[32m*\e[0m] Mounted successfully" return 0 else - echo "Failed mounting" + echo -e "[\e[31m*\e[0m] Failed mounting" return 1 fi } @@ -51,9 +51,29 @@ _fetch_version() { # FETCH NEW CONFIG.D DIRECTORY _fetch_confd() { - if rsync -aAPhrqc "${_ser_user}@${_ctserver}:${_conf_dir}/" "${CTCONFDIR}/confdir/" --delete; then - _ctflag_confd=0 + 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 @@ -72,16 +92,16 @@ _check_version() { _ctflag_sysfetch=1 fi else - echo "Remote version does not matches local" + echo -e "[\e[33m*\e[0m] Remote version does not matches local" _ctflag_sysfetch=0 fi else - echo "Remote version matches the local" + 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 "System is corrupted" - _call_backup_switch + echo -e "[\e[31m*\e[0m] System is corrupted" + _ctflag_sysfetch=9 fi export _ctflag_sysfetch fi @@ -94,15 +114,15 @@ _fetch_new_sys() { 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 "New system was fetched successfully" + #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 "Fetching new system FAILED" + echo -e "[\e[31m*\e[0m] Fetching new system FAILED" _ctflag_fetch=1 fi else - echo "Failed mounting ${SYSDEV} to $1" + echo -e "[\e[31m*\e[0m] Failed mounting ${SYSDEV} to $1" _ctflag_fetch=1 fi export _ctflag_fetch @@ -160,23 +180,23 @@ _verify_target() { _restricted() { if _check_last; then - echo "Origin verified" + echo -e "[\e[35m*\e[0m] Origin verified" _md5_check "$1" else if [[ ! -e "${CTSCRIPTS}/gpg/gpg_pub" ]]; then - echo "No gpg key found!" + echo -e "[\e[33m*\e[0m] No gpg key found!" _md5_check "$1" elif [[ -e "${CTSCRIPTS}/gpg/gpg_pub" ]]; then - echo "Failed to verify the authentication of the image" + 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 "Integrity verified" + echo -e "[\e[35m*\e[0m] Integrity verified" else - echo "Integrity check failed" + echo -e "[\e[33m*\e[0m] Integrity check failed" fi export _ctflag_verify } @@ -184,13 +204,16 @@ _verify_target() { _extract_sys() { ( cd "$1" - echo "Extracting system tarball..." + _e_report_back "Extracting system tarball..." if tar xvjpf "$2" --xattrs --numeric-owner >/dev/null; then - echo "Extracted" + echo -e "[\e[32m*\e[0m] Extracted" echo "PASS" > "/tmp/verify.info" else - echo "An error occured" + 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 index 0b0b726..b0a1660 100755 --- a/config.d/controller/modules/functions/ct_netf.sh +++ b/config.d/controller/modules/functions/ct_netf.sh @@ -34,10 +34,10 @@ _server_exp() { # POPULATE THE ABOVE TWO ARRAYS while read -r s; do - echo "Checking $s" + _e_report_back "Checking $s" # DROP AN ENTRY IF PING FAILS if ping -c 1 "$s" >/dev/null 2>&1; then - echo "Connection for $s is true" + 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 @@ -47,13 +47,13 @@ _server_exp() { _act_ser_ar+=("${avms}") else # SKIP ENTRY - echo "Could not get average value for $i" - echo "Rejecting this 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 "Connection with $s could not be established" - echo "Rejecting this 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}') @@ -74,7 +74,7 @@ _server_exp() { done # 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}" + _o_report_back "Most effective server is: ${_act_ser} with average ms: ${_min_ms}" _ctserver="${_act_ser}" export _ctserver @@ -86,7 +86,7 @@ _server_exp() { unset avms } - echo "Selecting server..." + echo -e "[\e[34m*\e[0m] Selecting server..." if [[ -e "/usr/bin/netselect" ]]; then _ser_tmp=() @@ -99,7 +99,7 @@ _server_exp() { for i in $(netselect -v -t2 -s10 "${_ser_tmp[@]}" | awk -F ' ' '{print $2}'); do _ser_list+=("$i") - echo "$i" + _e_report_back "$i" done unset _ser_tmp @@ -116,7 +116,7 @@ _check_net() { else if grep -q "net:0" "/usr/local/unet/udent_flag"; then # RE-SOURCE THE CUSTOM NET SCRIPT AND CHECK AGAIN - echo "Re-sourcing the custom net script" + 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 @@ -143,4 +143,7 @@ _check_net() { return 1 fi fi -}
\ No newline at end of file +} + + + diff --git a/config.d/controller/modules/functions/ct_newsys.sh b/config.d/controller/modules/functions/ct_newsys.sh index 5e8bd53..5ffa5d1 100755 --- a/config.d/controller/modules/functions/ct_newsys.sh +++ b/config.d/controller/modules/functions/ct_newsys.sh @@ -34,4 +34,7 @@ _remake_dev() { _ctflag_remake=1 fi export _ctflag_remake -}
\ No newline at end of file +} + + + diff --git a/config.d/controller/modules/functions/ct_prelim.sh b/config.d/controller/modules/functions/ct_prelim.sh index 4db040b..107e677 100755 --- a/config.d/controller/modules/functions/ct_prelim.sh +++ b/config.d/controller/modules/functions/ct_prelim.sh @@ -6,8 +6,14 @@ die() { } _call_backup_switch() { - _ctflag_switch=0 - export _ctflag_switch + if [[ "${_ctflag_bconf}" != 0 && "${_ctflag_setup}" != 0 && "${_ctflag_setup}" != 1 ]]; 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() { @@ -42,7 +48,56 @@ _bsu_dfs() { 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 @@ -90,18 +145,18 @@ _mount_target() { _unmount "$1" fi - echo "Using fsck on $2" + echo -e "[\e[34m*\e[0m] Using fsck on $2" if fsck -y "$2" >/dev/null 2>&1; then - echo "Filesystem looks healthy" + echo -e "[\e[32m*\e[0m] Filesystem looks healthy" _fscheck=0 else - echo "Filesystem appears corrupted" - echo "Attempting to repair" + echo -e "[\e[33m*\e[0m] Filesystem appears corrupted" + echo -e "[\e[34m*\e[0m] Attempting to repair" if fsck -yf "$2"; then - echo "Repair was successful" + echo -e "[\e[32m*\e[0m] Repair was successful" _fscheck=0 else - echo "Automatic repair failed" + echo -e "[\e[31m*\e[0m] Automatic repair failed" _fscheck=1 fi fi @@ -112,12 +167,12 @@ _mount_target() { unset _fscheck - echo "Attempting to mount $3 at $1" + echo -e "[\e[34m*\e[0m] Attempting to mount $3 at $1" if eval mount -t "$2" -o rw -L "$3" "$1"; then - echo "Mounted successfully" + echo -e "[\e[32m*\e[0m] Mounted successfully" return 0 else - echo "Failed mounting" + echo -e "[\e[31m*\e[0m] Failed mounting" return 1 fi } @@ -194,14 +249,17 @@ _check_rbfs() { unset _ctflag_setup if [[ "${_rfs_check}" == 1 && "${_bfs_check}" == 1 ]]; then - echo "Neither one of SYSFS or BACKUPFS appear to host a root system" + 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 "SYSFS appears to be missing" + echo -e "[\e[33m*\e[0m] SYSFS appears to be missing" _ctflag_setup=1 elif [[ "${_rfs_check}" == 0 && "${_bfs_check}" == 1 ]]; then - echo "BACKUPFS is missing, fixing..." + 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 @@ -235,17 +293,20 @@ _unset_ct() { 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" ]] && echo "$i" + [[ "$i" ]] && _e_report_back "$i" done while true; do - echo "Answer: Y/N " + _e_report_back "Answer: Y/N " read -rp "Input :: <= " ANS case "${ANS}" in [yY]) @@ -280,8 +341,8 @@ _rescue_shell() { echo "$i" done - echo "Do you wish to call shell function and fix the issues manually?" - echo "Answer Y/N " + _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]) @@ -297,9 +358,9 @@ _rescue_shell() { 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: " + _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 ) @@ -345,7 +406,7 @@ _unmount() { fi if [[ "$k" -ge 20 ]]; then - echo "Could not unmount target $1" + echo -e "[\e[31m*\e[0m] Could not unmount target $1" return 1 fi sleep 0.1 @@ -355,4 +416,6 @@ _unmount() { return 0 fi -}
\ No newline at end of file +} + + |