Git Updater Script

bell07
Member
 
Posts: 140
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Git Updater Script

by bell07 » Sat Feb 25, 2017 20:39

Since I use mods, I install them most from git repositories. I like maintained software and I do not like to do it by self :-)
To get all the repositories in sync I am to lazy, so I has written an update script for me.

The script does work on linux, I use it with bash shell. Maybe it is usable on windows with cygwin-bash, but I did not tested it, I do not use the W$.

The script does search from current directory trough all sub-directories for git-managed repos (".git" exists) and take the git-magic. Initial working support for ".hg" is included, but I do not have currently any mercurial repos.

How to use:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
cd ~/.minetest
sh update.sh 9

The number is log-level. 0-3 is implemented, but I use mostly 9 or 99 on command line, don't ask me why .

The script:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
~/.minetest $ cat update.sh

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#!/bin/bash

VERBOSE="$1"

if  [ "$VERBOSE" == "" ]; then
   VERBOSE=0
fi

# 0: just update relevant infos
# 1 display "branch -vaa" + local changes
# 2 display log on current branch
# 3 display "remote -v"


find . -name ".git" -type d | while read repo; do
   echo ''
   echo '--------------------------------------'
   echo "$(dirname "$repo")"
   echo '--------------------------------------'

   cd "$(dirname "$repo")"

# fetch all connected remotes
   for repo in $(git remote); do
      git fetch "$repo"
   done

# Display repo status in different verbosity
   if [ "$VERBOSE" -ge 1 ]; then
      git branch -vva
   fi

# create log range
   currentbranch="$(git branch | grep '^*' | sed 's:\* ::g')"
   remotebranch="$(git branch -avv | grep '^\*' | sed 's@.*\[@@g;s@[]:].*@@g' | grep -v '^\*')"

# print the log information
   if [ "$VERBOSE" -ge 2 ]; then
      if [ "$remotebranch" == "" ]; then
         echo '!!!!! No remote branch for' $currentbranch '!!!!!!'
      else
         echo $currentbranch '=>' "$remotebranch"
         git --no-pager log  $currentbranch..$remotebranch
      fi

      if [ "$VERBOSE" -ge 3 ]; then
         git remote -v
      fi
   fi

# Now pull+merge
#   git pull. (from man git-pull: git pull is shorthand for git fetch followed by git merge FETCH_HEAD.)
   if [ ! "$remotebranch" == "" ]; then
      git merge "$remotebranch"
   fi

# display local changes
   if [ $VERBOSE -ge 1 ]; then
      git --no-pager diff #display local changes
   fi

   echo "last commit: $(git log -1 --format=%cd)"

   cd - >/dev/null
done

#########################################
# Find all ".hg" and pull them
find . -name ".hg" -type d | while read repo; do
   echo "$(dirname "$repo")"
   cd "$(dirname "$repo")"
   hg pull
   cd - >/dev/null
done
 

User avatar
Linuxdirk
Member
 
Posts: 497
Joined: Wed Sep 17, 2014 11:21
GitHub: dsohler
In-game: Linuxdirk

Re: Git Updater Script

by Linuxdirk » Sun Feb 26, 2017 18:36

bell07 wrote:To get all the repositories in sync I am to lazy, so I has written an update script for me.

I did the same. Not as complex as yours and no automatic detection (because I have Git managed stuff there I don’t want to be updated because I am the maintainer by myself).

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#! /usr/bin/env luajit

local basedir = '/home/USERNAME/.minetest/mods/'

local mods = {
    'mod_1',
    'mod_2',
    'mod_3',
    'mod_N'
}

print('Updating '..#mods..' mods\n')

for i,mod in pairs(mods) do
    print('---------------------------------------------\n'..'Processing '..mod)
    os.execute('git -C '..basedir..mod..' pull')
    print('---------------------------------------------\n')
end

Just change basedir to where your mods are located, add your mods to the mods table and run the script.
 


Return to Minetest-Related

Who is online

Users browsing this forum: No registered users and 7 guests

cron