From 11856792221c7faa2f423bc106d1f4b1482bcdb8 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 1 Aug 2018 10:27:54 +0100 Subject: new url_to_id and added dry-run in burrow --- url_to_id | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'url_to_id') diff --git a/url_to_id b/url_to_id index 69cc0fc..4d96442 100755 --- a/url_to_id +++ b/url_to_id @@ -1,15 +1,25 @@ #!/bin/sh -## get a selector in gph format: +## +## Get a gopherlink in the format: +## +## gopher://domain.org:port/*/my/cool/selector +## +## or a selector in gph format: ## ## [TYPE|SEL|HOST|PORT] ## -## and print on output the corresponding selectorid: +## and print on output the corresponding "unique" selectorid: ## ## TYPE|SEL|HOST|PORT|SHA256 ## ## which is understood by `burrow` + +### +### get a selector in gph format and transform it in a selectorid +### +## function gph_to_id(){ gph="$( echo $1| sed 's/\[//g;s/\]//g')" OLDIFS=$IFS @@ -20,4 +30,45 @@ gph_to_id(){ IFS="$OLDIFS" } -gph_to_id "$1" +### +### Get a gopherurl and transform it in a selectorid +### +## function +gopherurl_to_id(){ + URL="$(echo $1 | sed 's,gopher://,,g')" + hostport=$(echo "$URL" | cut -d "/" -f 1) + host="$(echo $hostport | cut -d ":" -f 1)" + port="$(echo $hostport | cut -s -d ":" -f 2)" + [ -z "$port" ] && port='70' + type=$(echo "$URL" | cut -s -d "/" -f 2) + [ -z "$type" ] && { + type='1' + sel="/" + gph_to_id "[${type}|${sel}|${host}|$port]" + exit 0 + } + [ -n "${type#?}" ] && echo "Invalid Gopher URL" >&2 && exit 1 + ## Check if type is a valid one + type="$(echo $type | sed -n '/^[0-9ITghis+]$/p')" + [ -z "${type}" ] && echo "Invalid Gopher URL" >&2 && exit 1 + sel=/$(echo "$URL" | cut -s -d "/" -f 3-) + gph_to_id "[${type}|${sel}|${host}|$port]" + +} + + + +[ $# -lt 1 ] && echo "Usage: $0 " && echo " $0 " && exit 1 + + +[ -n "$(echo $1 | sed -n '/^gopher:\/\//p')" ] && { + gopherurl_to_id "$1" + exit 0 +} + +[ -n "$(echo $1 | sed -n '/^\[.*\]$/p')" ] && { + gph_to_id "$1" + exit 0 +} +echo "No valid URL or gph selector provided" >&2 +exit 1 -- cgit v1.2.3