#!/bin/bash if echo "${_flag_tty}" | grep -q 'sshd'; then LC_COLLATE="C" LC_ALL="en_US.UTF-8" LC_CTYPE="en_US.UTF-8" fi if [[ -z "${_flag_base}" ]]; then _e_report_back "You must choose a base if your run gse without main menu. Aborting..." _e_report_back "See man 1 gse for base options." die "Aborting actions..." fi # ENVIROMENTAL ECHO FOR TESTING echo "$@" # STAGE A clear echo "============================================================================" echo -e "\e[35m PART:A Fundamentals\e[0m" echo "============================================================================" echo -e "[\e[32m*\e[0m] \e[34mInitializing\e[0m" # ALL ESSENTIAL VARIABLES FOR THE DOWNLOAD AND AUTHENTICATION PROCESS source "${CWORKDIR}/etc/gentoo.conf" >/dev/null 2>&1 \ && echo -e "[\e[32m*\e[0m] \e[35mExporting variables\e[0m" \ || { echo -e "[\e[31m*\e[0m] \e[35mExporting variables\e[0m"; echo -e "\e[31mAborting\e[0m..."; sleep 2; return 1; } # CHECK POSITIONAL PARAMETERS inspector "$@" # PART A FUNDAMENTALS _part_a() { # CHECK IF THERE IS ANY WORK DONE if [[ "$(awk -F '=' '/CHECK/{ print $2 }' < "${CLOCALLG}/sinprog")" == 1 ]]; then if echo "${_flag_base}" | grep -q 'catalyst'; then _start_again "${CDISTDIR}/workdir-catalyst" "$@" elif echo "${_flag_base}" | grep -q 'precomp'; then _start_again "${CDISTDIR}/workdir-precomp" "$@" fi elif echo "$@" | grep -q 'force'; then if echo "${_flag_base}" | grep -q 'catalyst'; then _start_again "${CDISTDIR}/workdir-catalyst" "$@" "force" elif echo "${_flag_base}" | grep -q 'precomp'; then _start_again "${CDISTDIR}/workdir-precomp" "$@" "force" fi fi # CALL CATALYST BUILD OR PRECOMPILED BUILD case "${_flag_base}" in catalyst ) echo "$@" # PART NETWORK SEED _do_hs '\-gseed' "before" "seed part" _seed_net() { if [[ $(echo "${_flag_network}") == 0 ]]; then if _call_hook_points 'SEED' 'gseed' 'Part: Fetch tarball' "_fetch_new" "$@"; then sinit_flow_monitor "SEED" else die "Fetching tarball FAILED" fi elif [[ ! -e "${CDISTDIR}/dists/stage3-${ARCH}-latest.tar.bz2" ]]; then die "No local tarball is present. Please enable network connection and try again" elif [[ -e "${CDISTDIR}/dists/stage3-${ARCH}-latest.tar.bz2" ]]; then _e_report_back "Stage3 tarball located" _e_report_back "Calling catalyst" fi } _seed_net "$@" _do_hs '\+gseed' "after" "seed part" # PART CATALYST _do_hs '\-gcat' "before" "catalyst part" if _call_hook_points 'CATALYST' 'gcat' 'Part: Catalyst' "_callying_catalyst" "$@"; then sinit_flow_monitor "CATALYST" else die "Part: Catalyst FAILED" fi _do_hs '\+gcat' "after" "Catalyst" # PART CATALYST STAGE3 AND PORTAGE SNAPSHOT EXTRACTION _do_hs '\-gextr' "before" "Catalyst Extraction" if _call_hook_points 'EXTRACTION' 'gextr' 'Part: Catalyst Extraction' "_extracting_catalyst" "$@"; then sinit_flow_monitor "EXTRACTION" else die "Part: Catalyst Extraction FAILED" fi _do_hs '\+gextr' "after" "Catalyst Extraction" unset CATDIR unset TARGETNAME unset TARGETPATH unset TARGETSTAMP ;; precomp ) # PART NETWORK SEED _do_hs '\-gseed' "before" "seed part" _seed_net() { if [[ $(echo "${_flag_network}") == 0 ]]; then if _call_hook_points 'SEED' 'gseed' 'Part: Fetch tarball' "_fetch_new" "$@"; then sinit_flow_monitor "SEED" else die "Fetching tarball FAILED" fi elif [[ ! -e "${CDISTDIR}/dists/stage3-${ARCH}-latest.tar.bz2" ]]; then die "No local tarball is present. Please enable network connection and try again" elif [[ -e "${CDISTDIR}/dists/stage3-${ARCH}-latest.tar.bz2" ]]; then _e_report_back "Stage3 tarball located" _e_report_back "Calling catalyst" fi } _seed_net "$@" _do_hs '\+gseed' "after" "seed part" # PART PRECOMP STAGE3 EXTRACTION _prec_workdir_function() { _workdir_check "$1" "$2" "${@:3}" || die } _do_hs '\-gprec' "before" "Precomp extraction" if _call_hook_points 'PRECOMP' 'gprec' 'Part: prec' "_prec_workdir_function" "${CDISTDIR}/dists/stage3-${ARCH}-latest.tar.bz2" "${CDISTDIR}/workdir-precomp" "$@"; then sinit_flow_monitor "PRECOMP" else die "Part: Precomp FAILED" fi _do_hs '\+gprec' "after" "Precomp extraction" ;; esac } # PART A BEGINS _do_hs '\-gparta' "before" "Part: A" if _call_hook_points 'PARTA' "gparta" 'Part: A' "_part_a" "$@"; then sinit_flow_monitor "PARTA" else die "Part: A FAILED" fi _do_hs '\+gparta' "after" "Part: A" # EXPORT WORKDIR case "${_flag_base}" in catalyst ) BWORKDIR="${CDISTDIR}/workdir-catalyst";; precomp ) BWORKDIR="${CDISTDIR}/workdir-precomp";; esac # PART B FUNCTION _part_b() { echo "============================================================================" echo -e "\e[35m PART: B Preparing to enter the new system\e[0m" echo "============================================================================" if _am_i_root "$UID"; then echo -e "[\e[32m*\e[0m] Requesting root privileges" else die "Requesting root privileges" fi if _prepare_chroot "$@"; then _do_hs '\-gclean' "before" "clean part" _clean_target "$@" || die _do_hs '\+gclean' "after" "clean part" else die "Cleaning failed" fi } # 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 _archive_ "${BWORKDIR}" "catalyst" 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