Update linkloc

master
89wc 2023-09-05 20:01:17 +00:00
parent 6d766bf31f
commit c3632f3020
1 changed files with 6 additions and 11 deletions

17
linkloc
View File

@ -1,16 +1,11 @@
#!/bin/bash #!/bin/bash
if [ -z $1 ]; then echo "linkInvalid"; exit 1; fi; if [ -z "${1}" ]; then echo "linkInvalid"; exit 1; fi;
URL="${1}"
HEADS=$(curl -L --head --silent -A "getloc" "$URL"); LOCATION=$(\
STATUS=$(echo "$HEADS" | head -1); curl -L --head --silent -A "getloc" "${1}" | grep -ie '^location' \
LOCATION=$(echo "$HEADS" | grep -ie '^location' | grep -e 'http../' \ | grep -e 'http../' | tail -1 | cut -d'?' -f1 | cut -d' ' -f2 \
| tail -1 | cut -d'?' -f1 | cut -d' ' -f2 | sed 's@^.*reddit.com@https://old.reddit.com@' \ | sed 's@^.*reddit.com@https://old.reddit.com@' \
) )
if [ -z "$LOCATION" ]; then echo "${1}"; else echo "$LOCATION"; fi
if [ -z "$LOCATION" ]; then
echo "$URL"; exit 2;
fi
echo "$LOCATION"