#!/bin/bash ## ## # # # Gentoo Stateless Environment project # # # # Everything inside this directory has been created during Gentoo-soc 2017 and is distributed # # under General Public License version 2. # # # ## ## # 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 export PATH=${PATH}:${CWORKDIR}/scripts/functions source "${CWORKDIR}/scripts/functions/sinit_functions" || { echo -e "\e[31mMissing scripts\e[0m" && exit 1; } 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; } # ROOT CHECK FUNCTION, IS NEEDED FOR THE CATALYST AND CHROOT PROCESS amiroot() { if [[ "$1" != "0" ]] then echo "This operation requires root privileges" echo "Returning back..." sleep 2 BACKTO="MM" fi } subterm_f() { echo -e "\e[33mCalling bash subshell\e[0m" sleep 0.5 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 "${lppar[@]}";) 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" } # MENU FUNCTION _call_menu() { echo "${@}" unset _PARENT unset _CHILD unset _STAY echo "$_PARENT" echo "$_CHILD" echo "$_STAY" while true; do clear; men_opt "$1" eval "$4" #"${@:5}" if [[ "${_PARENT}" ]]; then BACKTO="$2" break elif [[ "${_CHILD}" ]]; then BACKTO="${_CHILD}" break elif [[ "${_STAY}" ]]; then BACKTO="$3" break fi done unset SELCT } # MAIN LOOP FUNCTION mainlp_f() { BACKTO="$1" while true; do case "${BACKTO:-Q}" in MM ) # PULLS MAIN MENU FUNCTION _call_menu "1" "Q" "MM" "main_f" "${lppar[@]}";; DOC ) # PULLS DOCUMENTATION MENU FUNCTION _call_menu "2" "MM" "DOC" "doc_f";; AB ) # PULLS ABOUT MENU FUNCTION _call_menu "3" "MM" "DOC" "about_f";; PORT_M ) # PULLS PORTAGE SUBMENU FUNCTION _call_menu "7" "SM" "PORT_M" "portage_men_f" "${lppar[@]}";; CATA_M ) _call_menu "10" "SM" "CATA_M" "catalyst_f" "${lppar[@]}";; SM ) # PULLS BUILD SYSTEM SUBMENU: THIS IS A SUBMENU OF BULDERS MENU _call_menu "6" "BSM" "SM" "bs_f" "${lppar[@]}";; BSM ) # PULLS BUILDER MENU _call_menu "5" "MM" "BSM" "bs_menu_f" "${lppar[@]}";; CO_F ) # PULLS CONFIGURATION SUBMENU: SUBMENU OF BUILDERS MENU _call_menu "8" "BSM" "CO_F" "config_f" "${lppar[@]}";; SELDEF ) # PULLS SELECT DEFAULT SYSTEM SUBMENU: SUBMENU OF BUILDERS MENU _call_menu "9" "BSM" "SELDEF" "selectdef_f" "${lppar[@]}";; GSET ) # PULL GSE TOOLS SUBMENU _call_menu "11" "MM" "GSET" "gse_t" "${lppar[@]}";; CONTR ) _call_menu '' "MM" "CONTR" "controller_f" "${lppar[@]}";; Q ) # EXIT sleep 1 break;; esac done } 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 [[ ! -e "${1#*=}" ]]; then die "No such file or directory" fi if [[ -d "${1#*=}" ]]; then die "Target is a directory, aborting" fi 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 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