diff --git a/README.md b/README.md index 7ed0286..10c3c83 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,23 @@ A curated list of awesome Arduino hardwares, libraries and projects * [Smart Garden](http://www.instructables.com/id/Smart-Garden-1/?ALLSTEPS) - clone of Erbbie * [Temperature controlled craft beer coolbox](http://www.instructables.com/id/temperature-controlled-craft-beer-coolbox/) - a coolbox in which you can control the temperature in three separate compartments +## usage + +```bash +usage() +{ + echo "" + echo " usage:" + echo "" + echo "./update.sh " + echo " where is one of:" + echo " --install-or-update (does full installation or update.)" + echo " --remove (removes all installed)" + echo "" + echo "example:" + echo ' $ ./update.sh --install-or-update' +} +``` ## Contributing * [Contributing](https://github.com/lembed/awesome-arduino/blob/master/CONTRIBUTING.md) diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..8a4f61c --- /dev/null +++ b/update.sh @@ -0,0 +1,128 @@ +#!/bin/bash + +INFILE='README.md' +OUTFILE='.tmp' + +usage() +{ + echo "" + echo " usage:" + echo "" + echo "./update.sh " + echo " where is one of:" + echo " --install-or-update (does full installation or update.)" + echo " --remove (removes all installed)" + echo "" + echo "example:" + echo ' $ ./update.sh --install-or-update' +} + +function check +{ + + git --version >/dev/null + if [ $? -ne 0 ] + then + echo "no git command found ! please download and install" + exit + fi + : +} + +function pure_context +{ + # zero list + >$2 + + for LINE in $(cat $1) + do + rs=$(echo $LINE | grep "github" ) + if [[ "$rs" != "" ]]; then + rt=$(echo $LINE | grep "Projects" ) + if [[ "$rt" != "" ]]; then + continue + fi + rl=$(echo $LINE | awk -F '(' '{print $2}' | awk -F ')' '{print $1}' ) + echo "$rl" >> $OUTFILE + fi + : + done +} + + + +function is_git +{ + isg=$(cat $1/.git/config) + if [[ "$isg" == "" ]]; then + return "0" + else + return "1" + fi +} + + +function do_update +{ + + for LINE in $(cat $1) + do + instant=$(echo $LINE | awk -F '/' '{print $5}' ) + echo $instant + if [[ "$instant" == "" ]]; then + continue + echo "noting" + fi + + if [ -d "$instant" ]; then + ig=is_git "$instant" + if [[ "$ig" == "0" ]]; then + rm -rf $instant + git clone "$LINE" & + fi + git pull origin master ; echo "$instant" + else + git clone "$LINE" & + fi + : + done +} + +function do_del +{ + + for LINE in $(cat $1) + do + instant=$(echo $LINE | awk -F '/' '{print $5}' ) + echo $instant + if [[ "$instant" == "" ]]; then + continue + fi + echo $instant + if [ -d "$instant" ]; then + rm -rf $instant + fi + : + done +} + + +# main +check + +if [ $# -eq 1 -a "$1" == "--install-or-update" ]; then + pure_context $INFILE $OUTFILE + do_update $OUTFILE + rm -rf $OUTFILE + exit +fi + +if [ $# -eq 1 -a "$1" == "--remove" ]; then + pure_context $INFILE $OUTFILE + do_del $OUTFILE + rm -rf $OUTFILE + exit +fi + + +usage \ No newline at end of file