gkmanager/gkmanager.sh

124 lines
3.0 KiB
Bash
Raw Normal View History

2018-01-30 21:11:07 -07:00
#!/bin/bash
# Colors
RED='\033[0;31m'
LRED="\033[1;31m"
BLUE="\033[0;34m"
LBLUE="\033[1;34m"
GREEN="\033[0;32m"
LGREEN="\033[1;32m"
YELLOW="\033[1;33m"
CYAN="\033[0;36m"
LCYAN="\033[1;36m"
PURPLE="\033[0;35m"
LPURPLE="\033[1;35m"
BWHITE="\e[1m"
NC='\033[0m' # No Color
2018-02-05 19:50:24 -07:00
source config.sh
2018-01-30 21:11:07 -07:00
passwordRepo="http://gitbutter.pw/mollusk/vault.git"
2018-02-05 19:50:24 -07:00
function writeConfig(){
cat >config.sh <<EOL
FIRSTRUN="${1}"
EOL
return
}
function readConfig(){
echo ${FIRSTRUN}
}
2018-01-30 21:11:07 -07:00
function installGit(){
if [ ! -f /usr/bin/git ];then
sudo apt update && sudo apt install -y git
fi
}
2018-02-05 19:50:24 -07:00
2018-01-30 21:11:07 -07:00
function gitSetup(){
printf "${LCYAN} ===============${NC}\n"
printf "${LCYAN}| Git Config |${NC}\n"
printf "${LCYAN} ===============${NC}\n"
printf "\n\n${YELLOW}The following information will be displayed when you \n commit changes to you repository...${NC}\n\n"
printf "${LGREEN}E-mail Address (required): ${NC}"
read email
printf "${LGREEN}Desired Username (required): ${NC}"
read name
printf "\n${YELLOW}Review and confirm your details${NC}\n\n"
printf "${LGREEN}Email Address: ${email}${NC}\n"
printf "${LGREEN}Username: ${name}${NC}\n\n"
printf "${YELLOW}Are these settings correct? (y/n): ${NC}"
read confirm
if [ "${confirm}" = "n" ];then
echo
echo "Setup Cancelled!"
exit 0;
elif [ "${confirm}" = "y" ];then
git config --global user.email ${email}
git config --global user.name ${name}
echo
echo "Saved git config"
exit 0;
fi
}
function gitButterSync(){
domain="https://gitbutter.pw"
defaultRepoDir="/home/${USER}/keepass/"
printf "${YELLOW} Your keepass database is stored on: ${domain}.\n"
printf "If this is the first time running this script\n"
printf "you need to clone the repository which contains your password database${NC}\n\n"
printf "${YELLOW}The following questions are asked so the script knows where to find your repository on gitbutter\n"
printf "As an example, the full URL would look similar to this:${NC}\n\n"
printf "${LPURPLE}${domain}/username/repository${NC}\n\n"
printf "${YELLOW}The script simply puts the Username and Repository name into the URL.${NC}\n\n"
printf "${LBLUE}Please enter your ${domain} Username: ${NC}"
read gbusername
printf "${LBLUE}Please enter the name of your repository: ${NC}"
read gbrepo
printf "${LPURPLE}INFO: You can leave this question blank to use the default location${NC}\n"
printf "${LBLUE}Where do you want to save your repository?(default: ${defaultRepoDir}) "
printf "\n\n${LPURPLE}INFO: Cloning your repository...${NC}\n"
2018-02-05 19:50:24 -07:00
git clone ${domain}/${gbusername}/${gbrepo} ${defaultRepoDir}
2018-01-30 21:11:07 -07:00
}
2018-02-05 19:50:24 -07:00
2018-01-30 21:11:07 -07:00
function main(){
2018-02-05 19:50:24 -07:00
while true;do
if [ "${FIRSTRUN}" = "true" ];then
installGit
#gitSetup
gitButterSync
if [ -d ${defaultRepoDir}/${gbrepo} ];then
writeConfig "false"
continue
fi
echo "Hello, welcome to gkmanager"
echo -n "Chose an option: "
read option
fi
done
2018-01-30 21:11:07 -07:00
}
main