aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.SRCINFO15
-rw-r--r--.gitignore3
-rw-r--r--PKGBUILD24
-rw-r--r--fetcher.install6
-rw-r--r--fetcher.service13
-rwxr-xr-xfetcher.sh134
6 files changed, 195 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..4966c316948c
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,15 @@
+pkgbase = fetcher
+ pkgdesc = Update a list of git repos
+ pkgver = 1.0
+ pkgrel = 0
+ install = fetcher.install
+ arch = any
+ license = MIT
+ depends = git
+ source = fetcher.sh
+ source = fetcher.service
+ md5sums = de164dec82476dcfc15efad1b9617792
+ md5sums = ac026457052512cfdb9ae12e100ea696
+
+pkgname = fetcher
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000000..6803660e373a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/src
+/pkg
+*.tar.*
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..07736b9641af
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,24 @@
+# Maintainer: Manoel Brunnen <manoel.brunnen@gmail.com>
+
+pkgname=fetcher
+pkgver=1.0
+pkgrel=0
+pkgdesc="Update a list of git repos"
+arch=('any')
+url=""
+license=('MIT')
+groups=()
+depends=('git')
+install="$pkgname.install"
+source=("fetcher.sh"
+ "fetcher.service")
+noextract=()
+md5sums=('de164dec82476dcfc15efad1b9617792'
+ 'ac026457052512cfdb9ae12e100ea696')
+
+package() {
+ install -Dm644 $srcdir/fetcher.service $pkgdir/usr/lib/systemd/system/fetcher@$USER.service
+ install -Dm755 $srcdir/fetcher.sh $pkgdir/usr/bin/fetcher
+}
+
+# vim:set ft=sh:
diff --git a/fetcher.install b/fetcher.install
new file mode 100644
index 000000000000..0009b115d473
--- /dev/null
+++ b/fetcher.install
@@ -0,0 +1,6 @@
+post_install() {
+ echo ================================== Important =================================
+ echo Enable the fetcher daemon with:
+ echo systemctl enable fetcher@\$USER.service
+ echo ==============================================================================
+}
diff --git a/fetcher.service b/fetcher.service
new file mode 100644
index 000000000000..272a1afd2b17
--- /dev/null
+++ b/fetcher.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Update some git repos
+Wants=network-online.target
+After=network-online.target
+
+[Service]
+Type=simple
+User=%i
+ExecStart=/bin/bash /usr/bin/fetcher -f=/home/%i/.config/fetcher.conf
+
+[Install]
+WantedBy=multi-user.target
+; vim:set ft=systemd:
diff --git a/fetcher.sh b/fetcher.sh
new file mode 100755
index 000000000000..25626dac53e8
--- /dev/null
+++ b/fetcher.sh
@@ -0,0 +1,134 @@
+#!/bin/bash
+#===============================================================================
+# AUTHOR: Manoel Brunnen, manoel.brunnen@gmail.com
+# CREATED: 21.07.2016
+# LICENSE: MIT
+# FILE: fetcher.sh
+# USAGE: ./fetcher.sh
+#
+# DESCRIPTION: update some git repos
+#
+# No warranty! For nothing. Use it at your own risk.
+#===============================================================================
+set -e
+set -o nounset # Treat unset variables as an error
+
+#================================== Logging ==================================
+script_name=`basename "${BASH_SOURCE[0]}"`
+
+# Backup stdout(&1) and stderr(&2) to fd 3 and fd 4
+exec 3>&1 4>&2
+# Restore stdout and stderr
+trap 'exec 2>&4 1>&3' 0 1 2 3
+# Use tee to redirect fd 1 to logfile.out and to stdout
+exec 1> >(tee >(systemd-cat --identifier="$script_name" --priority="debug") >&3)
+# Use tee to redirect fd 2 to logfile.err and to stderr
+exec 2> >(tee >(systemd-cat --identifier="$script_name" --priority="warning") >&4)
+
+#================================= Functions =================================
+function config_usage() {
+ echo "Create your fetcher config file $configfile like this:"
+ echo $HOME/workspace/repo pull
+ echo $HOME/.vim pull
+ echo $HOME/workspace/project1 pull origin master:master
+ echo $HOME/workspace/project2 alias
+}
+
+#============================== Parsing Options ==============================
+dryrun=false
+configfile="$HOME/.config/fetcher.conf"
+
+for i in "$@"
+do
+case $i in
+ -n|--dryrun)
+ dryrun=true
+ ;;
+ -f=*|--file=*)
+ configfile="${i#*=}"
+ ;;
+ -h|--help)
+ echo $script_name' Options:'
+ echo -h, --help Show this information
+ echo -n, --dryrun Do a dry run
+ echo -f=, --file= Use another input file for fetcher
+ echo
+ config_usage
+ exit
+ ;;
+ *)
+ # unknown option
+ ;;
+esac
+done
+
+if [ ! -f $configfile ]; then
+ echo "Configuration file \"$configfile\" not found." >&2
+ config_usage
+ exit
+fi
+
+#================================ Parse lines ================================
+readarray -t lines < $configfile
+
+if [ ${#lines[@]} -eq 0 ]; then
+ config_usage
+ exit
+fi
+
+for ((i=0; i < ${#lines[@]}; i++)); do
+ line="${lines[$i]}"
+
+ IFS=' ' read -r -a line <<< "$line"
+ eval path=${line[0]}
+ eval gitcmd=${line[1]}
+ remote=''
+ branch=''
+
+ if [ ${#line[@]} -gt 2 ]; then
+ eval remote=${line[2]}
+ fi
+
+ if [ ${#line[@]} -gt 3 ]; then
+ eval branch=${line[3]}
+ fi
+
+ case $gitcmd in
+ push)
+ if $dryrun; then
+ cmd="git -C $path add -n -A"
+ cmd="$cmd && (git -C $path commit -n -v || true)"
+ cmd="$cmd && git -C $path push -n $remote $branch"
+ else
+ cmd="git -C $path add -A"
+ cmd="$cmd && (git -C $path commit -v || true)"
+ cmd="$cmd && git -C $path push $remote $branch"
+ fi
+ ;;
+ pull)
+ if $dryrun; then
+ cmd="git -C $path pull -n $remote $branch"
+ else
+ cmd="git -C $path pull $remote $branch"
+ fi
+ ;;
+ *)
+ if $dryrun; then
+ cmd="echo 'git -C $path $gitcmd $remote $branch'"
+ else
+ cmd="git -C $path $gitcmd $remote $branch"
+ fi
+ ;;
+ esac
+
+ echo '=============================================================================='
+ echo "$script_name runs:"
+ echo "$cmd"
+ eval "$cmd"
+ echo
+done
+
+echo '=============================================================================='
+echo "fetcher processed successfully $configfile."
+echo '=============================================================================='
+