diff --git a/backup/archive_repos/_lib/c/base.sh b/backup/archive_repos/_lib/c/base.sh index 0899580..1d0d579 100644 --- a/backup/archive_repos/_lib/c/base.sh +++ b/backup/archive_repos/_lib/c/base.sh @@ -29,6 +29,7 @@ base_darkgrey_02="50;50;50m" base_black="0;0;0m" base_lime="0;255;0m" base_aqua="0;255;255m" +base_red="255;0;0m" l_grey_rgb="120;120;120m" m_grey_rgb="80;80;80m" @@ -46,6 +47,7 @@ fg_darkgrey_02="${esc_seq_fg}${base_darkgrey_02}" fg_black="${esc_seq_fg}${base_black}" fg_lime="${esc_seq_fg}${base_lime}" fg_aqua="${esc_seq_fg}${base_aqua}" +fg_red="${esc_seq_fg}${base_red}" # Named background colors # ------------------------------------------------------------------------------ @@ -56,8 +58,9 @@ bg_lightgrey="${esc_seq_fg}${c_white}${esc_seq_bg}${base_lightgrey}" bg_darkgrey_01="${esc_seq_fg}${c_white}${esc_seq_bg}${base_darkgrey_01}" bg_darkgrey_02="${esc_seq_fg}${c_white}${esc_seq_bg}${base_darkgrey_02}" bg_black="${esc_seq_fg}${c_white}${esc_seq_bg}${base_black}" -bg_lime="${esc_seq_fg}${c_white}${esc_seq_bg}${base_lime}" -bg_aqua="${esc_seq_fg}${c_white}${esc_seq_bg}${base_aqua}" +bg_lime="${esc_seq_fg}${c_black}${esc_seq_bg}${base_lime}" +bg_aqua="${esc_seq_fg}${c_black}${esc_seq_bg}${base_aqua}" +bg_red="${esc_seq_fg}${c_white}${esc_seq_bg}${base_red}" # Color variations and special use cases # ------------------------------------------------------------------------------ diff --git a/backup/archive_repos/_lib/config.sh b/backup/archive_repos/_lib/config.sh index e0d40b8..9cd6a5e 100755 --- a/backup/archive_repos/_lib/config.sh +++ b/backup/archive_repos/_lib/config.sh @@ -14,6 +14,11 @@ source_repo_dir="repos" output_dir="archive" repo_list="${base_dir}/_src/repo_list.txt" +# Other config things +# ------------------------------------------------------------------------------ +title="Repo archiving utility v0.01" + + # Variables for functions - Don't mess with these # ------------------------------------------------------------------------------ source="${base_dir}/${source_repo_dir}" diff --git a/backup/archive_repos/_lib/functions.sh b/backup/archive_repos/_lib/functions.sh index b70e60e..41e96d2 100755 --- a/backup/archive_repos/_lib/functions.sh +++ b/backup/archive_repos/_lib/functions.sh @@ -1,8 +1,10 @@ #!/usr/bin/env bash +ind=" " +sep_ll="56" + # Indention - for reuse # ----------------------------------------------- -ind=" " indent() { printf "${ind}" } @@ -11,13 +13,8 @@ indent() { # ----------------------------------------------- sep() { local ch="-" - local sep_line="$(printf '%*s' "56" | tr ' ' "$ch")" + local sep_line="$(printf '%*s' "${sep_ll}" | tr ' ' "$ch")" echo -e "${ind}${fg_darkgrey_01}${sep_line}${reset}${ind}" - #echo -e "-----------------------------------------------------------------------------" -} - -aaa() { - echo -e "${fg_darkgrey_01} -------------------------------------------------------- ${reset}" } info(){ @@ -26,11 +23,12 @@ info(){ cmd(){ indent; indent; echo -e "${bg_darkgrey_02} ${reset}" - indent; indent; echo -e "${bg_darkgrey_02}${ui_text_cmd} > ${reset}${fg_darkgrey_01} \$ ${reset}\c" + indent; indent; echo -e "${bg_darkgrey_02}${ui_text_cmd} > ${reset}${fg_lightgrey} \$ ${reset}\c" + echo -e "${fg_lightgrey}$1${reset}" } sec_hl(){ - indent; indent; echo -e "${bg_lightpurple} $1 ${reset}"; + indent; indent; echo -e "${bg_darkpurple} $1 ${reset}"; echo } @@ -38,10 +36,34 @@ line(){ echo -e $1 } +line_i(){ + indent; indent; echo -e $1 +} + line_2(){ indent; indent; echo -e "${bg_darkgrey_02} ${reset} \c"; echo -e $1 } +alert_line(){ + indent; indent; echo -e "${bg_darkgrey_02}${fg_red} ! ${reset} \c"; echo -e "${fg_red}$1${reset}" +} + +titleblock() { + local title_length="$(echo -e "${title}" | awk '{print length}')" #gets the length of the title var + local title_sp="$(($((sep_ll-title_length))/2))" #subtract the length of the title from the seperator, divide by 2 + local sp="$(printf "%*s%s" $title_sp '' "$sp")" #printf that amount of empty spaces (with sed) to a var called "sp" + local line="$(printf "%*s%s" $sep_ll '' "$line")" #print empty spaces the length of the "sep_ll" var + + clear; echo + echo -e "${ind}${bg_darkpurple}${line}${reset}" + echo -e "${ind}${bg_darkpurple}${sp}${title}${sp}${reset}" + echo -e "${ind}${bg_darkpurple}${line}${reset}" +} + +prompt_continue(){ + indent; indent; echo -e "${fg_lightgrey}\c"; read -n 1 -s -r -p "Press any key to continue... "; echo -e "${reset}" +} + # Check directory/file existence # ----------------------------------------------- @@ -53,47 +75,97 @@ check_ex(){ sec_hl "Checking for required files/folders:" if [ ! -d "${base_dir}" ]; then - info; line "${fg_lightgrey}Base dir${reset} doesn't exist."; line_2 "Making it now." - cmd; line "${fg_lightgrey}mkdir ${base_dir}${reset}" + alert_line "Base dir doesn't exist."; line_2 "Making it now." + cmd "mkdir ${base_dir}" echo; sleep 1 mkdir ${base_dir} else - info; line "Base dir exists at ${ui_text_cmd}${base_dir}${reset}" + info; line "Base dir exists at:"; line_2 "${ui_text_cmd}${base_dir}${reset}" echo fi if [ ! -d "${source}" ]; then - info; line "${fg_lightgrey}Source dir${reset} doesn't exist."; line_2 "Making it now." - cmd; line "${fg_lightgrey}mkdir ${source}${reset}" + alert_line "Source dir doesn't exist."; line_2 "Making it now." + cmd "mkdir ${source}" echo; sleep 1 mkdir ${source} else - info; line "Source dir exists at ${ui_text_cmd}${source}${reset}" + info; line "Source dir exists at:"; line_2 "${ui_text_cmd}${source}${reset}" echo fi if [ ! -d "${output}" ]; then - info; line "${fg_lightgrey}Output dir${reset} doesn't exist."; line_2 "Making it now." - cmd; line "${fg_lightgrey}mkdir ${output}${reset}" + alert_line "Output dir doesn't exist."; line_2 "Making it now." + cmd "mkdir ${output}" echo; sleep 1 mkdir ${output} else - info; line "Output dir exists at ${ui_text_cmd}${output}${reset}" + info; line "Output dir exists at:"; line_2 "${ui_text_cmd}${output}${reset}" echo fi if [ ! -f "${repo_list}" ]; then - info; line "A ${fg_lightgrey}repository list${reset} doesn't exist."; line_2 "Making the ${ui_text_cmd}_src${reset} dir and an empty list now." - cmd; line "${fg_lightgrey}touch ${repo_list}${reset}" + alert_line "A repository list doesn't exist."; line_2 "Making the ${bg_aqua} _src ${reset} dir and an empty list now." + cmd "touch ${repo_list}" echo; sleep 1 mkdir ${base_dir}/_src && touch ${repo_list} else - info; line "A repository list exists at ${ui_text_cmd}${repo_list}${reset}" + info; line "A repository list exists at:"; line_2 "${ui_text_cmd}${repo_list}${reset}" echo fi + sep + echo +} + +color_yn() { + echo -e "${fg_lightgrey}(yes/no):${reset} " +} + +user_prompt_continue() { + sep + echo + indent; indent; echo -e "${fg_lightgrey}\c"; read -r -p "Would you like to continue? $(color_yn)" response + if [[ $response =~ (y|yes|Y|YES|yep|yup) ]]; then + echo + info; line "You said YES"; + sleep 1s; + line_2 "Moving on..."; + echo + sleep 1s; + clear + else + echo + info; line "You said NO ${fg_lightgrey}(or didn't type y|yes|Y|YES|yep|yup)${reset}"; + echo + sleep .5s; + line_i "${bg_darkpurple} Exiting... ${reset}"; + echo + echo + sleep 2s; + exit 0; + fi +} + +# Check if repo_list.txt is empty + +repo_list_empty_check(){ echo sep + echo + + sec_hl "Checking for repositories in your list:" + + if [ ! -s "${repo_list}" ]; then + alert_line "There aren't any repos defined in your list yet."; line_2 "Add them to ${fg_aqua}${repo_list}${reset}" + exit 0; + else + info; line "Here's what you have in you list now:" + echo -e "${fg_aqua}" + cat ${repo_list} | sed 's/^/ /g' + echo -e "${reset}" + user_prompt_continue + fi } # # Clone everything in repo_list to source folder @@ -156,14 +228,10 @@ zzz (){ #zzz run() { + titleblock check_ex - echo - sep - indent; indent; echo "Yay" - sep - echo - aaa - indent; indent; echo "YAY!" - aaa - echo + prompt_continue + clear + repo_list_empty_check + echo -e "yay!" }