diff options
author | lassulus <lassulus@lassul.us> | 2021-10-05 23:18:09 +0200 |
---|---|---|
committer | lassulus <lassulus@lassul.us> | 2021-10-05 23:18:09 +0200 |
commit | 9a855d50a7619192b909e8e3657acb16ecbd5fb4 (patch) | |
tree | 404806cd8d33328661cb03591582a7d7a03bddc3 | |
parent | d8cb0a7522f27ee25846a7391540faf72efaf236 (diff) | |
parent | 1b65517b444daa190a9cb80ea85a85d49bd0d394 (diff) |
Merge remote-tracking branch 'ni/master'
-rw-r--r-- | krebs/5pkgs/simple/irc-announce/default.nix | 74 | ||||
-rw-r--r-- | krebs/5pkgs/simple/ircaids.nix | 32 | ||||
-rw-r--r-- | tv/2configs/elm-packages-proxy.nix | 105 | ||||
-rw-r--r-- | tv/2configs/gitrepos.nix | 3 |
4 files changed, 151 insertions, 63 deletions
diff --git a/krebs/5pkgs/simple/irc-announce/default.nix b/krebs/5pkgs/simple/irc-announce/default.nix index 5797b3667..7b2af0307 100644 --- a/krebs/5pkgs/simple/irc-announce/default.nix +++ b/krebs/5pkgs/simple/irc-announce/default.nix @@ -1,18 +1,8 @@ { pkgs, lib, ... }: -with lib; - pkgs.writeDashBin "irc-announce" '' set -euf - export PATH=${makeSearchPath "bin" (with pkgs; [ - coreutils - gawk - gnused - netcat - nettools - ])} - IRC_SERVER=$1 IRC_PORT=$2 IRC_NICK=$3_$$ @@ -20,57 +10,15 @@ pkgs.writeDashBin "irc-announce" '' IRC_TLS=$5 message=$6 - export IRC_CHANNEL # for privmsg_cat - - # echo2 and cat2 are used output to both, stdout and stderr - # This is used to see what we send to the irc server. (debug output) - echo2() { echo "$*"; echo "$*" >&2; } - cat2() { - awk '{ - print $0 - print $0 > "/dev/stderr" - }' - } - - # privmsg_cat transforms stdin to a privmsg - privmsg_cat() { awk '{ print "PRIVMSG "ENVIRON["IRC_CHANNEL"]" :"$0 }'; } - - tls_flag() { if [ "$IRC_TLS" -eq 1 ]; then echo "-c"; fi } - - # ircin is used to feed the output of netcat back to the "irc client" - # so we can implement expect-like behavior with sed^_^ - # XXX mkselfdestructingtmpfifo would be nice instead of this cruft - tmpdir=$(mktemp --tmpdir -d irc-announce_XXXXXXXX) - cd "$tmpdir" - mkfifo ircin - trap " - rm ircin - cd '$OLDPWD' - rmdir '$tmpdir' - trap - EXIT INT QUIT - " EXIT INT QUIT - - { - echo2 "USER $LOGNAME 0 * :$LOGNAME@$(hostname)" - echo2 "NICK $IRC_NICK" - - awk 'match($0, /PING(.*)/, m) {print "PONG", m[1]; exit}' - - # wait for MODE message - sed -n '/^:[^ ]* MODE /q' - - echo2 "JOIN $IRC_CHANNEL" - - printf '%s' "$message" \ - | privmsg_cat \ - | cat2 - - echo2 "PART $IRC_CHANNEL" - - # wait for PART confirmation - sed -n '/:'"$IRC_NICK"'![^ ]* PART /q' - - echo2 'QUIT :Gone to have lunch' - } < ircin \ - | nc $(tls_flag) "$IRC_SERVER" "$IRC_PORT" | tee -a ircin + if test "$IRC_TLS" != 1; then + unset IRC_TLS + fi + + printf %s "$message" | + ${pkgs.ircaids}/bin/ircsink \ + --nick="$IRC_NICK" \ + --port="$IRC_PORT" \ + --server="$IRC_SERVER" \ + --target="$IRC_CHANNEL" \ + ''${IRC_TLS:+--secure} '' diff --git a/krebs/5pkgs/simple/ircaids.nix b/krebs/5pkgs/simple/ircaids.nix new file mode 100644 index 000000000..566346cc9 --- /dev/null +++ b/krebs/5pkgs/simple/ircaids.nix @@ -0,0 +1,32 @@ +{ lib, pkgs, stdenv }: + +stdenv.mkDerivation rec { + pname = "ircaids"; + version = "1.0.0"; + + src = pkgs.fetchgit { + url = "https://cgit.krebsco.de/ircaids"; + rev = "refs/tags/${version}"; + sha256 = "13z9pc9vq2xq2qpavwmh7fvzvvjkc495ssxsh8cs044qflvj54b2"; + }; + + buildPhase = null; + + installPhase = '' + mkdir -p $out/bin + + cp $src/bin/ircsink $out/bin/ircsink + sed -i ' + s;^#! /bin/sh;#! ${pkgs.dash}/bin/dash; + s;^#!.*;&\nexport PATH=${lib.makeBinPath [ + pkgs.coreutils + pkgs.gawk + pkgs.gnused + pkgs.netcat + pkgs.nettools + pkgs.openssl + pkgs.utillinux + ]}; + ' $out/bin/ircsink + ''; +} diff --git a/tv/2configs/elm-packages-proxy.nix b/tv/2configs/elm-packages-proxy.nix index 097d706c6..1df8c7b70 100644 --- a/tv/2configs/elm-packages-proxy.nix +++ b/tv/2configs/elm-packages-proxy.nix @@ -60,6 +60,11 @@ in { proxy_pass $new_uri; ''; + + locations."/search.json".extraConfig = '' + proxy_pass http://127.0.0.1:${toString config.krebs.htgen.elm-packages-proxy.port}; + proxy_pass_header Server; + ''; }; krebs.htgen.elm-packages-proxy = { @@ -192,6 +197,36 @@ in { exit ;; + 'DELETE /packages/'*) + + author=$req_x_author + pname=$req_x_package + user=$req_x_user + version=$req_x_version + + zipball=${cfg.packageDir}/$author/$pname/$version/zipball + elmjson=$HOME/cache/$author%2F$pname%2F$version%2Felm.json + endpointjson=$HOME/cache/$author%2F$pname%2F$version%2Fendpoint.json + + if test -e "$zipball"; then + zipball_owner=$(attr -q -g X-User "$zipball" || :) + if test "$zipball_owner" = "$req_x_user"; then + echo "user $user is deleting package $author/$pname@$version" >&2 + rm -f "$elmjson" + rm -f "$endpointjson" + rm "$zipball" + string_response 200 OK \ + "package deleted: $author/$pname@$version" \ + text/plain + exit + else + string_response 403 Forbidden \ + "package already exists: $author/$pname@$version" \ + text/plain + exit + fi + fi + ;; 'GET /all-packages'|'POST /all-packages') response=$(mktemp -t htgen.$$.elm-packages-proxy.all-packages.XXXXXXXX) @@ -248,6 +283,76 @@ in { file_response 200 OK "$response" 'application/json; charset=UTF-8' exit ;; + 'GET /search.json') + + searchjson=$HOME/cache/search.json + mkdir -p "$HOME/cache" + + # update cached search.json + ( + last_modified=$( + if test -f "$searchjson"; then + date -Rr "$searchjson" + else + date -R -d @0 + fi + ) + tempsearchjson=$(mktemp "$searchjson.XXXXXXXX") + trap 'rm "$tempsearchjson" >&2' EXIT + curl -fsS --compressed https://package.elm-lang.org/search.json \ + -H "If-Modified-Since: $last_modified" \ + -o "$tempsearchjson" + if test -s "$tempsearchjson"; then + mv "$tempsearchjson" "$searchjson" + trap - EXIT + fi + ) + + response=$(mktemp -t htgen.$$.elm-packages-proxy.search.XXXXXXXX) + trap 'rm "$response" >&2' EXIT + + { + printf '{"upstream":'; cat "$searchjson" + printf ',"private":'; (cd ${cfg.packageDir}; find -mindepth 3 -maxdepth 3) | + jq -Rs ' + split("\n") | + map( + select(.!="") | + match("^\\./(?<author>[^/]+)/(?<pname>[^/]+)/(?<version>[^/]+)$").captures | + map({key:.name,value:.string}) | + from_entries + ) | + map({ + key: "\(.author)/\(.pname)", + value: .version, + }) | + from_entries + ' + printf '}' + } | + jq -c ' + reduce .upstream[] as $upstreamItem ({ private, output: [] }; + .private[$upstreamItem.name] as $privateItem | + if $privateItem then + .output += [$upstreamItem * { version: $privateItem.version }] | + .private |= del(.[$upstreamItem.name]) + else + .output += [$upstreamItem] + end + ) | + + .output + (.private | to_entries | sort_by(.key) | map({ + name: .key, + version: .value, + summary: "dummy summary", + license: "dummy license", + })) + ' \ + > $response + + file_response 200 OK "$response" 'application/json; charset=UTF-8' + exit + ;; esac ''}''; }; diff --git a/tv/2configs/gitrepos.nix b/tv/2configs/gitrepos.nix index 1586f3b33..2b8457e40 100644 --- a/tv/2configs/gitrepos.nix +++ b/tv/2configs/gitrepos.nix @@ -83,6 +83,9 @@ let { htgen = { cgit.desc = "toy HTTP server"; }; + ircaids = { + cgit.desc = "Assortment of aids for working with Internet relay chat"; + }; krops = { cgit.desc = "deployment tools"; }; |