]> gitweb.morketsmerke.org Git - backup.git/commitdiff
Dodanie skryptu weblinks
authorxf0r3m <jakubstasinski@protonmail.com>
Wed, 14 Feb 2024 17:31:53 +0000 (18:31 +0100)
committerxf0r3m <jakubstasinski@protonmail.com>
Wed, 14 Feb 2024 17:31:53 +0000 (18:31 +0100)
weblinks [new file with mode: 0755]

diff --git a/weblinks b/weblinks
new file mode 100755 (executable)
index 0000000..4ed819d
--- /dev/null
+++ b/weblinks
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+function det_protocol() {
+       if $(ss -ltn | grep '\*:443' > /dev/null 2>&1); then
+               echo -n "https";
+       else
+               echo -n "http";
+       fi
+}
+
+function get_fqdn() {
+       echo -n $(hostname -f);
+}
+
+function get_ip() {
+       defaultIf=$(ip route | grep 'default' | cut -d " " -f $(ip route | grep 'default' | wc -w)-);
+       echo -n $(ip addr show dev $defaultIf | grep 'inet\ ' | awk '{printf $2}' | cut -d "/" -f 1);
+}
+
+if [ "$1" = "-n" ]; then IPFlag=1; shift; fi
+
+DIR=$1;
+PROTO=$(det_protocol);
+if [ "$IPFlag" ] && [ $IPFlag -eq 1 ]; then
+       SERVER=$(get_ip);
+else
+       SERVER=$(get_fqdn);
+fi
+
+for file in $(ls -AF ${HOME}/public_html/${DIR} | sed 's,\ ,%20,g'); do
+       echo "${PROTO}://${SERVER}/~${USER}/${DIR}/$file";
+done