diff options
author | Christos.K <freedomrfox@gmail.com> | 2017-06-09 02:21:13 +0300 |
---|---|---|
committer | Christos.K <freedomrfox@gmail.com> | 2017-06-09 02:21:13 +0300 |
commit | 0de9687071fa4f5bc3de0056a794e87ce4912958 (patch) | |
tree | d2de130af6e5409c80eb32a1c46b64edcabb672b /scripts | |
parent | Included function entries (diff) | |
download | GSE-0de9687071fa4f5bc3de0056a794e87ce4912958.tar.gz GSE-0de9687071fa4f5bc3de0056a794e87ce4912958.tar.bz2 GSE-0de9687071fa4f5bc3de0056a794e87ce4912958.zip |
Included functions
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/functions/init_stage3_seq | 343 |
1 files changed, 34 insertions, 309 deletions
diff --git a/scripts/functions/init_stage3_seq b/scripts/functions/init_stage3_seq index 897e384..0dbed47 100755 --- a/scripts/functions/init_stage3_seq +++ b/scripts/functions/init_stage3_seq @@ -1,220 +1,34 @@ #!/bin/bash +# GET LATEST PORTAGE SNAPSHOT, CREATE GSE PROFILE AND LAST INITIATE THE STAGE 1,2,3 BUILD SEQUENCE LC_COLLATE=C LC_ALL="en_US.UTF-8" LC_CTYPE="en_US.UTF-8" -# GET LATEST PORTAGE SNAPSHOT, CREATE GSE PROFILE AND LAST INITIATE THE STAGE 1,2,3 BUILD SEQUENCE - -# storedir -CATDIR=$(grep storedir "${CCONFDIR}/system/catalyst/catalyst.conf" \ -| sed '/^#/ d' | awk -F '=' '{ print $2 }' | sed -e "s_\"__g") +# PP CHECK +[[ -z "$@" ]] && print_inf_f 4 && exit 1 -# portdir -CATPORTDIR=$(grep portdir "${CCONFDIR}/system/catalyst/catalyst.conf" \ -| sed '/^#/ d' | awk -F '=' '{ print $2 }' | sed -e "s_\"__g") - -# snapshot_cache -CATPORTCACHEDIR=$(grep "snapshot_cache" "${CCONFDIR}/system/catalyst/catalyst.conf" \ -| sed '/^#/ d' | awk -F '=' '{ print $2 }' | sed -e "s_\"__g") - -# port_logdir -CATLOGDIR=$(grep "port_logdir" "${CCONFDIR}/system/catalyst/catalyst.conf" \ -| sed '/^#/ d' | awk -F '=' '{ print $2 }' | sed -e "s_\"__g") -# distdir -CATDISTDIR=$(grep "distdir" "${CCONFDIR}/system/catalyst/catalyst.conf" \ -| sed '/^#/ d' | awk -F '=' '{ print $2 }' | sed -e "s_\"__g") +# EXPORT THE DIRECTORIES DEFINED BY STAGE1.SPEC +export_cat_dirs_f # CREATE DIRECTORIES FOR CATALYST -mkdir -p "${CATDIR}" -mkdir -p "${CATPORTDIR}" -mkdir -p "${CATPORTCACHEDIR}" -mkdir -p "${CATLOGDIR}" -mkdir -p "${CATDISTDIR}" -mkdir -p "${CATDIR}/builds/default" -mkdir -p "${CATDIR}/snapshots" - -# CREATE -TARGETPATH="$(grep 'source_subpath' "${CCONFDIR}/system/catalyst/stage1.spec" \ -| sed '/^#/ d' | awk -F ' ' '{ print $2 }' | sed -e "s_\"__g" | awk -F '/' '{ print $1 }')" +create_cata_dirs_f -TARGETNAME="$(grep 'source_subpath' "${CCONFDIR}/system/catalyst/stage1.spec" \ -| sed '/^#/ d' | awk -F ' ' '{ print $2 }' | sed -e "s_\"__g" | awk -F '/' '{ print $2 }')" +# CHECK IF STAGE3 TARBALL IS PRESENT AT THE INDICATED DIRECTORY +tar_path_name_f "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 -unset TARGETNAME -unset TARGETPATH - -get_latest_portage_f() { -# PORTAGE MD5SUM -wget -O "${CATDIR}/portage-latest.tar.bz2.md5sum" >/dev/null 2>&1 \ -http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2.md5sum \ -&& echo -e "[\e[32m*\e[0m] \e[34mGetting md5sum\e[0m" \ -|| { echo -e "[\e[31m*\e[0m] \e[31mFAILD\e[0m: \e[34mGetting md5sum\e[0m" \ -&& return 1; } -# VERIFYING LOCAL SNAPSHOT && FETCH NEW IF VERIFICATION FAILS -BTWRK="${PWD}" && cd "${CATDIR}" >/dev/null 2>&1 -if md5sum -c "portage-latest.tar.bz2.md5sum" >/dev/null 2>&1; then -cd "${BTWRK}" >/dev/null 2>&1 \ -&& echo -e "[\e[32m*\e[0m] Snapshot \e[32mverified\e[0m" && unset BTWRK -else -cd "${BTWRK}" >/dev/null 2>&1 \ -&& echo -e "[\e[31m*\e[0m] \e[31mFAILD\e[0m: Snapshot \e[31mverified\e[0m" \ -&& echo -e "[\e[31m*\e[0m] Purging old snapshot" \ -&& rm -f "${CATDIR}/portage-latest.tar.bz2" -# GETTING PORTAGE SNAPSHOT -echo -e "[\e[32m*\e[0m] \e[34mGetting latest portage snapshot\e[0m" \ -&& wget -O "${CATDIR}/portage-latest.tar.bz2" \ -http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2 \ -&& print_inf 1 || { print_inf 2; return 1; } \ -&& unset BTWRK -fi - -# VERIFYING NEW SNAPSHOT -( BTWRK="${PWD}" && cd "${CATDIR}" >/dev/null 2>&1 -if md5sum -c "portage-latest.tar.bz2.md5sum" >/dev/null 2>&1; then -cd "${BTWRK}" >/dev/null 2>&1 \ -&& echo -e "[\e[32m*\e[0m] Snapshot \e[32mverified\e[0m" && unset BTWRK -else -echo -e "[\e[31m*\e[0m] \e[31mFAILD\e[0m: Snapshot \e[31mverified\e[0m" \ -&& unset BTWRK && return 1 -fi; ) \ -&& echo "Copying to ${CATDIR}/snapshots" \ -&& cp "${CATDIR}/portage-latest.tar.bz2" "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2" \ -&& cp "${CATDIR}/portage-latest.tar.bz2.md5sum" "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2.md5sum" \ -&& print_inf 1 || { print_inf 2; return 1; } -} - -tar_path_name_f() { -TARGETPATH="$(grep 'source_subpath' "${CCONFDIR}/system/catalyst/stage$1.spec" \ -| sed '/^#/ d' | awk -F ' ' '{ print $2 }' | sed -e "s_\"__g" | awk -F '/' '{ print $1 }')" - - -TARGETNAME="$(grep 'source_subpath' "${CCONFDIR}/system/catalyst/stage$1.spec" \ -| sed '/^#/ d' | awk -F ' ' '{ print $2 }' | sed -e "s_\"__g" | awk -F '/' '{ print $2 }')" - -TARGETSTAMP="$(grep 'version_stamp' "${CCONFDIR}/system/catalyst/stage$1.spec" \ -| sed '/^#/ d' | awk -F ' ' '{ print $2 }' | sed -e "s_\"__g")" -} - -opt_f() { - echo -e "################## \e[94m~~Snapshot~~\e[39m #################" - echo "## ##" - echo -e "## [ \e[32mI\e[39m ] Fetch new ##" - echo -e "## [ \e[32mII\e[39m ] Let me show you ##" - echo -e "## [ \e[32mIII\e[39m] Try and find it please ##" - echo -e "## [ \e[32mIV\e[39m ] Where is my shell? ##" - echo -e "## [ \e[32mV\e[39m ] Built new from portdir ##" - echo "## ##" - echo "####################################################" -} - -chk_snap_f() { -[[ $(du -sh "$1" | awk -F ' ' '{print $1}' | sed 's/[^0-9]*//g') -le 220 ]] \ -&& [[ $(du -sh "$1" | awk -F ' ' '{print $1}' | sed 's/[^0-9]*//g') -ge 50 ]] \ -|| return 1 -} -search_snap_f() { -mapfile -t ARRAYSNAP < <(find / -name "*portage*.tar.bz2") - - -for i in "${ARRAYSNAP[@]}"; do - if [[ $(du -sh "$i" | awk -F ' ' '{print $1}' | sed 's/[^M]*//g') == M && -n $(echo "$i" | grep portage) ]]; then - if chk_snap_f "$i"; then - while true; do - echo "$i" - read -rp "Is this the snapshot? Y/N " YN - case "${YN:-5}" in - [yY][eE][sS]|[yY]) - echo -e "\e[34mCopying snapshot to ${CATDIR}/snapshots\e[0m" - cp "$i" "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2" - return 0 - ESCINNER=0 - break - ;; - [nN][oO]|[nN]) - ESCINNER=1 - break;; - esac - done - [[ "$ESCINNER" == 0 ]] && unset ESCINNER && break - fi - fi -done -return 1 -unset YN -unset ESCINNER -unset ARRAYSNAP -} - -build_port() { - call_cata_f() { - echo -e "\e[34mCreating snapshot...\e[0m" - catalyst -s "${TARGETNAME}" && { BRKVAR=0 && return 0; }|| { BRKVAR=1 && return 1; } - } - - echo -e "\e[35mIt is strongly recommended to update your portdir first\e[0m" - while true; do - read -rp "Do you wish to update? Y/N " YN - case "${YN:-n}" in - [yY][eE][sS]|[yY]) - echo -e "\e[32mUpdating...\e[0m" - { - { eix-sync >/dev/null 2>&1 \ - && echo -e "\e[32mDone\e[0m" && call_cata_f; } \ - || { emerge --sync >/dev/null 2>&1 \ - && echo -e "\e[32mDone\e[0m" && call_cata_f; } \ - || { emerge-webrsync >/dev/null 2>&1 \ - && echo -e "\e[32mDone\e[0m" && call_cata_f; } - } \ - || { echo -e "\e[31mUpdate failed, build without update?\e[0m" - while true; do - read -rp "Answer: YN " ANS - case "${ANS:-n}" in - [yY]) - echo -e "\e[34mProceeding\e[0m" - call_cata_f - break;; - [nN]) - echo -e "\e[34mAborting...\e[0m" - sleep 1 - BRKVAR=1 - return 0;; - esac - done; } - break;; - [nN][oO]|[nN]) - echo -e "\e[34mProceeding\e[0m" - call_cata_f - break;; - esac - done -} - -TARGETNAME="$(grep 'snapshot:' "${CCONFDIR}/system/catalyst/stage1.spec" \ -| sed '/^#/ d' | sed '/^\s*$/d' | awk -F ' ' '{ print $2 }' | sed -e "s_\"__g")" - -subterm_f() { - echo -e "\e[33mCalling bash subshell\e[0m" - sleep 2 - echo 'echo -e "\e[33mInside Subshell\e[0m"' >> /root/.bashrc - echo "echo -e "Please copy your snapshot to ${CATDIR}/snapshots with name: portage-${TARGETNAME}.tar.bz2"" - echo 'echo -e "\e[33mExit to return back to parent\e[0m"' >> /root/.bashrc - (clear; exec /bin/bash;) - 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" -} - -if [[ ! -e "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2" ]] || ! chk_snap_f "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2"; then - -rm -f "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2" >/dev/null 2>&1 +# CHECK IF SNAPSHOT EXISTS AND HAS NORMAL SIZE +check_portage_snap_f() { +if [[ ! -e "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2" ]] || ! chk_snap_f "${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 opt_f - echo -e "[\e[31m*\e[0m] Could not locate snapshots/portage-${TARGETNAME}.tar.bz2 @ ${CATDIR}/snapshots" + echo -e "[\e[31m*\e[0m] Could not locate snapshots/portage-${SNAPSHOTNAME}.tar.bz2 @ ${CATDIR}/snapshots" echo "Please select an option" read -rp "Option: " ANS case "$ANS" in @@ -224,7 +38,7 @@ while true; do II|ii|2) read -rp "Please enter the absolute path with the snapshot included: " PATHTOSNAP if [[ -n "${PATHTOSNAP}" ]] && chk_snap_f "${PATHTOSNAP}"; then - cp "${PATHTOSNAP}" "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2" \ + 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" @@ -233,7 +47,7 @@ while true; do case "${YN:-n}" in [yY][eE][sS]|[yY]) echo -e "\e[34mCopying file to ${CATDIR}/snapshots\e[0m" - cp "${PATHTOSNAP}" "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2\e[0m" \ + cp "${PATHTOSNAP}" "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2\e[0m" \ && BRKVAR=0 || BRKVAR=1 break;; [nN][oO]|[nN]) @@ -249,7 +63,7 @@ while true; do echo -e "\e[32mSearching\e[0m..." search_snap_f && 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 chk_snap_f "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2"; then + if chk_snap_f "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2"; then echo -e "[\e[32m*\e[0m] Snapshot seems normal" BRKVAR=0 else @@ -270,11 +84,11 @@ while true; do fi ;; IV|iv|4) - echo "\e[35mOpening new shell, please copy your snapshot to ${CATDIR}/snapshots with name: portage-${TARGETNAME}.tar.bz2\e[0m" + echo "\e[35mOpening new shell, please copy your snapshot to ${CATDIR}/snapshots with name: portage-${SNAPSHOTNAME}.tar.bz2\e[0m" subterm_f - if [[ -e "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2" ]]; then + if [[ -e "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2" ]]; then echo -e "\e[32mChecking\e[0m..." - if chk_snap_f "${CATDIR}/snapshots/portage-${TARGETNAME}.tar.bz2"; then + if chk_snap_f "${CATDIR}/snapshots/portage-${SNAPSHOTNAME}.tar.bz2"; then echo -e "[\e[32m*\e[0m] Snapshot seems normal" BRKVAR=0 else @@ -353,127 +167,38 @@ else echo -e "\e[32mPrtage snapshot found @ ${CATDIR}/snapshots\e[0m" fi -unset BRKVAR -unset TARGETNAME - -tar_path_name_f 1 -unset TARGETPATH - -TARGETPATH="$(grep 'source_subpath' "${CCONFDIR}/system/catalyst/stage1.spec" \ -| sed '/^#/ d' | awk -F ' ' '{ print $2 }' | sed -e "s_\"__g" | awk -F '/' '{ print $1}')" - -stage1_f() { -if [[ -e "${CATDIR}/builds/${TARGETPATH}/${TARGETNAME}.tar.bz2" ]]; then -# STAGE 1 - -echo -e "\e[35mBuilding stage1\e[0m" - -cat "${CCONFDIR}/system/catalyst/stage1.spec" | sed '/^#/ d' | sed '/^\s*$/d' \ -> "${CATDIR}/.stage1.spec" - -catalyst -c "${CCONFDIR}/system/catalyst/catalyst.conf" -f "${CATDIR}/.stage1.spec" \ -&& print_inf 1 || { print_inf 2 && exit 1; } -else - echo -e "\e[31mCould not locate ${TARGETNAME}.tar.bz2\e[0m" -fi +unset BRKVAR } -if [[ -e "${CATDIR}/builds/${TARGETPATH}/stage1-${ARCH}-${TARGETSTAMP}.tar.bz2" && "$3" == "s1" ]]; then - -echo -e "\e[32mStage1 located\e[0m" - -while read -p "Do you wish to build new? Y/N " ANS; do - case $ANS in - [yY]) - stage1_f - break;; - [nN]) - break;; - esac -done +if [[ -n $(echo $@ | grep '\--force-new') ]]; then + echo -e "\e[34mCreating snapshot...\e[0m" + catalyst -s "${SNAPSHOTNAME}" && print_inf 1 || { print_inf 2 && exit 1; } else -stage1_f + check_portage_snap_f fi - +# STAGE 1 +check_then_call_stageX_f "${CATDIR}/builds/${TARGETPATH}/${TARGETNAME}.tar.bz2" "1" "$@" unset TARGETNAME unset TARGETPATH unset TARGETSTAMP -tar_path_name_f 2 +unset SNAPSHOTNAME +tar_path_name_f "2" -stage2_f() { -if [[ -e "${CATDIR}/builds/${TARGETPATH}/stage1-${ARCH}-${TARGETSTAMP}.tar.bz2" ]]; then # STAGE 2 -echo -e "\e[35mBuilding stage2\e[0m" - -cat "${CCONFDIR}/system/catalyst/stage2.spec" | sed '/^#/ d' | sed '/^\s*$/d' \ -> "${CATDIR}/.stage2.spec" - -catalyst -c "${CCONFDIR}/system/catalyst/catalyst.conf" -f "${CATDIR}/.stage2.spec" \ -&& print_inf 1 || { print_inf 2 && exit 1; } -else - echo -e "\e[31mCould not locate stage1-${ARCH}-${TARGETSTAMP}.tar.bz2\e[0m" -fi -} - -if [[ -e "${CATDIR}/builds/${TARGETPATH}/stage2-${ARCH}-${TARGETSTAMP}.tar.bz2" && "$4" == "s2" ]]; then - -echo -e "\e[32mStage2 located\e[0m" - -while read -p "Do you wish to build new? Y/N " ANS; do - case $ANS in - [yY]) - stage2_f - break;; - [nN]) - break;; - esac -done -else -stage2_f -fi - +check_then_call_stageX_f "${CATDIR}/builds/${TARGETPATH}/stage1-${ARCH}-${TARGETSTAMP}.tar.bz2" "2" "$@" unset TARGETNAME unset TARGETPATH unset TARGETSTAMP -tar_path_name_f 3 +unset SNAPSHOTNAME +tar_path_name_f "3" -stage3_f() { -if [[ -e "${CATDIR}/builds/${TARGETPATH}/stage2-${ARCH}-${TARGETSTAMP}.tar.bz2" ]]; then # STAGE 3 - -echo -e "\e[35mBuilding stage3\e[0m" - -cat "${CCONFDIR}/system/catalyst/stage3.spec" | sed '/^#/ d' | sed '/^\s*$/d' \ -> "${CATDIR}/.stage3.spec" - -catalyst -c "${CCONFDIR}/system/catalyst/catalyst.conf" -f "${CATDIR}/.stage3.spec" \ -&& print_inf 1 || { print_inf 2 && exit 1; } -else - echo -e "\e[31mstage2-${ARCH}-${TARGETSTAMP}.tar.bz2\e[0m" -fi -} - -if [[ -e "${CATDIR}/builds/${TARGETPATH}/stage3-${ARCH}-${TARGETSTAMP}.tar.bz2" && "$5" == "s3" ]]; then - -echo -e "\e[32mStage3 located\e[0m" - -while read -p "Do you wish to build new? Y/N " ANS; do - case $ANS in - [yY]) - stage3_f - break;; - [nN]) - break;; - esac -done -else -stage3_f -fi - +check_then_call_stageX_f "${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 |