updates to archive scripts

This commit is contained in:
2020-05-15 12:10:30 -05:00
parent 57330438d5
commit ce6ee256ab
5 changed files with 187 additions and 46 deletions

View File

@@ -0,0 +1,11 @@
# Repository archive scripts
Use this to archive repos from Github, Bitbucket, or wherever.
## Usage
Coming soon.
### Note
Repositories need to be in the `repo.txt` file in your temporary directory. This file **MUST** have an empty line at the end in order to get all of the repositories in the list. (Plus, it's good practice to always have an empty line at the end of your file anyway.)

View File

@@ -91,6 +91,7 @@ function print_ff() {
echo echo
echo -e "${fg_darkgrey_01} -------------------------------------------------------- ${reset}" echo -e "${fg_darkgrey_01} -------------------------------------------------------- ${reset}"
echo echo
prompt_continue
} }
if [ $path = 'c' ]; then if [ $path = 'c' ]; then
print_ff print_ff

View File

@@ -26,7 +26,7 @@ output="${base_dir}/${output_dir}"
# Debugging # Debugging
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
print_colors="yes" print_colors="no"
# Colors - source the colors.sh file # Colors - source the colors.sh file
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@@ -1,7 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
ind=" " ind=" "
sep_ll="56" sep_ll="100"
cdate=$(date '+%F')
# Indention - for reuse # Indention - for reuse
# ----------------------------------------------- # -----------------------------------------------
@@ -21,6 +22,18 @@ info(){
indent; indent; echo -e "${bg_darkgrey_02}${ui_text_info} i ${reset} \c" indent; indent; echo -e "${bg_darkgrey_02}${ui_text_info} i ${reset} \c"
} }
action(){
indent; indent; echo -e "${bg_darkgrey_02}${ui_text_info} > ${reset} \c"
}
action_title(){
indent; indent; echo -e "${bg_aqua}${fg_black} $1 ${reset}"
}
action_indent(){
indent; indent; indent; indent;
}
cmd(){ cmd(){
# indent; indent; echo -e "${bg_darkgrey_02} ${reset}" # indent; indent; echo -e "${bg_darkgrey_02} ${reset}"
# echo; # echo;
@@ -32,6 +45,10 @@ cmd_inline(){
echo -e "${bg_black}${ui_text_cmd} \$ $1 ${reset}" echo -e "${bg_black}${ui_text_cmd} \$ $1 ${reset}"
} }
cmd_inline_noprompt(){
echo -e "${bg_black}${ui_text_cmd} $1 ${reset}"
}
sec_hl(){ sec_hl(){
indent; indent; echo -e "${bg_darkpurple} $1 ${reset}"; indent; indent; echo -e "${bg_darkpurple} $1 ${reset}";
echo echo
@@ -85,7 +102,7 @@ check_ex(){
echo; sleep 1 echo; sleep 1
mkdir ${base_dir} mkdir ${base_dir}
else else
info; line "Base dir exists at: ${ui_text_cmd}${base_dir}${reset}" info; line "Base dir exists at: \c"; cmd_inline_noprompt "${base_dir}"
echo echo
fi fi
@@ -95,7 +112,7 @@ check_ex(){
echo; sleep 1 echo; sleep 1
mkdir ${source} mkdir ${source}
else else
info; line "Source dir exists at: ${ui_text_cmd}${source}${reset}" info; line "Source dir exists at: \c"; cmd_inline_noprompt "${source}"
echo echo
fi fi
@@ -105,7 +122,7 @@ check_ex(){
echo; sleep 1 echo; sleep 1
mkdir ${output} mkdir ${output}
else else
info; line "Output dir exists at: ${ui_text_cmd}${output}${reset}" info; line "Output dir exists at: \c"; cmd_inline_noprompt "${output}"
echo echo
fi fi
@@ -115,7 +132,7 @@ check_ex(){
echo; sleep 1 echo; sleep 1
mkdir ${base_dir}/_src && touch ${repo_list} mkdir ${base_dir}/_src && touch ${repo_list}
else else
info; line "A repository list exists at: ${ui_text_cmd}${repo_list}${reset}" info; line "A repository list exists at: \c"; cmd_inline_noprompt "${repo_list}"
echo echo
fi fi
@@ -133,9 +150,9 @@ user_prompt_continue() {
indent; indent; echo -e "${fg_lightgrey}\c"; read -r -p "Would you like to continue? $(color_yn)" response 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 if [[ $response =~ (y|yes|Y|YES|yep|yup) ]]; then
echo echo
info; line "You said YES"; info; line "You said YES. \c";
sleep 1s; sleep 1s;
line_2 "Moving on..."; line "Let's go!";
echo echo
sleep 1s; sleep 1s;
clear clear
@@ -147,7 +164,7 @@ user_prompt_continue() {
line_i "${bg_darkpurple} Exiting... ${reset}"; line_i "${bg_darkpurple} Exiting... ${reset}";
echo echo
echo echo
sleep 2s; sleep 1s;
exit 0; exit 0;
fi fi
} }
@@ -162,14 +179,14 @@ repo_list_empty_check(){
sec_hl "Checking for repositories:" sec_hl "Checking for repositories:"
if [ ! -s "${repo_list}" ]; then 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}"; line_2 "and restart this script." alert_line "There aren't any repos defined in your list yet."; line_2 "Add them to ${bg_black}${fg_aqua} ${repo_list} ${reset}"; line_2 "and restart this script."
echo echo
sep sep
echo echo
sleep 2s; sleep 2s;
exit 0; exit 0;
else else
info; line "Here's what you have in you list now:" info; line "Here's your list. The following repos will be processed:"
echo -e "${fg_aqua}" echo -e "${fg_aqua}"
cat ${repo_list} | sed 's/^/ /g' cat ${repo_list} | sed 's/^/ /g'
echo -e "${reset}" echo -e "${reset}"
@@ -177,43 +194,132 @@ repo_list_empty_check(){
fi fi
} }
# # Clone everything in repo_list to source folder github_clone() {
# # ----------------------------------------------- # Clone everything in repo_list to source folder
# # -----------------------------------------------
# while read line; do
# #echo -e "git clone $line"; while read line; do
# git -C $source/ clone --quiet $line
# done < ${repo_list} suffix=".git"
# pre="${line##*/}"
# pre=${pre%"${suffix}"}
# # Archive repos reponame="${pre}"
# # -----------------------------------------------
# echo
# cd ${source} sep
# echo
# for dir in */
# do sec_hl "Processing ${fg_aqua}${reponame} ${reset}"
# base=$(basename "$dir")
# tar -czf "${base}.tar.gz" "$dir" if [ ! -d "${source}/${reponame}" ]; then
# done info; line "Repo directory doesn't exist. \c"; sleep 1; line "${fg_aqua}Creating it now.${reset}"; sleep 1;
# mkdir "${source}/${reponame}";
# else
# # Copy archive files to output folder info; line "Repo directory already exists. \c"; sleep 1; line "${fg_aqua}Deleting it and making a fresh copy.${reset}"; sleep 1;
# # ----------------------------------------------- rm -rf "${source}/${reponame}" && mkdir "${source}/${reponame}";
# fi
# mv *.tar.gz ${output}
echo
# cd "${source}/${reponame}";
# ls -la;
# pwd
action_title "RUNNING";
echo
action; cmd_inline "git clone ${reponame}";
git -C "${source}/${reponame}/" clone -q $line;
action; cmd_inline "git clone MIRROR ${reponame}";
git -C "${source}/${reponame}/" clone --mirror -q $line;
echo
# Make a bundle file out of the mirror repo copy
# -----------------------------------------------
action_title "MAKING";
echo
action; line "Preparing the bundle file for ${reponame}";
cd "${source}/${reponame}/${reponame}".git/;
git bundle create "${reponame}".bundle --all >> log 2>&1;
action; line "Moving the bundle file for ${reponame}";
mv "${reponame}".bundle ../;
cd "${dir}"
done < ${repo_list}
echo
sep;
echo
info; line "Finished processing your repositories. \c"; sleep 1; line "Moving on to archiving...";
sleep 5s;
clear
}
archive() {
# Archive repos
# -----------------------------------------------
echo
sep
echo
action_title "ARCHIVING";
echo
cd "${source}"
action; line "Making tar files. \c";
for dir in */
do
base=$(basename "$dir")
tar -czf "${base}_${cdate}.tar.gz" "$dir"
done
sleep 2s;
line "Finished.";
sleep 1s;
echo
sep
echo
}
copy_archive(){
# Copy archive files to output folder
# -----------------------------------------------
action_title "MOVING FILES";
echo
action; line "Moving all of the archived tar files. \c";
mv *.tar.gz ${output}
sleep 2s;
line "Finished.";
echo
sep
echo
sleep 1s;
}
# Cleanup # Cleanup
# ----------------------------------------------- # -----------------------------------------------
zzz (){ cleanup (){
filelines="$(cat $repo_list)" filelines="$(cat $repo_list)"
action_title "CLEANUP";
echo
for line in $filelines; do for line in $filelines; do
suffix=".git" suffix=".git"
pre="${line##*/}" pre="${line##*/}"
pre=${pre%"${suffix}"} pre=${pre%"${suffix}"}
f="${output}/${pre}.tar.gz" f="${output}/${pre}_${cdate}.tar.gz"
if [ ! -f "$f" ]; then if [ ! -f "$f" ]; then
sep sep
echo echo
@@ -227,14 +333,35 @@ zzz (){
indent; echo -e "tar -czf $(echo "${pre}").tar.gz $(echo "${output}/")" indent; echo -e "tar -czf $(echo "${pre}").tar.gz $(echo "${output}/")"
echo echo
sep sep
# else
# echo -e "It's there! \c"
# echo -e "${f}"
fi fi
done done
action; line "Removing the source repo folders. \c";
cd ${source} && rm -rf * && cd ../;
sleep 2s;
line "Finished.";
echo
sep
echo
sleep 3s;
clear
} }
#zzz finished_msg() {
echo
sep
echo
action_title "FINISHED";
echo
info; line "Your archives are ready!"
echo
line_i "You can find them in \c"; cmd_inline_noprompt "${output}/";
echo
sep;
echo
sleep 3;
}
run() { run() {
titleblock titleblock
@@ -242,5 +369,9 @@ run() {
prompt_continue prompt_continue
clear clear
repo_list_empty_check repo_list_empty_check
echo -e "yay!" github_clone
archive
copy_archive
cleanup
finished_msg
} }

View File

@@ -1,3 +1 @@
https://github.com/ff4500/startpage-gatsby.git
https://github.com/ff4500/sh-start.git
https://github.com/ff4500/jasonpitman.git