LXMF-Tools/build_git.sh

206 lines
3.1 KiB
Bash
Raw Permalink Normal View History

2022-10-21 11:58:11 -04:00
#!/bin/bash
##############################################################################################################
# Configuration
BRANCH="main"
ORIGIN="git@github.com:SebastianObi/LXMF-Tools.git"
FILES_ADD=("*")
FILES_REMOVE=(".git/*")
COMMENT_COMMIT="$(date +%Y-%m-%d_%H:%M:%S)"
COMMENT_CLEAR="Removed history, due to sensitive data"
COMMENT_INIT="Initial commit"
##############################################################################################################
# Functions
_prompt() {
echo -e "Origin: ${ORIGIN}"
echo -e "Branch: ${BRANCH}"
echo -e ""
2022-10-21 11:58:11 -04:00
echo -e ""
echo -e "Select an option:"
2023-11-05 09:24:22 -05:00
options=("Diff" "Pull" "Commit/Push" "Clear History" "Init" "Init (Pull only)" "Init (Push only)" "Exit")
2022-10-21 11:58:11 -04:00
select opt in "${options[@]}"; do
case $opt in
"Diff"*)
_diff
break;;
2023-11-05 09:24:22 -05:00
"Pull"*)
_pull
break;;
2022-10-21 11:58:11 -04:00
"Commit/Push"*)
_commit
break;;
"Clear History"*)
_clear
break;;
2022-10-23 13:26:06 -04:00
"Init (Pull only)"*)
_init_pull
break;;
2023-08-10 14:55:36 -04:00
"Init (Push only)"*)
_init_push
break;;
2022-10-21 11:58:11 -04:00
"Init"*)
_init
break;;
"Exit"*)
echo -e ""
echo -e "Exit"
break;;
*)
echo -e "Invalid choice!"
break;;
esac
done
}
_define_files() {
for file in ${FILES_ADD[@]}; do
git add "${file}"
done
for file in ${FILES_REMOVE[@]}; do
git reset -- "${file}"
done
}
_diff() {
2023-11-05 09:24:22 -05:00
git diff --numstat
}
_pull() {
echo -e ""
echo -e "Pull"
git pull origin "${BRANCH}"
}
2022-10-21 11:58:11 -04:00
_commit() {
_define_files
git diff --numstat
echo -e ""
echo -e "Commit/Push to Git"
echo -e "Comment:"
read VAR
if [ -z "${VAR}" ]; then
VAR="${COMMENT_COMMIT}"
fi
git commit -a -m "${VAR}"
git push
}
_clear() {
echo -e ""
echo -e "Clear History"
echo -e "Comment:"
read VAR
if [ -z "${VAR}" ]; then
VAR="${COMMENT_CLEAR}"
fi
rm -rf .git
git init
_define_files
git commit -m "${VAR}"
git branch -M "${BRANCH}"
git remote add origin "${ORIGIN}"
git push -f -u origin "${BRANCH}"
}
_init() {
echo -e ""
echo -e "Init"
echo -e "Comment:"
read VAR
if [ -z "${VAR}" ]; then
VAR="${COMMENT_INIT}"
fi
rm -rf .git
git init
_define_files
git branch -M "${BRANCH}"
git remote add origin "${ORIGIN}"
git pull origin "${BRANCH}"
git commit -m "${VAR}"
2022-10-23 13:26:06 -04:00
git push -f -u origin "${BRANCH}"
}
_init_pull() {
echo -e ""
echo -e "Init (Pull only)"
read VAR
if [ -z "${VAR}" ]; then
VAR="${COMMENT_INIT}"
fi
rm -rf .git
git init
_define_files
git branch -M "${BRANCH}"
git remote add origin "${ORIGIN}"
git pull origin "${BRANCH}"
2022-10-21 11:58:11 -04:00
git push -f -u origin "${BRANCH}"
}
2023-08-10 14:55:36 -04:00
_init_push() {
echo -e ""
echo -e "Init (Push only)"
read VAR
if [ -z "${VAR}" ]; then
VAR="${COMMENT_INIT}"
fi
rm -rf .git
git init
_define_files
git branch -M "${BRANCH}"
git remote add origin "${ORIGIN}"
git push -f -u origin "${BRANCH}"
}
2022-10-21 11:58:11 -04:00
##############################################################################################################
# Setup/Start
_prompt