#!/bin/bash # GET LATEST PORTAGE SNAPSHOT, CREATE GSE PROFILE AND LAST INITIATE THE STAGE 1,2,3 BUILD SEQUENCE if echo "${_flag_tty}" | grep -q 'sshd'; then LC_COLLATE="C" LC_ALL="en_US.UTF-8" LC_CTYPE="en_US.UTF-8" fi # INSPECTOR inspector "$@" source "${CWORKDIR}/scripts/functions/catalyst_functions" || die "Missing scripts" # EXPORT THE DIRECTORIES DEFINED BY STAGE1.SPEC _export_catalyst_workdirs # CREATE DIRECTORIES FOR CATALYST _create_catalyst_workdirs # CHECK IF STAGE3 TARBALL IS PRESENT AT THE INDICATED DIRECTORY _target_paths "1" if [[ ! -e "${CATDIR}/builds/${TARGETPATH}/${TARGETNAME}.tar.bz2" ]]; then cp "${CDISTDIR}/dists/stage3-${ARCH}-latest.tar.bz2" "${CATDIR}/builds/${TARGETPATH}/${TARGETNAME}.tar.bz2" fi # CHECK IF SNAPSHOT EXISTS AND HAS NORMAL SIZE check_portage_snap() { if [[ ! -e "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2" ]] || ! _snapshot_checkup "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2"; then # REMOVE THE SNAPSHOT IF IT EXISTS BUT SEEMS HEAVILY MODIFIED rm -f "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2" >/dev/null 2>&1 while true; do _copt echo -e "[\e[31m*\e[0m] Could not locate snapshots/portage-${SNAPSHOTNAME}.tar.bz2 @ ${CATDIR}/snapshots" echo "Please select an option" read -rp "Input :: <= " ANS case "$ANS" in I|i|1) _get_latest_snapshot "$@" && BRKVAR=0 || BRKVAR=1 ;; II|ii|2) echo "Please enter the absolute path with the snapshot included: " read -rp "Input :: <= " PATHTOSNAP if [[ -n "${PATHTOSNAP}" ]] && _snapshot_checkup "${PATHTOSNAP}"; then cp "${PATHTOSNAP}" "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2" \ && echo -e "\e[34mCopying snapshot to ${CATDIR}/snapshots\e[0m" && BRKVAR=0 || BTWRK=1 else echo -e "\e[31mThe file you entered is either a heavily modified snapshot or not a snapshot" while true; do echo "Do you wish to proceed? Y/N" read -rp "Input :: <= " YN case "${YN:-n}" in [yY][eE][sS]|[yY]) echo -e "\e[34mCopying file to ${CATDIR}/snapshots\e[0m" cp "${PATHTOSNAP}" "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2\e[0m" \ && BRKVAR=0 || BRKVAR=1 break;; [nN][oO]|[nN]) BRKVAR=1 break;; esac done fi unset PATHTOSNAP unset YN break;; III|iii|3) echo -e "\e[32mSearching\e[0m..." _search_snapshot && echo -e "\e[32mChecking\e[0m..." || { echo -e "\e[31mCould not locate the snapshot\e[0m"; BRKVAR=1; } echo -e "[\e[32m*\e[0m] Located the snapshot" if _snapshot_checkup "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2"; then echo -e "[\e[32m*\e[0m] Snapshot seems normal" BRKVAR=0 else echo -e "[\e[31m*\e[0m] Snapshot located but it's size is out of normal boundaries" while true; do echo "Do you wish to continue? Y/N " read -rp "Input :: <= " YN case "${YN:-n}" in [yY][eE][sS]|[yY]) echo -e "[\e[32m*\e[0m] Proceeding" BRKVAR=0 break;; [nN][oO]|[nN]) echo -e "[\e[31m*\e[0m] Returning options" BRKVAR=1 break;; esac done fi ;; IV|iv|4) echo "\e[35mOpening new shell, please copy your snapshot to ${CATDIR}/snapshots with name: portage-${SNAPSHOTNAME}.tar.bz2\e[0m" _csubshell if [[ -e "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2" ]]; then echo -e "\e[32mChecking\e[0m..." if _snapshot_checkup "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2"; then echo -e "[\e[32m*\e[0m] Snapshot seems normal" BRKVAR=0 else echo -e "[\e[31m*\e[0m] Snapshot located but it's size is out of normal boundaries" while true; do echo "Do you wish to continue? Y/N " read -rp "Input :: <= " YN case "${YN:-n}" in [yY][eE][sS]|[yY]) echo -e "[\e[32m*\e[0m] Proceeding" BRKVAR=0 break;; [nN][oO]|[nN]) echo -e "[\e[31m*\e[0m] Returning options" BRKVAR=1 break;; esac done fi else echo -e "[\e[31m*\e[0m] Could not locate the snapshot" echo -e "[\e[31m*\e[0m] Returning options" BRKVAR=1 fi ;; V|v|5) if [[ (($(ls -A "${CATPORTDIR}" | grep 'app-portage') != 'app-portage')) ]]; then echo -e "[\e[32m*\e[0m] ${CATPORTDIR} does not look like a normal portage location" while true; do echo "Do you wish to continue? Y/N " read -rp "Input :: <= " YN case "${YN:-n}" in [yY][eE][sS]|[yY]) _snapshot_builder && echo -e "[\e[32m*\e[0m] Built" || echo -e "[\e[31m*\e[0m] Failed" ;; [nN][oO]|[nN]) while true; do echo "Do you wish to give a new portdir location? Y/N " read -rp "Input :: <= " case $YN in [yY][eE][sS]|[yY]) echo "Portdir's absolute path: " read -rp "Input :: <= " CATPORTDIR if [[ (($(ls -A "${CATPORTDIR}" | grep 'app-portage') != 'app-portage')) ]]; then echo "Neither this location looks to contain a normal portage directory" while true; do echo "Do you wish to proceed? Y/N " read -rp "Input :: <= " case $YN in [yY][eE][sS]|[yY]) export CATPORTDIR _snapshot_builder && echo -e "[\e[32m*\e[0m] Built" || echo -e "[\e[31m*\e[0m] Failed" ;; [nN][oO]|[nN]) echo -e "[\e[31m*\e[0m] Returning back to options" BRKVAR=1 break;; esac done else _snapshot_builder && echo -e "[\e[32m*\e[0m] Built" || echo -e "[\e[31m*\e[0m] Failed" fi break;; [nN][oO]|[nN]) echo -e "[\e[32m*\e[0m] Built" || echo -e "[\e[31m*\e[0m] Failed" BRKVAR=1 break;; esac done ;; esac done else _snapshot_builder && echo -e "[\e[32m*\e[0m] Built" || echo -e "[\e[31m*\e[0m] Failed" fi ;; esac [[ "${BRKVAR}" == 0 ]] && break done else echo -e "\e[32mPrtage snapshot found @ ${CATDIR}/snapshots\e[0m" fi unset BRKVAR } if echo "$@" | grep -q 'force' || echo "$@" | grep -q '_flag_auto'; then echo -e "\e[33mSearching for portage snapshot...\e[0m" if [[ ! -e "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2" ]]; then echo -e "\e[31mForce is active!\e[0m" echo -e "\e[33mCould not locate snapshot\e[0m" echo -e "\e[33mAttempting to fetch new...\e[0m" if _get_latest_snapshot "$@"; then _o_report_back "Fetched" else echo -e "\e[34mCreating snapshot...\e[0m" if catalyst -s "${SNAPSHOTNAME}"; then _o_report_back "Created" else die "FAILED" fi fi fi else check_portage_snap fi # STAGE 1 _call_stagex "${CATDIR}/builds/${TARGETPATH}/${TARGETNAME}.tar.bz2" "1" "$@" unset TARGETNAME unset TARGETPATH unset TARGETSTAMP unset SNAPSHOTNAME _target_paths "2" # STAGE 2 _call_stagex "${CATDIR}/builds/${TARGETPATH}/stage1-${ARCH}-${TARGETSTAMP}.tar.bz2" "2" "$@" unset TARGETNAME unset TARGETPATH unset TARGETSTAMP unset SNAPSHOTNAME _target_paths "3" # STAGE 3 _call_stagex "${CATDIR}/builds/${TARGETPATH}/stage2-${ARCH}-${TARGETSTAMP}.tar.bz2" "3" "$@" unset ANS unset TARGETNAME unset TARGETPATH unset TARGETSTAMP unset SNAPSHOTNAME unset CATDIR unset CATPORTDIR unset CATPORTCACHEDIR unset CATLOGDIR unset CATDISTDIR