add old scripts

master
Christian Ulrich 2020-03-01 13:02:34 +01:00
parent 5db0aab718
commit 9fd9d1d5d6
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
20 changed files with 518 additions and 0 deletions

33
authentication/htpasswd-b Executable file
View File

@ -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;
}

2
disk/find_large_files.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
find $1 -type f -printf '%s %p\n'| sort -nr | head -30

77
encryption/close_container.sh Executable file
View File

@ -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 <return> um abzubrechen (aktueller Pfad: $SAFE):"
SAFE_tmp=
read SAFE_tmp
if [[ -n "$SAFE_tmp" ]]; then #if only <return> was pressed
SAFE=$SAFE_tmp
fi
;;
2 ) echo "Neuen Dateinamen eingeben oder <return> 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 <return> 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

89
encryption/open_container.sh Executable file
View File

@ -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 <return> um abzubrechen (aktueller Pfad: $SAFE):"
SAFE_tmp=
read SAFE_tmp
if [[ -n "$SAFE_tmp" ]]; then #if only <return> was pressed
SAFE=$SAFE_tmp
fi
;;
2 ) echo "Neuen Dateinamen eingeben oder <return> 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 <return> 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 <return> 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

2
gentoo/depends_on_old_libs.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
lsof | awk '$5 == "DEL" { print }'

5
gentoo/find_all_modules.sh Executable file
View File

@ -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

2
gentoo/list_modules.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
find /lib/modules/4.0.5-gentoo/ -type f -iname '*.o' -or -iname '*.ko' | less

View File

@ -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

View File

@ -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)

View File

@ -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)"

2
gentoo/upgrade.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
emerge --ask --update --deep --with-bdeps=y --keep-going=y --newuse --jobs world

View File

@ -0,0 +1,2 @@
#!/bin/bash
emerge --ask --update --deep --with-bdeps=y --newuse world

11
kvm/vm_setup.sh Executable file
View File

@ -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

105
mail/mailadmin.sh Executable file
View File

@ -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

View File

@ -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;

17
network/open_door/open_door.sh Executable file
View File

@ -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

2
network/upnp_ip_address.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
upnpc -s | grep ^ExternalIPAddress | cut -c21-

124
openwrt/choose_wifi.sh Executable file
View File

@ -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

22
openwrt/ddns_gandi.sh Executable file
View File

@ -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"

2
random/random_string.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
< /dev/urandom tr -dc _.:=\;A-Z-a-z-0-9 | head -c${1:-32};echo;