From a265ea9d0693a25fffa2ed0eaa9622b91758f51a Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 19 Feb 2014 14:10:56 +0100 Subject: hosts sync: rename index for nicer journal --- retiolum/scripts/github_hosts_sync/hosts-sync | 64 ++++++++++++++++++++++ retiolum/scripts/github_hosts_sync/index | 64 ---------------------- .../github_hosts_sync/systemd/hosts-sync.service | 2 +- 3 files changed, 65 insertions(+), 65 deletions(-) create mode 100755 retiolum/scripts/github_hosts_sync/hosts-sync delete mode 100755 retiolum/scripts/github_hosts_sync/index (limited to 'retiolum') diff --git a/retiolum/scripts/github_hosts_sync/hosts-sync b/retiolum/scripts/github_hosts_sync/hosts-sync new file mode 100755 index 00000000..53c96efd --- /dev/null +++ b/retiolum/scripts/github_hosts_sync/hosts-sync @@ -0,0 +1,64 @@ +#! /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 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 "$@" diff --git a/retiolum/scripts/github_hosts_sync/index b/retiolum/scripts/github_hosts_sync/index deleted file mode 100755 index 53c96efd..00000000 --- a/retiolum/scripts/github_hosts_sync/index +++ /dev/null @@ -1,64 +0,0 @@ -#! /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 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 "$@" diff --git a/retiolum/scripts/github_hosts_sync/systemd/hosts-sync.service b/retiolum/scripts/github_hosts_sync/systemd/hosts-sync.service index 83609740..5fb9ed41 100644 --- a/retiolum/scripts/github_hosts_sync/systemd/hosts-sync.service +++ b/retiolum/scripts/github_hosts_sync/systemd/hosts-sync.service @@ -4,7 +4,7 @@ After=network.target [Service] EnvironmentFile=/etc/conf.d/hosts-sync.conf -ExecStart=/krebs/retiolum/scripts/github_hosts_sync/index +ExecStart=/krebs/retiolum/scripts/github_hosts_sync/hosts-sync KillMode=process User=hosts-sync Group=hosts-sync -- cgit v1.2.3