From 9fd9d1d5d64cd17de25346f5f12ce20a5b3bda1c Mon Sep 17 00:00:00 2001 From: Christian Ulrich Date: Sun, 1 Mar 2020 13:02:34 +0100 Subject: [PATCH] add old scripts --- authentication/htpasswd-b | 33 ++++++++ disk/find_large_files.sh | 2 + encryption/close_container.sh | 77 +++++++++++++++++ encryption/open_container.sh | 89 ++++++++++++++++++++ gentoo/depends_on_old_libs.sh | 2 + gentoo/find_all_modules.sh | 5 ++ gentoo/list_modules.sh | 2 + gentoo/list_overlay_packages.sh | 2 + gentoo/rebuild_after_gcc_upgrade.sh | 6 ++ gentoo/tp_charging_thresholds.sh | 5 ++ gentoo/upgrade.sh | 2 + gentoo/upgrade_with_messages.sh | 2 + kvm/vm_setup.sh | 11 +++ mail/mailadmin.sh | 105 +++++++++++++++++++++++ network/open_door/open_door.desktop | 8 ++ network/open_door/open_door.sh | 17 ++++ network/upnp_ip_address.sh | 2 + openwrt/choose_wifi.sh | 124 ++++++++++++++++++++++++++++ openwrt/ddns_gandi.sh | 22 +++++ random/random_string.sh | 2 + 20 files changed, 518 insertions(+) create mode 100755 authentication/htpasswd-b create mode 100755 disk/find_large_files.sh create mode 100755 encryption/close_container.sh create mode 100755 encryption/open_container.sh create mode 100755 gentoo/depends_on_old_libs.sh create mode 100755 gentoo/find_all_modules.sh create mode 100755 gentoo/list_modules.sh create mode 100755 gentoo/list_overlay_packages.sh create mode 100755 gentoo/rebuild_after_gcc_upgrade.sh create mode 100755 gentoo/tp_charging_thresholds.sh create mode 100755 gentoo/upgrade.sh create mode 100755 gentoo/upgrade_with_messages.sh create mode 100755 kvm/vm_setup.sh create mode 100755 mail/mailadmin.sh create mode 100755 network/open_door/open_door.desktop create mode 100755 network/open_door/open_door.sh create mode 100755 network/upnp_ip_address.sh create mode 100755 openwrt/choose_wifi.sh create mode 100755 openwrt/ddns_gandi.sh create mode 100755 random/random_string.sh diff --git a/authentication/htpasswd-b b/authentication/htpasswd-b new file mode 100755 index 0000000..b64c5f9 --- /dev/null +++ b/authentication/htpasswd-b @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +if (! scalar @ARGV ) { + print "Usage: htpasswd-b passwordfile user password\n"; + print "(this program automatically creates the pw file if needed.)\n"; + exit 0; +} + +@saltsource = ('a'..'z', 'A'..'Z', '0'..'9','.','/'); +$randum_num = int(rand(scalar @saltsource)); +$salt = $saltsource[$randum_num]; +$randum_num = int(rand(scalar @saltsource)); +$salt .= $saltsource[$randum_num]; + +print "salt: $salt"; + +$outf=$ARGV[0]; +$user=$ARGV[1]; +$passwd=$ARGV[2]; + +if ($user && $passwd) { + $encrypted = crypt($passwd, "$salt"); + + if (-f $outf) { + open(OUT, ">>$outf") || die "htpasswd-b error: $!\n"; + } else { + open(OUT, ">$outf") || die "htpasswd-b error: $!\n"; + } + print OUT "$user:$encrypted\n"; + close(OUT); + + exit 0; +} diff --git a/disk/find_large_files.sh b/disk/find_large_files.sh new file mode 100755 index 0000000..b3054f1 --- /dev/null +++ b/disk/find_large_files.sh @@ -0,0 +1,2 @@ +#!/bin/bash +find $1 -type f -printf '%s %p\n'| sort -nr | head -30 diff --git a/encryption/close_container.sh b/encryption/close_container.sh new file mode 100755 index 0000000..d5e4086 --- /dev/null +++ b/encryption/close_container.sh @@ -0,0 +1,77 @@ +#!/bin/bash +# script to close a LUKS encrypted container file (use open_container.sh to open) +# -must be run with root privileges +# -start it without any or with 3 arguments: ./open_container.sh /path/to/container mapper_filename /path/to/mount_point +# written by Christian Ulrich (based on a script from http://wiki.ubuntuusers.de/LUKS/Containerdatei) +# version: 0.2 +# date: 2011/09/13 + +run=1 +choice= + +if test $# -ne 0; then + if test $# -ne 3; then + echo "Aufruf des Skripts entweder ohne Argumante oder: ./close_container /Pfad/zum/Container mapper_filename /Pfad/zum/Mountpoint" + exit 1 + else + SAFE=$1 + CRYPTNAME=$2 + MNT=$3 + fi +else + SAFE=/home/christian/privat/encrypted + CRYPTNAME=container + MNT=/home/christian/mnt +fi +LOOPDEV=`losetup -a | grep "$SAFE" | sed "s/: .*//"` + +echo "close_container.sh v0.2 (by Christian Ulrich) +---------------------------------------------" + +while [ $run -ne 0 ]; do + echo + echo "Bitte wählen:" + echo "-------------" + echo "[1] Pfad zum Container ändern ($SAFE)" + echo "[2] Dateiname in /dev/mapper/ ändern ($CRYPTNAME)" + echo "[3] Mount-Pfad ändern ($MNT)" + echo "---------------------------------------------------" + echo "[c] Container schließen" + echo "[q] Script beenden" + read choice + case $choice in + 1 ) echo "Neuen Pfad eingeben oder um abzubrechen (aktueller Pfad: $SAFE):" + SAFE_tmp= + read SAFE_tmp + if [[ -n "$SAFE_tmp" ]]; then #if only was pressed + SAFE=$SAFE_tmp + fi + ;; + 2 ) echo "Neuen Dateinamen eingeben oder um abzubrechen (aktueller Dateiname: $CRYPTNAME):" + CRYPTNAME_tmp= + read CRYPTNAME_tmp + if [[ -n "$CRYPTNAME_tmp" ]]; then + CRYPTNAME=$CRYPTNAME_tmp + fi + ;; + 3 ) echo "Neuen Mount-Pfad eingeben oder um abzubrechen (aktueller Pfad: $MNT):" + MNT_tmp= + read MNT_tmp + if [[ -n "$MNT_tmp" ]]; then + MNT=$MNT_tmp + fi + ;; + 'c' ) run=0 + if [ "`losetup -a | grep -c "$SAFE"`" != "1" ]; then + echo "nicht eingehängt" + exit + fi + umount $MNT + cryptsetup luksClose $CRYPTNAME + losetup -d $LOOPDEV + echo "Container geschlossen" + ;; + 'q' ) run=0;; + * ) echo "Falsche Eingabe!";; + esac +done diff --git a/encryption/open_container.sh b/encryption/open_container.sh new file mode 100755 index 0000000..dd98454 --- /dev/null +++ b/encryption/open_container.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# script to open a LUKS encrypted container file (use close_container.sh to close) +# -must be run with root privileges +# -start it without any or with 2 arguments: ./open_container.sh /path/to/container /path/to/mount_point +# written by Christian Ulrich (based on a script from http://wiki.ubuntuusers.de/LUKS/Containerdatei) +# version: 0.2 +# date: 2011/09/13 + +run=1 +choice= +CRYPTNAME=container +FS=ext4 +LOOPDEV=`losetup -f` + +if test $# -ne 0; then + if test $# -ne 2; then + echo "Aufruf des Skripts entweder ohne Argumante oder: ./open_container /Pfad/zum/Container /Pfad/zum/Mountpoint" + exit 1 + else + SAFE=$1 + MNT=$2 + fi +else + SAFE=/home/christian/privat/encrypted + MNT=/home/christian/mnt +fi + +echo "open_container.sh v0.2 (by Christian Ulrich) +---------------------------------------------" + +while [ $run -ne 0 ]; do + echo + echo "Bitte wählen:" + echo "-------------" + echo "[1] Pfad zum Container ändern ($SAFE)" + echo "[2] Dateiname in /dev/mapper/ ändern ($CRYPTNAME)" + echo "[3] Mount-Pfad ändern ($MNT)" + echo "[4] Dateisystem ändern ($FS)" + echo "---------------------------------------------------" + echo "[o] Container öffnen" + echo "[q] Script beenden" + read choice + case $choice in + 1 ) echo "Neuen Pfad eingeben oder um abzubrechen (aktueller Pfad: $SAFE):" + SAFE_tmp= + read SAFE_tmp + if [[ -n "$SAFE_tmp" ]]; then #if only was pressed + SAFE=$SAFE_tmp + fi + ;; + 2 ) echo "Neuen Dateinamen eingeben oder um abzubrechen (aktueller Dateiname: $CRYPTNAME):" + CRYPTNAME_tmp= + read CRYPTNAME_tmp + if [[ -n "$CRYPTNAME_tmp" ]]; then + CRYPTNAME=$CRYPTNAME_tmp + fi + ;; + 3 ) echo "Neuen Mount-Pfad eingeben oder um abzubrechen (aktueller Pfad: $MNT):" + MNT_tmp= + read MNT_tmp + if [[ -n "$MNT_tmp" ]]; then + MNT=$MNT_tmp + fi + ;; + 4 ) echo "Neues Dateisystem eingeben oder um abzubrechen (aktuelles Dateisystem: $FS)" + FS_tmp= + read FS_tmp + if [[ -n "$FS_tmp" ]]; then + FS=$FS_tmp + fi + ;; + 'o' ) run=0 + echo "Container öffnen" + if [ "`losetup -a | grep -c "$SAFE"`" != "0" ]; then + echo "bereits eingehängt" + exit + fi + losetup $LOOPDEV $SAFE + cryptsetup luksOpen $LOOPDEV $CRYPTNAME + mount -t $FS /dev/mapper/$CRYPTNAME $MNT + echo "Verschlüsseltes Dateisystem ist jetzt unter $MNT gemountet und kann mit dem Skript close_container.sh wieder unmountet werden. Aufruf wie folgt:" + echo "######################## cut here ###########################" + echo "sudo ./close_container.sh $SAFE $CRYPTNAME $MNT" + echo "######################## cut here ###########################" + ;; + 'q' ) run=0;; + * ) echo "Falsche Eingabe!";; + esac +done diff --git a/gentoo/depends_on_old_libs.sh b/gentoo/depends_on_old_libs.sh new file mode 100755 index 0000000..83a0a25 --- /dev/null +++ b/gentoo/depends_on_old_libs.sh @@ -0,0 +1,2 @@ +#!/bin/bash +lsof | awk '$5 == "DEL" { print }' diff --git a/gentoo/find_all_modules.sh b/gentoo/find_all_modules.sh new file mode 100755 index 0000000..9e2eda3 --- /dev/null +++ b/gentoo/find_all_modules.sh @@ -0,0 +1,5 @@ +#!/bin/bash +for i in `find /sys/ -name modalias -exec cat {} \;`; do + /sbin/modprobe --config /dev/null --show-depends $i ; +done | rev | cut -f 1 -d '/' | rev | sort -u + diff --git a/gentoo/list_modules.sh b/gentoo/list_modules.sh new file mode 100755 index 0000000..bac623f --- /dev/null +++ b/gentoo/list_modules.sh @@ -0,0 +1,2 @@ +#!/bin/bash +find /lib/modules/4.0.5-gentoo/ -type f -iname '*.o' -or -iname '*.ko' | less diff --git a/gentoo/list_overlay_packages.sh b/gentoo/list_overlay_packages.sh new file mode 100755 index 0000000..7030cc8 --- /dev/null +++ b/gentoo/list_overlay_packages.sh @@ -0,0 +1,2 @@ +#!/bin/bash +for i in /var/db/pkg/*/*; do if ! grep gentoo $i/repository >/dev/null; then echo -e "`basename $i`\t`cat $i/repository`"; fi; done diff --git a/gentoo/rebuild_after_gcc_upgrade.sh b/gentoo/rebuild_after_gcc_upgrade.sh new file mode 100755 index 0000000..b5cfbee --- /dev/null +++ b/gentoo/rebuild_after_gcc_upgrade.sh @@ -0,0 +1,6 @@ +#!/bin/bash +while read i ; do + [ -n "$(ldd -r "$i" | grep 'libstdc++')" ] && qfile "$i" >> rebuild.packages +done < <(find $(echo $PATH | tr ':' ' ') -type f -executable) +cut -d ' ' -f1 rebuild.packages | sort -u -o rebuild.packages +emerge -1av $(cat rebuild.packages) diff --git a/gentoo/tp_charging_thresholds.sh b/gentoo/tp_charging_thresholds.sh new file mode 100755 index 0000000..f6ea5e6 --- /dev/null +++ b/gentoo/tp_charging_thresholds.sh @@ -0,0 +1,5 @@ +#! /bin/sh +echo $1 > /sys/devices/platform/smapi/BAT0/start_charge_thresh +echo $2 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh +echo "start_charging_thresh = $(cat /sys/devices/platform/smapi/BAT0/start_charge_thresh)" +echo "stop_charging_thresh = $(cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh)" \ No newline at end of file diff --git a/gentoo/upgrade.sh b/gentoo/upgrade.sh new file mode 100755 index 0000000..1b0c9d8 --- /dev/null +++ b/gentoo/upgrade.sh @@ -0,0 +1,2 @@ +#!/bin/bash +emerge --ask --update --deep --with-bdeps=y --keep-going=y --newuse --jobs world diff --git a/gentoo/upgrade_with_messages.sh b/gentoo/upgrade_with_messages.sh new file mode 100755 index 0000000..9643625 --- /dev/null +++ b/gentoo/upgrade_with_messages.sh @@ -0,0 +1,2 @@ +#!/bin/bash +emerge --ask --update --deep --with-bdeps=y --newuse world diff --git a/kvm/vm_setup.sh b/kvm/vm_setup.sh new file mode 100755 index 0000000..c30c854 --- /dev/null +++ b/kvm/vm_setup.sh @@ -0,0 +1,11 @@ +virt-install \ + --memory 7680 \ + --accelerate \ + --name christian_vm \ + --vcpus 6 \ + --disk size=450,format=raw \ + --noautoconsole \ + --graphics vnc,listen=0.0.0.0,port=5900 \ + --network bridge=br0,model=virtio \ + --os-variant=debian8 \ + --cdrom=/var/lib/libvirt/images/grml64-small_2014.11.iso diff --git a/mail/mailadmin.sh b/mail/mailadmin.sh new file mode 100755 index 0000000..497a46a --- /dev/null +++ b/mail/mailadmin.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# +# Script to add/delete users or change their passwords for +# Dovecot/Postfix using Virtual Users + +USAGE="Usage: $0 OPTION EMAIL [BASEDIR]\n\nOptions:\n\t-a: add user\n\t-d: delete user\n\t-c: change password" + +if [ ! -n "$2" ] +then + echo -e $USAGE + exit 1 +fi + +USERNAME=$(echo "$2" | cut -f1 -d@); +DOMAIN=$(echo "$2" | cut -f2 -d@); +MAIL_REGEX="^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$" + +if [[ ! "$2" =~ $MAIL_REGEX ]]; then + echo "ERROR: Invalid email address." + exit 2 +fi +ADDRESS=$2 + +if [ -n "$3" ] +then + if [ ! -d "$3" ]; then + echo -e $USAGE + echo "ERROR: BASEDIR must be a valid directory!" + echo "I would have tried $(postconf | grep ^virtual_mailbox_base | cut -f3 -d' ')" + exit 2 + else + BASEDIR="$3" + fi +else + BASEDIR="$(postconf | grep ^virtual_mailbox_base | cut -f3 -d' ')" +fi + +VMAILBOX="/etc/postfix/vmailbox" +PASSWD="$BASEDIR/$DOMAIN/passwd" +SHADOW="$BASEDIR/$DOMAIN/shadow" + +[ -d "$BASEDIR/$DOMAIN" ] || (mkdir "$BASEDIR/$DOMAIN" && chown vmail:vmail "$BASEDIR/$DOMAIN") +[ -f "$VMAILBOX" ] || (touch $VMAILBOX && echo "Warning: $VMAILBOX not existent. Creating it.") + +case $(echo $1 | cut -f2 -d-) in + # Add user + 'a') + grep_ret=1 + paths=("$PASSWD" "$SHADOW") + for p in $paths; do + grep "$USERNAME:" $p > /dev/null 2>&1 + grep_ret=$(($grep_ret && $?)) + done + grep "$ADDRESS" $VMAILBOX > /dev/null 2>&1 + if [ 1 -ne $(($grep_ret && $?)) ]; then + echo "ERROR: User $ADDRESS already exists." + exit 3 + fi + if [ -f $VMAILBOX ] + then + echo "Adding Postfix user configuration..." + echo $ADDRESS $DOMAIN/$USERNAME/ >> $VMAILBOX + postmap $VMAILBOX + + if [ $? -eq 0 ] + then + echo "Adding Dovecot user configuration..." + echo $USERNAME::5000:5000::$BASEDIR/$DOMAIN/$USERNAME >> $PASSWD + echo $USERNAME":"$(doveadm pw -s SHA512-CRYPT) >> $SHADOW + chown vmail:vmail $PASSWD && chmod 600 $PASSWD + chown vmail:vmail $SHADOW && chmod 600 $SHADOW + /etc/init.d/postfix reload + fi + + fi + ;; + + # Delete user + 'd') + echo "Deleting user $ADDRESS. Remove user's mail directory? [y/n]: " + sed -i "/$ADDRESS.*/d" $VMAILBOX + postmap $VMAILBOX + sed -i "/$USERNAME.*/d" $PASSWD + sed -i "/$USERNAME.*/d" $SHADOW + rm -rI "$BASEDIR/$DOMAIN/$USERNAME" > /dev/null 2>&1 + if [ ! -s $SHADOW ] && [ ! -s $PASSWD ] && [ $(find $BASEDIR/$DOMAIN -maxdepth 0 -type d 2>/dev/null) ]; then + echo "Remove empty directory $BASEDIR/$DOMAIN? [y/n]: " + rm -rI "$BASEDIR/$DOMAIN" > /dev/null 2>&1 + fi + /etc/init.d/postfix reload + ;; + + # Change user's password + 'c') + echo "Changing password for $ADDRESS" + sed -i "s#$USERNAME:.*#$USERNAME:$(doveadm pw -s SHA512-CRYPT)#" $SHADOW + ;; + + *) + echo -e $USAGE + ;; + +esac + +exit 0 diff --git a/network/open_door/open_door.desktop b/network/open_door/open_door.desktop new file mode 100755 index 0000000..7dadf77 --- /dev/null +++ b/network/open_door/open_door.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=Remote-Zugriff erlauben +Terminal=true +Exec=/usr/local/bin/open_door.sh +Type=Application +Terminal=false +#Icon=/path/icon.png +Categories=Utility; diff --git a/network/open_door/open_door.sh b/network/open_door/open_door.sh new file mode 100755 index 0000000..9c8d513 --- /dev/null +++ b/network/open_door/open_door.sh @@ -0,0 +1,17 @@ +#!/bin/bash +SSH_HOST=strangeplace.net +SSH_PORT=2200 +SSH_USER=karin +gsettings set org.gnome.Vino enabled true +gsettings set org.gnome.Vino prompt-enabled false +/usr/lib/vino/vino-server 2>/dev/null & +vino_pid="$!" +#echo $! > /tmp/open_door_vino.pid +ssh -C -N -R 5900:localhost:5900 -p $SSH_PORT $SSH_USER@$SSH_HOST & +ssh_pid="$!" +#echo $! > /tmp/open_door_ssh.pid +zenity --info --text "Fernzugriff aktiv!" --ok-label="Beenden" +kill $vino_pid +kill $ssh_pid +gsettings set org.gnome.Vino enabled false +gsettings set org.gnome.Vino prompt-enabled true diff --git a/network/upnp_ip_address.sh b/network/upnp_ip_address.sh new file mode 100755 index 0000000..d236e14 --- /dev/null +++ b/network/upnp_ip_address.sh @@ -0,0 +1,2 @@ +#!/bin/sh +upnpc -s | grep ^ExternalIPAddress | cut -c21- diff --git a/openwrt/choose_wifi.sh b/openwrt/choose_wifi.sh new file mode 100755 index 0000000..c5ab1ae --- /dev/null +++ b/openwrt/choose_wifi.sh @@ -0,0 +1,124 @@ +#! /bin/sh +################################################################################### +# Choose and enable wifi-interface with uci +# Usage: choose_wifi.sh [ssid] +# when argument is passed, script tries to activate wifi interface with that ssid +# else script tries to activate first match from iwlist scanning results +# +# author: Christian Ulrich +# version: 0.1 +################################################################################### + + +# function search_ssid( ssid, number_of_ifaces ) +################################################# +search_ssid(){ + found=false + current=0 + index_to_return=0 + while [ $found = false -a $current -lt $2 ] + do + uci_result=`uci get wireless.@wifi-iface[$current].ssid 2>&1` + if [ $uci_result = $1 ]; then + index_to_return=`expr $current + 1` + found=true + fi + current=`expr $current + 1` #increment counter + done + return $index_to_return +} + +# Count interfaces in /etc/config/wireless (result in $iface_counter) +# and check if any of them is enabled +###################################################################### +uci_result="0" +value_exists=true +iface_counter=0 +enabled_iface_exists=false +while [ $value_exists = true ] +do + uci_result=`uci get wireless.@wifi-iface[$iface_counter].ssid 2>&1` + if [ $? -eq 0 ]; then + #iface_counter=`expr $iface_counter + 1` #increment iface_counter + #uci_result=`uci get wireless.@wifi-iface[$iface_counter].disabled 2>/dev/null` + if [ `uci get wireless.@wifi-iface[$iface_counter].disabled 2>/dev/null` = 0 ]; then + enabled_iface_exists=true + fi + iface_counter=`expr $iface_counter + 1` #increment iface_counter + else + value_exists=false + fi +done + +# Get Wifi interface +##################### +#wifi_iface=$(cat /proc/net/wireless | grep : ) +#wifi_iface=$(echo $wifi_iface | cut -c1-$(expr $(expr index "$wifi_iface" :) - 1 )) + +# Check commandline options and start searching +################################################ +if [ $# -eq 0 ]; then + if [ $enabled_iface_exists = false ]; then # if no interface is enabled, enable first one + uci set wireless.@wifi-iface[0].disabled=0 + /etc/init.d/network reload + sleep 1 + fi + + #scan_result=`iwlist ${wifi_iface} scanning | grep ESSID` + scan_result=`iwlist scanning 2>/dev/null | grep ESSID` + if [ $? -eq 1 ]; then + sleep 1 + scan_result=`iwlist scanning 2>/dev/null | grep ESSID` + fi + #echo ${scan_result[1]} + scan_result=`echo $scan_result | tr -d 'ESSID:"'` + #scan_result=`echo $scan_result | tr -d '" '` + + index_of_ssid_to_activate=0 + for j in $scan_result + do + if [ $index_of_ssid_to_activate -eq 0 ]; then + search_ssid $j $iface_counter + index_of_ssid_to_activate=$? + if [ $index_of_ssid_to_activate -ne 0 ]; then + #ssid=$j + break + fi + fi + done + +elif [ $# -eq 1 ]; then + index_of_ssid_to_activate=0 + search_ssid $1 $iface_counter + index_of_ssid_to_activate=$? + +else + echo "usage: choose_wifi.sh [ssid]" + exit 1 +fi + + +# Evaluate results and enable the right interface with uci +########################################################### + +if [ $index_of_ssid_to_activate -eq 0 ]; then + echo "Network with SSID ${1} not defined in /etc/config/wireless." + exit 1 +fi + +i=1 +while [ $i -le $iface_counter ] +do + if [ $i -eq $index_of_ssid_to_activate ]; then + uci set wireless.@wifi-iface[`expr $i - 1`].disabled=0 + ssid=$(uci get wireless.@wifi-iface[`expr $i - 1`].ssid) + else + uci set wireless.@wifi-iface[`expr $i - 1`].disabled=1 + fi + i=`expr $i + 1` +done + +# Activate interface +########################################## +echo "Activating wifi-interface ${ssid}..." +/etc/init.d/network reload diff --git a/openwrt/ddns_gandi.sh b/openwrt/ddns_gandi.sh new file mode 100755 index 0000000..c3b768a --- /dev/null +++ b/openwrt/ddns_gandi.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +ttl=300 +ip=${1} + +second_level_domain="$domain" +subdomain="{@}" + +depth=$(echo "$domain" | grep -o "[.]" | wc -l) + +if [ "$depth" -ge 2 ]; then + second_level_domain=$(echo "$domain" | cut -s -d '.' -f ${depth}-) + subdomain=$(echo "$domain" | cut -s -d '.' -f -$((depth - 1))) +fi + +echo "second_level_domain = ${second_level_domain}" +echo "subdomain = ${subdomain}" + +curl -fs -o /dev/null -X PUT -H "Content-Type: application/json" \ + -H "X-Api-Key: ${password}" \ + -d "{\"rrset_ttl\": ${ttl}, \"rrset_values\": [\"${ip}\"]}" \ + "https://dns.api.gandi.net/api/v5/domains/${second_level_domain}/records/${subdomain}/A" diff --git a/random/random_string.sh b/random/random_string.sh new file mode 100755 index 0000000..f3ece9e --- /dev/null +++ b/random/random_string.sh @@ -0,0 +1,2 @@ +#!/bin/bash +< /dev/urandom tr -dc _.:=\;A-Z-a-z-0-9 | head -c${1:-32};echo;