dot

packages and services management
Log | Files | Refs | README

commit 8bcaa9f70ea4592172d133fb5d84fec9c4adead3
parent 0bf4841462facbc4b390558a6a21cff5ee404aa2
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun,  8 Jul 2018 01:45:49 +0200

Merge branch 'master' of josuah.net:conf

Diffstat:
Abin/ics2txt | 182+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mbin/pack | 26+++++++++++---------------
Abin/pass | 15+++++++++++++++
Abin/txt2ics | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdata/ics/josuah.ics | 8++++++++
Mdot/mpoprc | 2+-
Mdot/profile | 2+-
7 files changed, 311 insertions(+), 17 deletions(-)

diff --git a/bin/ics2txt b/bin/ics2txt @@ -0,0 +1,182 @@ +#!/usr/bin/awk -f +# handle ical agenda and display them in plain text + +function leap(yrs) +{ + return (yrs % 4 == 0) && (yrs % 100 != 0) || (yrs % 400 == 0); +} + +function days_per_month(mth, yrs) +{ + if (mth == 2) + return 28 + leap(yrs); + else + return 30 + (mth - (mth > 7)) % 2; +} + +function to_sec(yrs, mth, day, hrs, min, sec) +{ + while (--mth >= 1) + day += days_per_month(mth, yrs); + while (--yrs >= 1970) + day += 365 + leap(yrs); + return (((((day - 1) * 24) + hrs) * 60) + min) * 60 + sec; +} + +function to_date(fmt, sec) +{ + for (yrs = 1970; sec >= (s = 3600 * 24 * (365 + leap(yrs))); yrs++) + sec -= s; + for (mth = 1; sec >= (s = 3600 * 24 * days_per_month(mth, yrs)); mth++) + sec -= s; + for (day = 1; sec >= (s = 3600 * 24); day++) + sec -= s; + for (hrs = 0; sec >= 3600; hrs++) + sec -= 3600; + for (min = 0; sec >= 60; min++) + sec -= 60; + return sprintf(fmt, yrs, mth, day, hrs, min, sec); +} + +function date_ical(str, offset) { + yrs = substr(str, 1, 4); + mth = substr(str, 5, 2); + day = substr(str, 7, 2); + hrs = substr(str, 10, 2); + min = substr(str, 12, 2); + return to_sec(yrs, mth, day, hrs, min, 0) - offset; +} + +function date_iso8601(date, offset) +{ + yrs = substr(date, 1, 4); + mth = substr(date, 6, 2); + day = substr(date, 9, 2); + hrs = substr(date, 12, 2); + min = substr(date, 15, 2); + return to_sec(yrs, mth, day, hrs, min, 0) - offset; +} + +function swap(array, a, b) +{ + tmp = array[a]; + array[a] = array[b]; + array[b] = tmp; +} + +function sort(array, beg, end) +{ + if (beg >= end) # end recursion + return; + + a = beg + 1; # #1 is the pivot + b = end; + while (a < b) { + while (a < b && array[a] <= array[beg]) # beg: skip lesser + a++; + while (a < b && array[b] > array[beg]) # end: skip greater + b--; + swap(array, a, b); # found 2 misplaced + } + + if (array[beg] > array[a]) # put the pivot back + swap(array, beg, a); + + sort(array, beg, a - 1); # sort lower half + sort(array, a, end); # sort higher half +} + +function parse_ical(list, offset) +{ + FS = "[:;]"; + + while (getline) { + gsub("\r", " "); gsub("\\\\[ntr]", " "); gsub("\\\\", ""); + gsub("^ *", ""); gsub(" *$", ""); + gsub(" *<[a-zA-Z0-9/]*>* *", ""); + + if (match($0, "^ ")) { + event[type] = event[type] substr($0, 2, length($0) - 1); + } else { + type = $1; + i = index($0, ":"); + event[type] = substr($0, i + 1, length($0) - i); + } + + if ($0 ~ /END:VEVENT/) + list[++nb] = sprintf("%d\t%d\t%s\t%s\t%s\t%s", + date_ical(event["DTSTART"], offset), + date_ical(event["DTEND"], offset), + event["CATEGORIES"], + event["SUMMARY"], + event["LOCATION"], + event["DESCRIPTION"]); + } + sort(list, 1, nb); + return nb; +} + +function txt_one(beg, end, cat, sum, loc, des, offset) { + b = to_date("%04d/%02d/%02d %02d:%02d", beg + offset); + e = to_date("%04d/%02d/%02d %02d:%02d", end + offset); + b_mth = substr(b, 1, 7); + b_day = substr(b, 9, 2); + e_day = substr(e, 9, 2); + b_hrs = substr(b, 12); + e_hrs = substr(e, 12); + + printf("%s\n%2s %2s %s\n%2s %2s %s%s\n", + (b_mth != l_mth) ? ("\n[" b_mth "]\n") : (""), + (b_day != l_day) ? (b_day) : (""), b_hrs, sum, + (b_day != e_day) ? (e_day) : (""), e_hrs, + (cat) ? ("[" cat "] ") : (""), loc); + + while ((line = substr(des, 1, 66)) != "") { + if (length(line) == 66) + sub(" +[^ ]*$", "", line); + des = substr(des, length(line) + 2); + sub("^ *", "", line); + sub("^ *", "", des); + printf(" %s\n", line); + } + l_mth = b_mth; + l_day = b_day; +} + +function txt(offset) +{ + nb = parse_ical(list, offset); + for (i = 1; i <= nb; i++) { + split(list[i], arr, "\t"); + txt_one(arr[1], arr[2], arr[3], arr[4], arr[5], arr[6]); + } +} + +function tsv(offset) +{ + nb = parse_ical(list, offset); + for (i = 0; i < nb; i++) + print(list[i]); +} + +function usage() +{ + print("usage: ics2txt txt file.ics..."); + print(" ics2txt tsv file.ics..."); +} + +BEGIN { + #"date +%z" | getline offset; + #close("date +%z"); + offset = 0; #substr(offset, 1, 3) * 3600; + + if (ARGV[1] == "txt") { + ARGV[1] = ARGV[--ARGC]; + txt(offset); + } else if (ARGV[1] == "tsv") { + ARGV[1] = ARGV[--ARGC]; + tsv(offset); + } else { + usage(); + } +} diff --git a/bin/pack b/bin/pack @@ -9,7 +9,7 @@ export PREFIX=$DEST/opt/$2 export SOURCE=$DEST/src/$2 case $1 in -(-t) test -d "$SOURCE" && exit 0 +(tar) test -d "$SOURCE" && exit 0 mkdir -p "$SOURCE" IFS="" read -r url <$PACK/tar wget -O - "$url" | case $url in @@ -20,44 +20,40 @@ case $1 in mv "$SOURCE"/*/* "$SOURCE" rmdir "$SOURCE"/* 2>/dev/null || true ;; -(-g) test -d "$SOURCE" && exit 0 +(git) test -d "$SOURCE" && exit 0 IFS="" read -r url <$PACK/git git clone "$url" "$SOURCE" ;; -(-c) test -d "$SOURCE" && exit 0 +(cvs) test -d "$SOURCE" && exit 0 mkdir -p "$SOURCE" cd "$SOURCE" read -r url path <$PACK/cvs cvs -qd "$url" checkout -P "$path" ;; -(-d) test -f "$PACK/tar" && exec "$0" -t "$2" +(get) test -f "$PACK/tar" && exec "$0" -t "$2" test -f "$PACK/git" && exec "$0" -g "$2" test -f "$PACK/cvs" && exec "$0" -c "$2" ;; -(-b) test -d "$SOURCE" || "$0" -d "$2" +(build) test -d "$SOURCE" || "$0" -d "$2" cd "$SOURCE" mkdir -p "$PREFIX" exec "$PACK/build" ;; -(-i) test -d "$PREFIX" || "$0" -b "$2" || rm -rf "$PREFIX" +(add) test -d "$PREFIX" || "$0" -b "$2" || rm -rf "$PREFIX" cd "$PREFIX" find -L . -type d | xargs -n 1 -I {} mkdir -p "$DEST/{}" find -L . -type f | xargs -n 1 -I {} ln -sf "$PREFIX/{}" "$DEST/{}" ;; -(-r) cd "$PREFIX" +(del) cd "$PREFIX" find . -type f | xargs -I {} rm -f "$DEST/{}" rm -rf "$PREFIX" ;; -(-u) "$0" -r "$2" +(up) "$0" -r "$2" rm -rf "$SOURCE" "$0" -i "$2" ;; -(-l) ls "$PACKDIR" - ;; -(*) echo 'usage: pack -[tgcdiru] package' - echo ' -t download from tar -b build package -l list packages' - echo ' -g download from git -i install package' - echo ' -c donwload from cvs -r remove package' - echo ' -d download from any -u update package' +(*) echo 'usage: pack {tar,git,cvs,get,build,add,up} package' + echo + ls "$PACKDIR" ;; esac diff --git a/bin/pass b/bin/pass @@ -0,0 +1,15 @@ +#!/bin/sh -e + +case $1 in +(set) + dd if=/dev/random bs=48 count=1 | base64>"/mnt/key/pass/$2" + ;; +(get) + cat "/mnt/key/pass/$2" + ;; +(*) + echo 'usage: pass {add,set}' + echo + ls /mnt/key/pass/ + ;; +esac diff --git a/bin/txt2ics b/bin/txt2ics @@ -0,0 +1,93 @@ +#!/usr/bin/awk -f + +function prompt(msg) +{ + if (TTY) + printf("%s", msg) >"/dev/stderr"; + if (!getline str) + exit(1); + return str; +} + +function parse_date(str, tm) +{ + if (length(str) == 5) { + "date +%Y/%m/%d" | getline date + str = date " " str ; + close("date +%Y/%m/%d"); + } + + if (length(str) != 16) { + print("invalid date length") >"/dev/stderr"; + return -1; + } + + tm["yrs"] = substr(str, 1, 4); + if (! match(tm["yrs"], "^[0-9]+$")) { + print("invalid year: " tm["yrs"]) >"/dev/stderr"; + return -1; + } + + tm["mth"] = substr(str, 6, 2); + if (! match(tm["mth"], "^[0-1][0-9]$")) { + print("invalid month: " tm["mth"]) >"/dev/stderr"; + return -1; + } + + tm["day"] = substr(str, 9, 2); + if (! match(tm["day"], "^[0-3][0-9]$")) { + print("invalid day: " tm["day"]) >"/dev/stderr"; + return -1; + } + + tm["hrs"] = substr(str, 12, 2); + if (! match(tm["hrs"], "^[0-2][0-9]$")) { + print("invalid hours: " tm["hrs"]) >"/dev/stderr"; + return -1; + } + + tm["min"] = substr(str, 15, 2); + if (! match(tm["min"], "^[0-6][0-9]$")) { + print("invalid minutes: " tm["min"]) >"/dev/stderr"; + return -1; + } + + return 0; +} + +BEGIN { + TTY = !system("tty >/dev/null"); + + if (TTY) { + "date +%Y" | getline yrs + close("date +%Y"); + system("cal " yrs ">/dev/stderr"); + system("date >/dev/stderr"); + system("date +'%Y/%m/%d %H:%M' >/dev/stderr"); + print("") >"/dev/stderr"; + } + + do beg = prompt("Start [YYYY/MM/DD HH:MM] or [HH:MM] for today: "); + while (parse_date(beg, tm_beg) == -1); + + do end = prompt("End [YYYY/MM/DD HH:MM] or [HH:MM] for same day: "); + while (parse_date(end, tm_end) == -1); + + sum = prompt("Summary: "); + cat = prompt("Category: "); + loc = prompt("Location: "); + des = prompt("Description: "); + + print("BEGIN:VEVENT"); + print("DTSTART:" \ + tm_beg["yrs"] tm_beg["mth"] tm_beg["day"] "T" \ + tm_beg["hrs"] tm_beg["min"] "00"); + print("DTEND:" \ + tm_end["yrs"] tm_end["mth"] tm_end["day"] "T" \ + tm_end["hrs"] tm_end["min"] "00"); + if (cat) print("CATEGORIES:" cat); + if (sum) print("SUMMARY:" sum); + if (des) print("DESCRIPTION:" des); + if (loc) print("LOCATION:" loc); + print("END:VEVENT"); +} diff --git a/data/ics/josuah.ics b/data/ics/josuah.ics @@ -29,3 +29,11 @@ SUMMARY:RCV CMB talk about credits DESCRIPTION:0299263060 LOCATION:phone END:VEVENT +BEGIN:VEVENT +DTSTART:20180721T080000 +DTEND:20180707T220000 +CATEGORIES:admin +SUMMARY:rdv facteur verification identité +DESCRIPTION:Attention : Vous devez être impérativement présent à votre domicile pour une vérification en face à face de votre pièce d'identité. Aucune procuration ne sera acceptée. +LOCATION:15 rue des Bonnes Rappes, Lille +END:VEVENT diff --git a/dot/mpoprc b/dot/mpoprc @@ -8,7 +8,7 @@ account mail@josuah.net host mail.gandi.net user mail@josuah.net auth user -passwordeval "enchive -a$((3600*12)) extract /mnt/key/vault/mpop /dev/stdout" +passwordeval "pass get mail.josuah.net" delivery maildir /home/josuah/mail/INBOX keep on diff --git a/dot/profile b/dot/profile @@ -23,7 +23,7 @@ export LC_TIME=en_US.UTF-8 export PLAN9=/usr/local/9base export PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin -export PATH=/local/bin:$HOME/conf/bin:$PATH:/usr/X11R6/bin:$PLAN9/bin +export PATH=$HOME/conf/bin:/local/bin:$PATH:/usr/X11R6/bin:$PLAN9/bin export MANPATH=/usr/man:/usr/share/man:/usr/local/man:/usr/local/share/man export MANPATH=/local/share/man:$MANPATH:$PLAN9/share/man