Mediawiki installation/write wmf-shared git-branches-tags2home ext-tags-and-branches.sh

From Biowikifarm Metawiki
Jump to: navigation, search

Run script write_wmf-shared_git-branches-tags2home_ext-tags-and-branches.sh not as copy and paste but from the command line. You can make the script executable by

# uog means: user who owns it (u), other users in the file's group (g), other users (o)
chmod u+x write_wmf-shared_git-branches-tags2home_ext-tags-and-branches.sh # add executable mode for the owned user
#!/bin/bash
# @name: write_wmf-shared_git-branches-tags2home_ext-tags-and-branches.sh
# @description: write git branch and tag of all extensions in /usr/share/mw-wmf-clone/extensions
#    to a file in the home directory: wmf-extensions_tags_and_branches.txt
# @requires: a previous git pull and quick-update in /usr/share/mw-wmf-clone/extensions

if ! [ -d /usr/share/mw-wmf-clone/extensions ];then 
  echo "# Stop: /usr/share/mw-wmf-clone/extensions dos not exist (stop here. exit: 1)"
  exit 1;
else
  echo '# Write git tags and branches to ~/wmf-extensions_tags_and_branches.txt'
fi

##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# 1. INFORMATION ONLY:
# LIST (and write to file) git tags / git branches of all extensions 
# Write into file in the user's home folder
# (Note: Ignore error about /mw-wmf-clone/extensions/extensions)
printf "\n"  > ~/"wmf-extensions_tags_and_branches.txt"; 
IFS=$'\n'; # change internal Field Separator to newline only; test: printf %q "$IFS"; default $' \t\n'
all_wmf_extensions=`find /usr/share/mw-wmf-clone/extensions -maxdepth 1 -not -name '.*' -type d -printf "%f\n" | sort`
n_maxchar_ext=`echo "$all_wmf_extensions" | wc --max-line-length`
n_ext=` echo "$all_wmf_extensions" | wc --lines`
i_ext=1
for this_ext in `find /usr/share/mw-wmf-clone/extensions -maxdepth 1 -not -name '.*' -type d -printf "%f\n" | sort`; do 
  if [ -d "/usr/share/mw-wmf-clone/extensions/$this_ext" ]; then
    printf "# extension (%3d of %3d) %-${n_maxchar_ext}s: append git branch/tag into your home directory: '~/wmf-extensions_tags_and_branches.txt'\n" "$i_ext" "$n_ext" "'$this_ext'"
    printf "\n%s" "$this_ext" >> ~/"wmf-extensions_tags_and_branches.txt"; 
    cd "/usr/share/mw-wmf-clone/extensions/$this_ext";
    # List all extensions with their branches, write into same file
    branches=""; branches=`git branch --remotes | sort --version-sort --ignore-case | sed 's@^ \+\(.\+\)[ ]*$@\1@;$!{ s@$@,@;}' | fmt - | sed 's@^\(.\+\)@    \1@;'`
    if [ "$branches" != "" ]; then 
      printf "\n  branches:\n%s" "$branches"  >> ~/"wmf-extensions_tags_and_branches.txt"; 
    else 
      printf "\n" >> ~/"wmf-extensions_tags_and_branches.txt"; 
    fi
    # List all extensions with their tags, write into same file
    tags=""; tags=`git tag --list | sort --version-sort --ignore-case | sed 's@^ \+\(.\+\)[ ]*$@\1@;$!{ s@$@,@;}' | fmt - | sed 's@^\(.\+\)@    \1@;'` ; 
    if [ "$tags" != "" ]; then 
      printf "\n  tags:\n%s" "$tags" >> ~/"wmf-extensions_tags_and_branches.txt"; 
    else 
      printf "\n"  >> ~/"wmf-extensions_tags_and_branches.txt"; 
    fi
  fi
  i_ext=$((i_ext + 1))
done;
cd /usr/share/mw-wmf-clone/extensions
IFS=$' \t\n';
# end list extensions' tags and branches