Implement update for git repo

This commit is contained in:
Yorick Barbanneau 2019-11-23 23:59:35 +01:00
parent 1fb4bcac81
commit 7c5a944148

View file

@ -14,6 +14,7 @@ OVERWRITE_FILE=0
repository="" repository=""
install=1 install=1
update=0
usage () usage ()
{ {
@ -310,25 +311,64 @@ define_env ()
## create bin directory ## create bin directory
[ ! -d $BIN_DIRECTORY ] && mkdir -p $BIN_DIRECTORY || printf "bin exist\n" [ ! -d $BIN_DIRECTORY ] && mkdir -p $BIN_DIRECTORY || printf "bin exist\n"
# Test parameters : we need to know if it's a git repo or a file # define mode : install, uninstall or update
[[ $1 == "uninstall" || $1 == "-u" ]] && { install=0; printf "Activate uninstall mode\n"; shift; } case $1 in
"uninstall")
install=0
printf "Activate uninstall mode\n"
shift
;;
"update")
update=1;
printf "Activate update mode\n"
shift
;;
esac
[ "$*" = "" ] && die "You must specify a bootstrap file" 10 1 [ "$*" = "" ] && die "You must specify a bootstrap file" 10 1
if [[ $* =~ ^https://.*\.git$ || $* =~ ^ssh://.*\.git$ ]] if [[ $* =~ ^https://.*\.git$ || $* =~ ^ssh://.*\.git$ ]]
then then
bin_check "git" check_bin "git"
# Check # Check
localdir="${DOTREPO}/$(basename $* .git)" localrepo="${DOTREPO}/$(basename $* .git)"
[ -d "$localdir" ] && die "destination folder for git repository already exist" 21 0 if [ $update -eq 1 ]
private:clone_repository "$*" "$localdir"
if [ -f "${localdir}/bootstrap" ]
then then
$0 "${localdir}/bootstrap" [ ! -d $localrepo ] && die "The local repository does not exist" 22 0
exit $?
# For update we need to uninstall repo, then git pull and install
current_dir=$(pwd)
$0 uninstall ${locarepo}/bootstrap
cd $localrepo
pwd
git pull
[ $? -ne 0 ] && die "$localrepo does not seems to be a git repo" 23 0
$0 bootstrap
cd $current_dir
else else
die "Can't find a \`boostrap\` file in ${repo}" 22 0 if [ $install -eq 0 ]
then
if [ -f "$localrepo" ]
then
$0 uninstall ${localrepo}/bootstrap
printf "\nRemove $localrepo folder : "
ret=$(rm -rf $localrepo)
[ $? -eq 0 ] && printf " \e[32mdone\e[0m\n" || error "$ret"
else
die "destination folder for git repository not exist in $DOTREPO" 21 0
fi
else
private:clone_repository "$*" "$localrepo"
if [ -f "${localrepo}/bootstrap" ]
then
$0 "${localrepo}/bootstrap"
exit $?
else
die "Can't find a \`boostrap\` file in ${repo}" 22 0
fi
fi
fi fi
else else
[ ! -f "$*" ] && die "$* does not exist" 10 1 [ ! -f "$*" ] && die "$* does not exist" 10 1