add various scripts that could be useful to people

This commit is contained in:
Bela 2018-07-23 17:43:14 +02:00
parent ef1d366427
commit d3f061cbde
8 changed files with 1037 additions and 4 deletions

View file

@ -1 +0,0 @@
/home/felix/myconfigs/notes/Tricks.html

214
Tricks.html Executable file
View file

@ -0,0 +1,214 @@
<html>
<head>
</head>
<body>
<p>
Automatisches mounten einer Partition. <br>
Erkl&auml;rt unter https://help.ubuntu.com/community/AutomaticallyMountPartitions. <br>
Bei meinen Daten-Partitionen hat das zu den Kommandos<br>
udisksctl mount --block-device /dev/disk/by-uuid/99fb08ea-47fb-4595-9527-c259f318331c <br>
und <br>
udisksctl mount --block-device /dev/disk/by-uuid/7AB0D22F35BD16B1
gef&uuml;hrt.<br>
Unter Einstellungen - Sitzung und Startverhalten - Automatisch gestartete Anwendungen - Hinzuf&uuml;gen diesen Befehl hinzugef&uuml;gt.
</p>
<p>
Touchpad deaktivieren in Lubuntu<br>
vollst&auml;ndig deaktivieren: synclient TouchpadOFF=1 <br>
curser aktivieren, klicken deaktivieren: synclient TouchpadOFF=2 <br>
Touchpad voll aktivieren: synclient TouchpadOFF=0 <br>
Auch dieser Befehl macht sich gut im Autostart
</p>
Einstellungen f&uuml;r eduroam an der TUD:<br>
Halte dich an die Anleitung auf der ZIH-TU-Seite. Dort gibt es funktionierende Installationsprogramme (Bash-Skript für Linux, App + Config-Datei für Android)<br>
Alte Einstellungen, die offenbar nicht mehr funktionieren:<br>
Sicherheit des Funknetzwerks:<br>
Sicherheit: WPA &amp; WPA2 Enterprise <br>
Legitimierung: Gesch&uuml;tztes EAP (PEAP) <br>
Anonyme Identit&auml;t: anonymous@tu-dresden.de <br>
CA-Certifikat: von TU-Seite runter zu laden, liegt im Ordner Studium/Imma-Orga <br>
PEAP-Version: Automatisch <br>
Innere Legitimierung: MSCHAPv2 <br>
Benutzername: s-Nummer (s1140568) <br>
Passwort: das vom ZIH (nicht HISQIS)
</p>
<p>
Installation/ Einrichten von vpn ins TU-Netz<br>
haupts&auml;chlich entsprechend der Anleitung: https://tu-dresden.de/zih/dienste/service-katalog/arbeitsumgebung/zugang_datennetz/vpn/ssl_vpn/howto_anyconnect_linux/index<br>
um die GUI von Cisco AnyConnect zu &ouml;ffnen wird das Paket libpangox ben&ouml;tigt. Habe ich &uuml;ber den Paketmanager installieren k&ouml;nnen<br>
Cisco AnyConnect ist die Datei /opt/cisco/anyconnect/bin/vpnui
</p>
<p>
zum Bilder verkleinern in Kommandozeile: <br>
"for i in *.jpg; do convert $i -resize 541x304 $i; done",
Achtung, Bilder werden ersetzt! (wenn nicht gewollt das $i um ein pr&auml;fix erg&auml;nzen); gleiches ggf. mit *.JPG
</p>
<p>
Nach anpassen der Datei lxde-rc.xml mit den Shortcuts, rufe den Befehl "openbox --reconfigure" auf. Dann werden die &Auml;nderungen beachtet.
</p>
<p>
im LXTerminal (LXDE-Standard) gibt es den Befehl alias, mit help alias gibt es alle relevanten Infos, mit alias bekommt man alle aktuellen aliase
<br>
/home/felix/.bashrc: Dies wird beim Start jeder Konsole ausgef&uuml;hrt, kann angepasst werden
<br>
/home/felix/.bash_aliases: Diese Befehle werden von bashrc aufgerufen, dort sollen alle aliases rein, die man jedes Mal haben m&ouml;chte
</p>
<p>
/home/felix/.config/gtk-3.0/bookmarks: Dort stellt man ein, welche Ordner unter Places bzw. Orte in Thunar angezeigt werden.
</p>
<p>
Einstellung um mein Tastaturlayouts beim Einloggen einzustellen:<br>
localectl set-x11-keymap "my_neo2(my_neo2)"<br>
damit ist auch der nicht funktionierende Autostart umgangen<br>
kommt von https://wiki.archlinux.org/index.php/Keyboard_configuration_in_Xorg
<p>
Anleitung f&uuml;r's ver&auml;ndern des Tastaturlayouts<br>
1) Im Ordner /usr/share/X11/xkb/symbols/ die Datei my_neo &ouml;ffnen<br>
2) die entsprechende Taste finden und das zugeh&ouml;rige Level (Achtung, die sind nicht in der NEO-Reihenfolge), dort &auml;ndern, Unicode mit UHexnr, speichern<br>
3) im Ordner /var/lib/xkb/ alle xkm-Dateien l&ouml;schen (das sind die kompilierten Dateien). Daf&uuml;r sind root-Rechte n&ouml;tig, also mit "sudo rm *.xkm"<br>
4) setxkbmap "my_neo(my_neo)" -v<br>
5) Im Ordner SSD-Daten/Startscreen die entsprechenden Ebenen &auml;ndern mit KolourPaint<br>
6) bash buildMyNeo.sh<br>
7) entsprechende Zeichen unter HDD-Daten/Computer/LaTeX/exDocs/neoUTF8enc.tex erg&auml;nzen und die Ver&auml;nderung an andere Stellen, wo die Datei sitzt, kopieren
</p>
<p>
Sachen, in shell Skripten:<br>
in Bedingungsklammern [] von if muss am Anfang und am Ende ein " " (blank) stehen!! <br>
Hinweise zu Bedingungen in if abrufbar unter "man test" <br>
bei Zuweisungen mit = darf zwischen Variablenname und = kein Leerzeichen sein! (sonst wird Variablenname als command interpretiert)
</p>
<p>
SSH-Key Erstellung:<br>
ssh-keygen -t rsa -f BelaSSHKey
(ausgeführt in ~/.ssh, weiss nicht ob das wichtig ist)
<br>
Passphrase das von git-Kram. <br>
Ausgabe:<br>
The key fingerprint is:<br>
4a:ad:de:1b:26:ed:f5:cb:78:01:b1:8c:98:38:1c:3e felix@felix-L450<br>
The key's randomart image is:<br>
+--[ RSA 2048]----+<br>
| |<br>
| . . |<br>
| o o o o o |<br>
| E o.. + |<br>
| o. S . |<br>
| . + . |<br>
| + + . . |<br>
| . = o +. |<br>
| . +...+. |<br>
+-----------------+<br>
Dateien wurden in ~/.ssh erstellt.
</p>
<p>
How to: install Sublime Text<br>
sudo add-apt-repository ppa:webupd8team/sublime-text-3<br>
sudo apt-get update<br>
sudo apt-get install sublime-text-installer<br>
Infos: http://www.webupd8.org/2013/07/sublime-text-3-ubuntu-ppa-now-available.html
</p>
<p>
Shell code um alle Kapitel einer Geschichte von fanfiction.net herunterzuladen (statt 30..35 die passenden Kapitelzahlen und die Adresse anpassen):<br>
for i in {30..108}; do mkdir AA$i; cd AA$i; wget -nd -l 1 https://www.fanfiction.net/s/9863146/$i/The-Accidental-Animagus; sed "16,329 d" The-Accidental-Animagus > ../The-Accidental-Animagus-$i; cd ..; rm -r AA$i; done
<br>
oder in mehreren Zeilen:<br>
<br>
for i in {30..35}<br>
&emsp;do mkdir AA$i<br>
&emsp;cd AA$i<br>
&emsp;wget -nd -l 1 https://www.fanfiction.net/s/9863146/$i/The-Accidental-Animagus<br>
&emsp;sed "16,332 d" The-Accidental-Animagus > ../The-Accidental-Animagus-$i<br>
&emsp;cd ..<br>
&emsp;rm -r AA$i<br>
done
</p>
<p>
Remap of Print key to Menu key (right click):<br>
with xev | grep keycode -> observe that Print key has keycode 107<br>
command xmodmap ~/.xmodmaprc in autostart (~.config/autostart/xmodmap.sh)<br>
in ~/.xmodmaprc: "keycode 107 = Menu"<br>
Alternative (genutzt):<br>
command xmodmap ~/.xmodmaprc in autostart file "/home/felix/.config/lxsession/LXDE/autostart"
</p>
<p>
Installation unseres EPSON WF-7620 Druckers (Druck, noch nicht scan) <br>
Installation von Treibern u.&auml;.: <br>
1) sudo apt-get install lsb <br>
2) Unter <br>
http://www.openprinting.org/printer/Epson/Epson-WF-7620_Series <br>
download: <br>
http://download.ebz.epson.net/dsc/op/stable/debian/dists/lsb3.2/main/binary-amd64/epson-inkjet-printer-escpr_1.4.1-1lsb3.2_amd64.deb<br>
Installiere durch Doppelklick (ggf. vorher gdebi installieren)<br>
3) Zus&auml;tzlich Epsons Kram installieren: unter <br>
download.ebz.epson.net/dsc/search/01/search<br>
- suche nach WF-7620 - Epson Printer Utility - amd64 <br>
download und installieren durch Doppelklick:<br>
epson-printer-utility_1.0.0-1lsb3.2_amd64.deb<br>
4) Dann cups starten:<br>
/etc/init.d/cups restart<br>
check with ps -ef | grep cups<br>
5) cups &uuml;ffnen: localhost:631, durch Men&uuml;s wurschteln, dabei Epson WF-7620 Series ausw&auml;hlen.<br>
6) In Standardeinstellungen w&auml;hle Normalpapier-Standard-Vivid<br>
Wenn nach Benutzername und Passwort gefragt wird, gib dein Benutzername und Passwort ein (geht wegen sudo).
</p>
<p>
Installation des EPSON WF-7620 als Scanners <br>
Anleitung: http://download.ebz.epson.net/man/linux/iscan_e.html#sec6-1-3 <br>
Download: http://support.epson.net/linux/en/iscan_c.php?version=1.0.4 <br>
entpackt, README gelesen, ./install.sh --dry-run -- entsprechend Dinge per Hand getan in anderer Reihenfolge: <br>
sudo apt-get install xsltproc <br>
sudo dpkg --install ./data/iscan-data_1.39.0-1_all.deb <br>
sudo dpkg --install ./core/iscan_2.30.3-1_amd64.deb <br>
sudo dpkg --install ./plugins/iscan-network-nt_1.1.1-1_amd64.deb <br>
Anleitung: https://wiki.ubuntuusers.de/SANE-Scanserver_im_Netzwerk/ <br>
ein Deamon immer beim Rechnerstart starten: <br>
sudo systemctl enable saned.socket <br>
mit simple-scan scannen :)
</p>
<p>
Installation des Scanners:<br>
Install sane-utils (sane organisiert das Scannen, libsane sollte schon installiert sein.)<br>
F&uuml;ge IP-Adresse des Scanners in passende Datei ein:<br>
/etc/sane.d/net.conf<br>
am Ende der Datei einf&uuml;gen:<br>
192.168.178.1<br>
Ich habe ausserdem die time-out Zeit (s. Datei) auf 10 sek gesetzt.<br>
Dann mit SimpleScan scannen. Als ich die Datei gespeichert habe (muss man nach dem Scannen noch tun) schien SimepleScan abgest&uuml;rzt zu sein, aber nach einer Weile war es wieder OK. Vermutlich reagiert das Programm nicht so lange es an der pdf-Erstellung arbeitet.
</p>
<p>
Signal installieren:<br>
Signal App Signal Private Messenger &uuml;ber Chrome Web Store installiert. Beim Einf&uuml;hrungsbildschirmen hat Bene was mit dem QR-Code gemacht. Mein Name ist Bela. <br>
Anleitung f&uuml;r Kommandozeilenprogramm entsprechend
https://github.com/AsamK/signal-cli <br>
git clone https://github.com/AsamK/signal-cli.git <br>
gradle build <br>
gradle installDist <br>
gradle distTar <br>
cd build/distributions <br>
sudo tar xf signal-cli-... -C /opt <br>
sudo ln -sf /opt/signal-cli-"${VERSION}"/bin/signal-cli ~/myconfigs/configs/bin/signal
<br>
registrieren &uuml;ber die Signal Kommmandozeile: <br>
signal-cli -u "+49 meine Telnr." register <br>
signal-cli -u "+49 meine Telnr" verify "die zugesendete Nr" <br>
</p>
<p>
Einstellungen in Simple Scan f&uuml;r Mitschriften-Scans: <br>
Photo, 150 dpi, Brightness Mitte, Contrast maximal, Quality bei 2/3
</p>
<p>
Zum Mappen notes nutzen: Download via api:<br>
S&uuml;dvorstadt:
http://api.openstreetmap.org/api/0.6/notes.gpx?bbox=13.6961424,51.0199804,13.7432142,51.043165
Dann das gpx auf das gps laden und das gpx mit dem Skript /home/felix/Documents/Hobby/OSM_Data/extract.py bearbeiten und das Produkt ausdrucken und mitnehmen.
</p>
<p>
Ripping a CD: (CD to mp3): Nutze abcde mit Anleitung: http://www.andrews-corner.org/linux/abcde/index.html
</p>
</body>
</html>

286
addDateTaken.sh Executable file
View file

@ -0,0 +1,286 @@
#!/bin/sh
#todo: bei jeder Aenderung auch usage (doc) anpassen
#todo: translate entire script into english
# adds date taken in beginning of file name if jpg, .png, (not yet: .mp4, .mov, ...)
# Attention: there is a hard link to this script at the end!!! moving this script meens changing it
# options
# -h --help display help
# -a --noask --no-interactive do not prompt the user to confirm renaming
# -l --onlylog just logs what would have been done but not doing anything
# -o [file] --outputfile [file] specifies the output (log) file (standard is da.log)
# -v [file] --voutputfile [file] specifies the verbose output log file (standard dav.log)
# to be implemented in other sript:
# -i --image adds date taken in beginning of file name if jpg, .png, (not yet: .mp4, .mov, ...)
#Functions
vLog()
{
echo "$1" >> "$VLOGFILE"
}
log()
{
echo "$1" >> "$NVLOGFILE"
echo "$1" >> "$VLOGFILE"
}
rename()
# moves $1 to $2 if rn is 1, otherwise set variable new to $1
# log move on any case
{
log "rn \"$1\" to \"$2\""
if [ $rn -eq 1 ]
then
mv -- "$1" "$2"
else
new="$1"
fi
}
remove()
# deletes $1 if rn is 1, otherwise only logging
{
if test -f "$1"
then
#echo "$1"
log "rm \"$1\""
if test $rn -eq 1
then
trash "$1"
fi
fi
}
usage()
# displays help message and exit
{
echo ""
echo "help page for $0"
echo "---------------------------------"
echo "this script should not be called directly but by the Wrapper script WrapperAddDateTaken.sh"
echo "Usage: bash $0 [OPTIONS] DIR"
echo " $0 adds the date the picture was taken or movie was filmed at the beginning of the file name."
echo ""
echo "options"
echo " -h, --help display this help"
echo " -a, --noask --no-interactive do not prompt the user to confirm renaming (standard is asking for each file)"
echo " -l, --onlylog just logs what would have been done but not doing anything"
echo " -o [file], --outputfile [file] specifies the output (log) file (standard is da.log)"
echo " -v [file], --voutputfile [file] specifies the verbose output log file (standard dav.log)"
echo " -- finishes the list of options, next argument is taken as the dir"
#echo " -i, --image adds date taken in beginning of file name if jpg, .png, (not yet: .mp4, .mov, ...)"
echo ""
echo "error handling"
echo " if DIR is no valid directory, the scripts eith error code 1"
exit
}
folderloc()
# returns the argument as absolute path
# arg1: if arg1 starts with /, return arg1, otherwise return $(pwd)/arg1
{
case "$1" in
/* ) echo "$1"
break
;;
* ) echo "$(pwd)/$1"
break
;;
esac
}
# considering options
# saving all options to give them recursively
ops=""
# standard behavior: ask the user is file is to be renamed
# 0 meens not asking
ask=1
# standard behavior: actually rename
# 0 meens not renaming but just log what would have be done
rn=1
# standard behaviour: rename as usual
# 1 meens adding date taken to image and video files
# image=0
# the log file for verbose logging
#VLOGFILE="$1"
VLOGFILE="$(pwd)"/../rnv.log
# the log file for short logging
#NVLOGFILE="$2"
NVLOGFILE="$(pwd)"/../rn.log
#directory to be checked
dir="$(pwd)" # standard if not specified
# -n = string is non-zero length?
while test -n "$1" ; do
case $1 in
-h | --help ) usage;;
-o | --outputfile ) # ops="$ops -o ../$2"
shift
NVLOGFILE="$(folderloc "$1")"
;;
-v | --voutputfile ) #ops="$ops -v ../$2"
shift
VLOGFILE="$(folderloc "$1")"
;;
-a | --noask | --no-interactive ) ops="$ops -a"
ask=0
;;
-l | --onlylog ) ops="$ops -l"
rn=0
;;
-- ) shift
dir="$(folderloc "$1")"
break
;;
* ) dir="$(folderloc "$1")"
break
;;
esac
shift # must be done in any case: the next argument is $1
done
# echo "options"
# echo "asking=$ask"
# echo "rename=$rn"
# echo "log file=$NVLOGFILE"
# echo "verbose log file=$VLOGFILE"
# echo "direc=$dir"
#for testing purposes:
# exit
addDates()
# adds the picture taken dates to all pictures and descends into subfolders
{
for fil in *
do
if test -d "$fil"
then
cd "$fil"
addDates
cd ..
vLog "went back to $(pwd)"
continue
#vLog "handle dir"
# * als einziger Dateiname kommt auch bei leerem Ordner vor
fi
if test -e "$fil" # file to be moved exists
then
: # ok, do what comes after fi
else
continue
fi
case "$fil" in
201[0-9]_[01][0-9]_[0-3][0-9]*)
vLog "dont rename bc already date there: $fil";;
*.[jJ][pP][gG]|*.[jJ][pP][eE][gG]|*.[pP][nN][gG]) #|*.3gp|*.[aA][vV][iI])
date=$(exiftool -d "%Y_%m_%d_%H%M%S" -CreateDate "$fil" | awk '{print $4}')
# -z length is zero
if test -z "$date"
then
vLog "the file has no creation date: $fil"
else
# remove SAM_Zahl
new="$(echo "$fil" | sed 's/SAM_[0-9]\{4\}//')"
# remove DSC_Zahl (e.g. Hollys camera)
new="$(echo "$new" | sed 's/DSC_[0-9]\{4\}//')"
# remove DSCZaahl
new="$(echo "$new" | sed 's/DSC[0-9]\{5\}//')"
# remove DSCFZahl
new="$(echo "$new" | sed 's/DSCF[0-9]\{4\}//')"
# remove DSCIZahl
new="$(echo "$new" | sed 's/DSCI[0-9]\{4\}//')"
# remove DSCNZahl
new="$(echo "$new" | sed 's/DSCN[0-9]\{4\}//')"
# remove IMGPZahl (e.g. Romy Fischers camera)
new="$(echo "$new" | sed 's/IMGP[0-9]\{4\}//')"
#remove Zah-Zahl_IMG
new="$(echo "$new" | sed 's/[0-9]\{3\}-[0-9]\{4\}_IMG//')"
# remove IMG_Daaatuum_Zeeiit (e.g. my smartphone)
new="$(echo "$new" | sed 's/IMG_20[0-9]\{6\}_[0-9]\{6\}//')"
# remove IMG_Zahl
new="$(echo "$new" | sed 's/IMG_[0-9]\{4\}//')"
# remove PZaaaahl
new="$(echo "$new" | sed 's/P[0-9]\{7\}//')"
# remove PCZaaahl
new="$(echo "$new" | sed 's/P[ABC][0-9]\{6\}//')"
# remove PICTZahl
new="$(echo "$new" | sed 's/PICT[0-9]\{4\}//')"
# remove SDCZaahl
new="$(echo "$new" | sed 's/SDC[0-9]\{5\}//')"
# remove RIMGZahl
new="$(echo "$new" | sed 's/RIMG[0-9]\{4\}//')"
# remove Zaaaaaaaaahl_0Mbelieb--.Z (my smart phone at second bluetooth copy)
new="$(echo "$new" | sed 's/[0-9]\{14\}_0M.\{6\}\--\.[1-9]//')"
# remove 0Mbelieb--.Z (my smart phone)
new="$(echo "$new" | sed 's/0M.\{6\}--\.[1-9]//')"
# remove 0CLxbelb--.Z (my smart phone)
new="$(echo "$new" | sed 's/0CLx.\{6\}--\.[1-9]//')"
# remove FotoZahl
new="$(echo "$new" | sed 's/Foto[0-9]\{4\}//')"
# hochzeitsbilder 180505_Za_Hochzeit (Z)
new="$(echo "$new" | sed 's/180505_[01][0-9]_Hochzeit ([0-9]*)/Hochzeit/')"
case "$new" in
_*|.*) ;; #tue nichts
*)
new="_$new";;
esac
new="$date$new" # date und _ haben keine Leerzeichen
# existiert eine Datei mit dem neuen Namen bereits?
# -e ist exist. die Datei schon?
# different jpeg extensions:
new="$(echo "$new" | sed 's/\.JPG/.jpg/g')"
new="$(echo "$new" | sed 's/\.JPEG/.jpg/g')"
new="$(echo "$new" | sed 's/\.jpeg/.jpg/g')"
if test -e "$new"
then
log "a file with name \"$new\" already exists, -> dont rename: $fil"
else
if test $ask -eq 0
then
rename "$fil" "$new"
else
# Abfrage ob man wirklich umbenennen will
echo "rename $fil to $new? enter, y, yes = yes"
read q
if test -z "$q" -o "$q" = "y" -o "$q" = "yes"
then
rename "$fil" "$new"
fi
fi
fi
fi
;;
*) vLog "dont rename bc no image: $fil"
esac
done
}
#actual script
# check if the argument is correct:
if test ! -d "$dir"
then
log "exiting bc there is no such dir as $dir"
#echo "exiting bc there is no such dir"
exit 1
fi
vLog "move to $dir"
cd "$dir"
addDates
# merke: in Bedingungsklammern [] von if muss am Anfang und am Ende ein " " (blank) stehen!!
# merke: Hinweise zu Bedingungen in if abrufbar unter "man test"
# merke: bei Zuweisungen mit = darf zwischen Variablenname und = kein Leerzweichen sein!
# (sonst wird Variablenname als command interpretiert)

View file

@ -1 +0,0 @@
/home/felix/myconfigs/templates/latex/belamath.sty

8
listLinks.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
# first argument: the directory this works on, with / at the end!
cd $1
echo '' > linkLocations.txt
for li in $(find . -type l)
do
echo $li ' ' $(readlink $li) >> linkLocations.txt
done

View file

@ -1 +0,0 @@
/home/felix/myconfigs/templates/latex/neo2symbols.sty

View file

@ -1 +0,0 @@
/home/felix/myconfigs/scripte/removeBadSymbols.sh

403
removeBadSymbols.sh Executable file
View file

@ -0,0 +1,403 @@
#!/bin/bash
# this is a shebang. It guarantees that this script is executed with bash, not the currently open shell
# problem with shanging to sh: I can't get test to work with * wildcards :(
#todo: also handle hidden files -- actually doable but not a good idea
#todo: bei jeder Aenderung auch usage (doc) anpassen
#todo: translate entire script into english
# options
# -h --help display help
# -a --noask --no-interactive do not prompt the user to confirm renaming
# -l --onlylog just logs what would have been done but not doing anything
# the following two MUST be present # TODO: not making them mandatory
# -o [file] --outputfile [file] specifies the output (log) file (standard is rn.log)
# -v [file] --voutputfile [file] specifies the verbose output log file (standard rnv.log)
# -rm removes files of the form AlbumArt_*, Folder.jpg, Thumbs.db, desktop.ini
# -c converts file names to lower case
#Constants
# weil im folgenden ein Apostroph vorkommt, kann man diesen String nicht einfach einfuegen
STRICHSTR=s/\'//g
# auch hier muss " escaped werden
ANFUERSTR=s/\"//g
# und hier ist es `
ANDSTRSTR=s/\`//g
# und hier ist es &
AMBERSSTR=s/\&/_und_/g
# und hier ist es *
STERNXSTR=s/\*/x/g
#Functions
vLog()
{
echo "$1" >> "$VLOGFILE"
}
log()
{
echo "$1" >> "$NVLOGFILE"
echo "$1" >> "$VLOGFILE"
}
rename()
# moves $1 to $2 if rn is 1,
# not anymore: otherwise set variable new to $1
{
log "rn \"$1\" to \"$2\""
if test $rn -eq 1
then
mv -- "$1" "$2"
# else # not necessary since $new is not used anymore
# new="$1"
fi
}
remove()
# deletes $1 if rn is 1, otherwise only logging
{
if test -f "$1"
then
#echo "$1"
log "rm \"$1\""
if test $rn -eq 1
then
trash "$1"
fi
fi
}
usage()
# displays help message and exit
{
echo ""
echo "help page for $0"
echo "---------------------------------"
echo "this script should not be called directly but by the Wrapper script WrapperRemoveBadSymbols.sh"
echo "Usage: bash $0 [OPTIONS] DIR"
echo " $0 removes a bunch of symbols that should not be in file names in all subdirs and files of DIR:"
echo " (with lyrics) -> remove"
echo " lyrics -> remove"
echo " blank -> _"
echo " ' - ' -> '-'"
echo " ' (Apostroph) -> remove"
echo " '\"'' (Anfuerungsstriche) -> remove"
echo " ´ -> remove"
echo " \& -> _und_"
echo " * -> x"
echo " # -> _"
echo " | -> l (small L since it looks similar)"
echo " ~ -> -"
echo " : -> _"
echo " , -> _"
echo " (){}[] -> remove"
echo " € -> EUR"
echo " $ -> USD"
echo " ä, ö, ü, Ä, Ü, Ö, ß -> ae, ..."
echo " remove various accents (not all, you can add missing ones)"
echo " consecutive _ and - and _ around - -> remove"
echo ""
echo "options"
echo " -h, --help display this help"
echo " -a, --noask --no-interactive do not prompt the user to confirm renaming (standard is asking for each file)"
echo " -l, --onlylog just logs what would have been done but not doing anything"
echo " -o [file], --outputfile [file] specifies the output (log) file (standard is rn.log)"
echo " -v [file], --voutputfile [file] specifies the verbose output log file (standard rnv.log)"
echo " -rm removes files of the form AlbumArt* and Folder.jpg and Thumbs.db"
echo " -c change everything to lowercase (doesn't work for foreign letters if diacritics remain"
echo " -- finishes the list of options, next argument is taken as the dir"
#echo " -i, --image adds date taken in beginning of file name if jpg, .png, (not yet: .mp4, .mov, ...)"
echo ""
echo "error handling"
echo " if DIR is no valid directory, the scripts eith error code 1"
exit
}
folderloc()
# returns the argument as absolute path
# arg1: if arg1 starts with /, return arg1, otherwise return $(pwd)/arg1
{
case "$1" in
/* ) echo "$1"
break
;;
* ) echo "$(pwd)/$1"
break
;;
esac
}
# considering options
# saving all options to give them recursively
ops=""
# standard behavior: ask the user is file is to be renamed
# 0 meens not asking
ask=1
# standard behavior: actually rename
# 0 meens not renaming but just log what would have be done
rn=1
# remove album pictures
# standard behavior: not removing
rmAlbumPics=0
# if file names should be converted to lower case
# standard behavior: no
lowercase=0
# the log file for verbose logging
#VLOGFILE="$1"
VLOGFILE="$(pwd)"/../rnv.log
# the log file for short logging
#NVLOGFILE="$2"
NVLOGFILE="$(pwd)"/../rn.log
#directory to be checked
dir="$(pwd)" # standard if not specified
while [ "$1" != "" ]; do
case $1 in
-h | --help ) usage;;
-o | --outputfile ) # ops="$ops -o ../$2"
shift
NVLOGFILE="$(folderloc "$1")"
;;
-v | --voutputfile ) #ops="$ops -v ../$2"
shift
VLOGFILE="$(folderloc "$1")"
;;
-a | --noask | --no-interactive ) ops="$ops -a"
ask=0
;;
-l | --onlylog ) ops="$ops -l"
rn=0
;;
-rm ) ops="$ops -rm"
rmAlbumPics=1
;;
-c ) lowercase=1
;;
-- ) shift
dir="$(folderloc "$1")"
break
;;
* ) dir="$(folderloc "$1")"
break
;;
esac
shift # must be done in any case: the next argument is $1
done
# echo "options"
# echo "asking=$ask"
# echo "rename=$rn"
# echo "image=$image"
# echo "log file=$NVLOGFILE"
# echo "verbose log file=$VLOGFILE"
# echo "direc=$dir"
#for testing purposes:
# exit
improveNames()
# this function does the work for one folder and goes into subfolders recursively
# assumes it is already in the right place
{
vLog "start with folder: $(pwd)"
printf '.'
# delete unnecessary album pictures and other useless files
if test $rmAlbumPics -eq 1
then
for alb in AlbumArt*.jpg
do
remove "$alb"
done
remove Folder.jpg
remove Thumbs.db
remove desktop.ini
fi
for fil in ./* # ../{.[^.],..?,}*
# that is: .NOTDOTanything &
# ..anything but something &
# something, not starting with dot
# also working on hidden files is not good, e.g. there are .git and many config files
do
# * als einziger Dateiname kommt auch bei leerem Ordner vor
if test -e "$fil" # file to be moved exists
then
:
# do nothing
else
continue # continue with next file
fi
# with lyrics entfernen
new="$(echo "$fil" | sed 's/(with lyrics)//g')"
# lyrics entfernen
new="$(echo "$new" | sed 's/lyrics//g')"
# Leerzeichen entfernen:
new="$(echo "$new" | sed 's/ /_/g')"
# Apostroph entfernen:
new="$(echo "$new" | sed $STRICHSTR)"
# anderes Apostroph entfernen:
new="$(echo "$new" | sed $ANDSTRSTR)"
# Anfuerungstriche entfernen:
new="$(echo "$new" | sed $ANFUERSTR)"
# wieder anderes Apostroph entfernen:
new="$(echo "$new" | sed 's/´//g')"
# Ambersands (&) entfernen:
new="$(echo "$new" | sed $AMBERSSTR)"
# Sternchen (*) entfernen:
new="$(echo "$new" | sed $STERNXSTR)"
# Rauten als Teil von Csharp:
new="$(echo "$new" | sed 's/C#/C_sharp/g')"
new="$(echo "$new" | sed 's/c#/c_sharp/g')"
# Rauten entfernen:
new="$(echo "$new" | sed 's/#/_/g')"
# vertical bars |
new="$(echo "$new" | sed 's/|/l/g')"
# comma, entfernen
new="$(echo "$new" | sed 's/,/_/g')"
# parenthesis
new="$(echo "$new" | sed 's/{//g')"
new="$(echo "$new" | sed 's/}//g')"
new="$(echo "$new" | sed 's/(//g')"
new="$(echo "$new" | sed 's/)//g')"
# [] need escaping since they are part of regexps
new="$(echo "$new" | sed 's/\[//g')"
new="$(echo "$new" | sed 's/\]//g')"
# Tilde ~
new="$(echo "$new" | sed 's/~/-/g')"
# :
new="$(echo "$new" | sed 's/:/_/g')"
# diacritics
# y as sed command says replace one character with the corresponding
# here you might want to add letters when the need arises
while true
do
new2=$new
new="$(echo "$new" | sed 'y/ãāáǎàēéěèȩêīíǐìĩïōóǒòũūúǔùǖǘǚǜşļĻķĶḩģĢḨņŅŗŖĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛ/aaaaaeeeeeeiiiiiioooouuuuuüüüüslLkKhgGHnNrRAAAAEEEEIIIIOOOOUUUUÜÜÜÜ/')"
if test "$new2" = "$new"
then
break
fi
done
# äa
new="$(echo "$new" | sed 's/ä/ae/g')"
# Äa
new="$(echo "$new" | sed 's/Ä/Ae/g')"
# öa
new="$(echo "$new" | sed 's/ö/oe/g')"
# Öa
new="$(echo "$new" | sed 's/Ö/Oe/g')"
# üa
new="$(echo "$new" | sed 's/ü/ue/g')"
# Üa
new="$(echo "$new" | sed 's/Ü/Ue/g')"
# ßs
new="$(echo "$new" | sed 's/ß/ss/g')"
# $
new="$(echo "$new" | sed 's/\$/USD/g')"
# €
new="$(echo "$new" | sed 's/€/EUR/g')"
# different jpeg extensions:
new="$(echo "$new" | sed 's/\.JPG/.jpg/g')"
new="$(echo "$new" | sed 's/\.JPEG/.jpg/g')"
new="$(echo "$new" | sed 's/\.jpeg/.jpg/g')"
if test $lowercase -eq 1 # if should be converted to upper case
then
new="$(echo "$new" | tr '[:upper:]' '[:lower:]')"
fi
#log "before complicated: $fil -> $new"
for i in "_" "\." "-"
do
# remove _ around i
isymbostr="s/_$i/$i/g"
new="$(echo "$new" | sed $isymbostr)"
#log "step 1 $i: $new"
# _ um i entfernen:
isymbostr="s/$i""_/$i/g"
#echo $isymbostr
new="$(echo "$new" | sed $isymbostr)"
#log "step 2 $i: $new; $isymbostr"
# Remove several consecutive
while true
do
isymbostr="s/$i$i/$i/g"
new2="$(echo "$new" | sed $isymbostr)"
if [ $new2 = $new ]
then break
else
new=$new2
fi
done
#log "step 3 $i: $new"
done
if test "$new" = "." -o "$new" = ".."
then
log "dont rename bc would result in $new : $(pwd)/$fil"
elif test "$fil" = "$new"
then
vLog "dont rename bc no change: $fil"
elif [[ "$fil" == ./__*__.py || "$fil" == ./__*__.html || "$fil" == ./__*__.txt ]]
then
vLog "dont rename bc probably special python file: $fil"
elif [[ "$fil" == *.class ]]
then
# sollten unproblematisch sein, beinhalten aber $s
vLog "dont rename bc probably special java class file: $fil"
# existiert eine Datei mit dem neuen Namen bereits?
elif test -e "$new" # bisher: -f (file ex. and is regular file but folders are problematic as well?!)
then
log "a file with name \"$new\" already exists, -> dont rename: $(pwd)/$fil"
elif test $ask -eq 0
then
rename "$fil" "$new"
else
# Abfrage ob man wirklich umbenennen will
echo "rename $fil to $new? enter, y, yes = yes"
read q
if [ "$q" = "" -o "$q" = "y" -o "$q" = "yes" ]
then
rename "$fil" "$new"
fi
fi
done
# renaming done, now iterate over new names
for dir in ./*; do #./{.[^.],..?,}*; do
if test -d "$dir"
then
cd "$dir"
improveNames # arbeite im Unterordner
cd ..
vLog "went back to folder $(pwd)"
fi
done
}
#actual script
# check if the argument is correct:
if [ ! -d "$dir" ]
then
log "exiting bc there is no such dir"
#echo "exiting bc there is no such dir"
exit 1
fi
# vLog "move to $dir"
cd "$dir"
# reset log files
echo "" > "$NVLOGFILE"
echo "" > "$VLOGFILE"
improveNames
# merke: in Bedingungsklammern [] von if muss am Anfang und am Ende ein " " (blank) stehen!!
# merke: Hinweise zu Bedingungen in if abrufbar unter "man test"
# merke: bei Zuweisungen mit = darf zwischen Variablenname und = kein Leerzweichen sein!
# (sonst wird Variablenname als command interpretiert)

109
rmCreated.py Executable file
View file

@ -0,0 +1,109 @@
#!/usr/bin/python3.5
# -*- coding: utf-8 -*-
"""Delete latex created files.
Go through a directory and remove all files that
are created by latex and are not necessary due to the
existing original .tex files.
"""
import os
import os.path
# from os.path import islink, join, basename, abspath, lexists, samefile, isfile
# from os.path import isdir, getsize, splitext, dirname # , exists
# from shutil import move
# from os import walk, sep, symlink, readlink
from argparse import ArgumentParser
# from binaryornot.check import is_binary
createdExtensions = ["aux", "fls", "log", "synctex.gz",
"pgf-plot", "dvi", "bbl", "toc", "run.xml",
"out", "blg", "bcf", "lco", "vrb", "snm",
"nav", "auxlock", "upb", "upa", "glg", "glo",
"gls", "glsdefs", "idx", "ilg", "ind", "ist",
"fdb_latexmk", "pdf"]
# first check for command line arguments
parser = ArgumentParser(description="Remove by latex created files.")
parser.add_argument(
dest='filenames',
metavar='F',
help="the directories to be processed",
nargs='*',
default='.')
parser.add_argument(
'-v', '--verbose',
dest='verbose',
action='store_true',
help="turn on verbose output, " +
"additionally printing all tex files.")
parser.add_argument(
'-l', '--onlylog',
dest='onlylog',
action='store_true',
help=("do not actually move anything but tells what would have been " +
"done ('dry run')."))
parser.add_argument(
'-i', "--ignore",
dest='ignore',
nargs='+',
default=['.git', '.svn'],
help=("""ignore the directories and files (and their subdirectories) """ +
"""given after -i. """ +
"""Since this takes all following arguments as ignored """ +
"""subdirectories,""" +
""" place the processed directories in front of -i.
Default: .git .svn"""))
args = parser.parse_args()
if args.ignore is None:
args.ignore = ['.git', '.svn']
ignore = args.ignore
igndirs = [d for d in args.ignore if os.path.isdir(d)]
ignfiles = [f for f in args.ignore if os.path.isfile(f)]
def possiblyRemove(rootDir, toRemove):
"""Remove root/toRemove if exists.
Attributes:
rootDir: directory where toRemove should lie.
toRemove: filename that is to be removed.
"""
path = os.path.join(rootDir, toRemove)
# if os.path.exists(path):
if args.onlylog:
if os.path.exists(path):
print("removed file:", path)
else:
try:
os.remove(path)
except FileNotFoundError:
# do nothing, not to be removed
pass
else:
print("removed file:", path)
for top in args.filenames:
top = os.path.abspath(top)
for root, dirs, files in os.walk(top, topdown=True):
# print("currdir:", root, dirs)
# remove directories and files that are to be ignored
dirs[:] = [d for d in dirs if
not any(os.path.samefile(os.path.join(root, d), ign)
for ign in igndirs)]
files[:] = [f for f in files if
not any(os.path.samefile(os.path.join(root, f), ign)
for ign in ignfiles)]
for tex in [os.path.splitext(f)[0] for f in files if
f.endswith(".tex") and len(f) > 4]:
if args.verbose:
print("remove associated files to:", tex)
for ext in createdExtensions:
possiblyRemove(root, tex + "." + ext)

17
wavToMp3.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
shopt -s dotglob
for j in {1..10}; do
for i in *; do
new=$(echo "$i" | sed -e s#\(#-#)
new=$(echo "$new" | sed -e s#\)#-#)
new=$(echo "$new" | sed -e s#" "#_#)
new=$(echo "$new" | sed -e s#\'##)
mv "$i" "$new"
done
done
currdir=$(pwd)
for i in *.wav; do
new=$(echo "$i" | sed -e s#wav#mp3#)
vlc -I dummy file://$currdir/$i ":sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}:std{access=file{no-overwrite},mux=mp3,dst=$new}" vlc://quit
done