@@ -825,17 +825,63 @@ remove() {
825825
826826}
827827
828- update () {
828+ update_cache () {
829829 TITLE " > UPDATE distro data from remote"
830830 fetch_distro_data " online" true
831831}
832832
833- _reset () {
834- # TODO
835- TITLE " [TODO]"
833+ # To upgrade tool with git
834+ # by maintaining a local cache
835+ _upgrade () {
836+ local branch=$1
837+
838+ # place to store repository
839+ repo_cache=" ${HOME} /.fs-manager-udroid"
840+ repo_url=" https://github.com/RandomCoderOrg/fs-manager-udroid"
841+
842+ # check if repo exists and clone it if not found
843+ if [[ ! -d $repo_cache ]]; then
844+ LOG " upgrade(): cloning repo"
845+ git clone $repo_url $repo_cache || DIE " failed to upgrade"
846+ fi
836847
848+ # check if branch is specified
849+ if [[ -z $branch ]]; then
850+ LOG " upgrade(): no branch specified, using master"
851+ branch=" main"
852+ fi
853+
854+ # if repo is not in $branch checkout to $branch
855+ if [[ $( git -C $repo_cache branch --show-current) != " $branch " ]]; then
856+ LOG " upgrade(): switching to branch $branch "
857+ git -C $repo_cache checkout $branch
858+ fi
859+
860+ # pull latest changes, if conflict occurs, clean and pull again
861+ git -C $repo_cache pull || {
862+ LOG " upgrade(): conflict occured, cleaning and pulling again"
863+ git -C $repo_cache reset --hard
864+ git -C $repo_cache pull
865+ }
866+
867+ # change to repo directory and install it
868+ cd $repo_cache || {
869+ ELOG " upgrade(): failed to change to $repo_cache "
870+ exit 1
871+ }
872+
873+ # install
874+ LOG " upgrade(): installing"
875+ bash install.sh
876+
877+ # TODO: look out for commit hashes to see if upgrade is needed
837878
838879}
880+
881+ _reset () {
882+ # TODO
883+ TITLE " [TODO] RESET"
884+ }
839885# ###################
840886download () {
841887 local name=$1
890936while [ $# -gt 0 ]; do
891937 case $1 in
892938 install | --install|-i) shift 1; install $@ ; break ;;
893- update | --update|-u) shift 1; update $@ ; break ;;
939+ upgrade | --upgrade|-u) shift 1; _upgrade " revamp-v2.5" ; break ;;
940+ --update-cache) shift 1; update_cache $@ ; break ;;
894941 login | --login|-l) shift 1; login $@ ; break ;;
895942 remove | --remove | --uninstall ) shift 1 ; remove $@ ; break ;;
896943 reset | --reset | --reinstall ) shift 1 ; _reset $@ ; break ;;
0 commit comments