From 4630d10b3151f689247c0e8e7488917ee6313c7f Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 17 May 2019 12:50:48 +0200 Subject: github-hosts-sync: import 1.0.0 from painload --- .../5pkgs/simple/github-hosts-sync/src/hosts-sync | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync (limited to 'krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync') diff --git a/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync b/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync new file mode 100755 index 000000000..f36c700d8 --- /dev/null +++ b/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync @@ -0,0 +1,66 @@ +#! /bin/sh +# TODO do_work should retry until success +set -euf + +port=${port-1028} +local_painload=$HOME/painload +remote_painload="https://github.com/krebscode/painload" +local_hosts=$HOME/hosts +remote_hosts="git@github.com:krebscode/hosts.git" + +main() { + ensure_local_painload + ensure_local_hosts + is_worker && do_work || become_server +} + +ensure_local_painload() { + test -d "$local_painload" || git clone "$remote_painload" "$local_painload" +} + +ensure_local_hosts() { + test -d "$local_hosts" || git clone "$remote_hosts" "$local_hosts" +} + +become_server() { + exec socat "TCP-LISTEN:$port,reuseaddr,fork" "EXEC:$0" +} + +is_worker() { + test "${SOCAT_SOCKPORT-}" = "$port" +} + +do_work() { + # read request + req_line="$(read line && echo "$line")" + req_hdrs="$(sed -n '/^\r$/q;p')" + + set -x + + cd "$local_hosts" + git pull >&2 + + cd "$local_hosts" + find . -name .git -prune -o -type f -exec git rm \{\} \; >/dev/null + + cd "$local_painload" + git pull >&2 + + find "$local_painload/retiolum/hosts" -type f -exec cp \{\} "$local_hosts" \; + + cd "$local_hosts" + find . -name .git -prune -o -type f -exec git add \{\} \; >&2 + if git status --porcelain | grep -q .; then + git config user.email "$LOGNAME@$(hostname)" + git config user.name "$LOGNAME" + git commit -m bump >&2 + git push >&2 + fi + + echo "HTTP/1.1 200 OK" + echo + echo "https://github.com/krebscode/hosts/archive/master.tar.gz" + echo "https://github.com/krebscode/hosts/archive/master.zip" +} + +main "$@" -- cgit v1.2.3 From acb3f95fa6586a9c9b1b1ffa76368c1b39edb8aa Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 17 May 2019 13:06:36 +0200 Subject: github-hosts-sync: 1.0.0 -> 2.0.0 --- .../5pkgs/simple/github-hosts-sync/src/hosts-sync | 81 ++++++---------------- 1 file changed, 23 insertions(+), 58 deletions(-) (limited to 'krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync') diff --git a/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync b/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync index f36c700d8..4bae44bef 100755 --- a/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync +++ b/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync @@ -1,66 +1,31 @@ #! /bin/sh -# TODO do_work should retry until success -set -euf +set -efu +exec >&2 -port=${port-1028} -local_painload=$HOME/painload -remote_painload="https://github.com/krebscode/painload" -local_hosts=$HOME/hosts -remote_hosts="git@github.com:krebscode/hosts.git" +hosts_srcdir=$GITHUB_HOST_SYNC_SRCDIR +hosts_worktree=${GITHUB_HOST_SYNC_WORKTREE-/tmp/hosts} +hosts_url=${GITHUB_HOST_SYNC_URL-git@github.com:krebscode/hosts.git} -main() { - ensure_local_painload - ensure_local_hosts - is_worker && do_work || become_server -} +test -d "$hosts_worktree" || git clone "$hosts_url" "$hosts_worktree" -ensure_local_painload() { - test -d "$local_painload" || git clone "$remote_painload" "$local_painload" -} +cd "$hosts_worktree" -ensure_local_hosts() { - test -d "$local_hosts" || git clone "$remote_hosts" "$local_hosts" -} +git pull -become_server() { - exec socat "TCP-LISTEN:$port,reuseaddr,fork" "EXEC:$0" -} +rsync \ + --chmod D755,F644 \ + --delete-excluded \ + --filter 'protect .git' \ + --recursive \ + --verbose \ + "$hosts_srcdir/" \ + . -is_worker() { - test "${SOCAT_SOCKPORT-}" = "$port" -} +git add . -do_work() { - # read request - req_line="$(read line && echo "$line")" - req_hdrs="$(sed -n '/^\r$/q;p')" - - set -x - - cd "$local_hosts" - git pull >&2 - - cd "$local_hosts" - find . -name .git -prune -o -type f -exec git rm \{\} \; >/dev/null - - cd "$local_painload" - git pull >&2 - - find "$local_painload/retiolum/hosts" -type f -exec cp \{\} "$local_hosts" \; - - cd "$local_hosts" - find . -name .git -prune -o -type f -exec git add \{\} \; >&2 - if git status --porcelain | grep -q .; then - git config user.email "$LOGNAME@$(hostname)" - git config user.name "$LOGNAME" - git commit -m bump >&2 - git push >&2 - fi - - echo "HTTP/1.1 200 OK" - echo - echo "https://github.com/krebscode/hosts/archive/master.tar.gz" - echo "https://github.com/krebscode/hosts/archive/master.zip" -} - -main "$@" +if test -n "$(git status --porcelain)"; then + git config user.email "$LOGNAME@$(hostname)" + git config user.name "$LOGNAME" + git commit -m bump + git push +fi -- cgit v1.2.3 From c7cfc7d6a3988615fd40369d0e02bd570a52bc7f Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 17 May 2019 13:43:13 +0200 Subject: github-hosts-sync: update default URL --- krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync') diff --git a/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync b/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync index 4bae44bef..d2017ef63 100755 --- a/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync +++ b/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync @@ -4,7 +4,7 @@ exec >&2 hosts_srcdir=$GITHUB_HOST_SYNC_SRCDIR hosts_worktree=${GITHUB_HOST_SYNC_WORKTREE-/tmp/hosts} -hosts_url=${GITHUB_HOST_SYNC_URL-git@github.com:krebscode/hosts.git} +hosts_url=${GITHUB_HOST_SYNC_URL-git@github.com:krebs/hosts.git} test -d "$hosts_worktree" || git clone "$hosts_url" "$hosts_worktree" -- cgit v1.2.3 From a666abeaabbed73749cd5e2f1745b4a4527c4bc6 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 17 May 2019 14:02:22 +0200 Subject: github-hosts-sync: make user name/mail overridable --- krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync') diff --git a/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync b/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync index d2017ef63..a8973e72b 100755 --- a/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync +++ b/krebs/5pkgs/simple/github-hosts-sync/src/hosts-sync @@ -5,6 +5,8 @@ exec >&2 hosts_srcdir=$GITHUB_HOST_SYNC_SRCDIR hosts_worktree=${GITHUB_HOST_SYNC_WORKTREE-/tmp/hosts} hosts_url=${GITHUB_HOST_SYNC_URL-git@github.com:krebs/hosts.git} +user_mail=${GITHUB_HOST_SYNC_USER_MAIL-$LOGNAME@$(hostname)} +user_name=${GITHUB_HOST_SYNC_USER_NAME-$LOGNAME} test -d "$hosts_worktree" || git clone "$hosts_url" "$hosts_worktree" @@ -24,8 +26,8 @@ rsync \ git add . if test -n "$(git status --porcelain)"; then - git config user.email "$LOGNAME@$(hostname)" - git config user.name "$LOGNAME" + git config user.email "$user_mail" + git config user.name "$user_name" git commit -m bump git push fi -- cgit v1.2.3