From 292dc8ccff9db46e21f6ee91c8e2c193cc2484ef Mon Sep 17 00:00:00 2001 From: Oliver Bohlen Date: Wed, 6 Jul 2022 12:24:21 +0200 Subject: [PATCH] first commit --- README.md | 0 gaboshlib.include | 36 +++ gaboshlib/g_all-to-syslog.bashfunc | 22 ++ gaboshlib/g_anonfilesdownload.bashfunc | 52 ++++ gaboshlib/g_audiotagsort.bashfunc | 238 ++++++++++++++++++ gaboshlib/g_checkbasicmounts.bashfunc | 10 + gaboshlib/g_compress_audio.bashfunc | 138 ++++++++++ gaboshlib/g_compress_image.bashfunc | 22 ++ gaboshlib/g_compress_video.bashfunc | 201 +++++++++++++++ gaboshlib/g_createvboxvm.bashfunc | 28 +++ gaboshlib/g_cryptdevice-chpass.bashfunc | 20 ++ gaboshlib/g_cryptdevice.bashfunc | 40 +++ gaboshlib/g_date.bashfunc | 5 + gaboshlib/g_date_print.bashfunc | 6 + gaboshlib/g_echo.bashfunc | 9 + gaboshlib/g_echo_error.bashfunc | 19 ++ gaboshlib/g_echo_error_exit.bashfunc | 8 + gaboshlib/g_echo_ok.bashfunc | 9 + gaboshlib/g_echo_warn.bashfunc | 19 ++ gaboshlib/g_enterend.bashfunc | 7 + gaboshlib/g_find_audio.bashfunc | 12 + gaboshlib/g_find_image.bashfunc | 13 + gaboshlib/g_find_video.bashfunc | 18 ++ gaboshlib/g_gentooupdate.bashfunc | 30 +++ gaboshlib/g_imageaddgps.bashfunc | 26 ++ .../g_imagefiledatetocreatedate.bashfunc | 18 ++ .../g_imagerenameIMG_createdate.bashfunc | 17 ++ .../g_imagesetcreatetimedynminsec.bashfunc | 27 ++ gaboshlib/g_imagesorttonextclouddir.bashfunc | 17 ++ gaboshlib/g_ipsext.bashfunc | 10 + gaboshlib/g_iptor.bashfunc | 5 + gaboshlib/g_lockfile.bashfunc | 33 +++ gaboshlib/g_logger.bashfunc | 5 + gaboshlib/g_newtorip.bashfunc | 13 + gaboshlib/g_nice.bashfunc | 6 + gaboshlib/g_portagesync.bashfunc | 7 + gaboshlib/g_read.bashfunc | 16 ++ gaboshlib/g_select-path.bashfunc | 14 ++ gaboshlib/g_similar.bashfunc | 33 +++ gaboshlib/g_sortAZ09.bashfunc | 31 +++ gaboshlib/g_startvboxvm.bashfunc | 6 + gaboshlib/g_test_mediafile.bashfunc | 11 + gaboshlib/g_valid_ipv4.bashfunc | 17 ++ gaboshlib/g_valid_ipv6.bashfunc | 13 + gaboshlib/g_videorenamecamdateformat.bashfunc | 23 ++ gaboshlib/g_yesno.bashfunc | 13 + 46 files changed, 1323 insertions(+) create mode 100644 README.md create mode 100644 gaboshlib.include create mode 100644 gaboshlib/g_all-to-syslog.bashfunc create mode 100644 gaboshlib/g_anonfilesdownload.bashfunc create mode 100644 gaboshlib/g_audiotagsort.bashfunc create mode 100644 gaboshlib/g_checkbasicmounts.bashfunc create mode 100644 gaboshlib/g_compress_audio.bashfunc create mode 100644 gaboshlib/g_compress_image.bashfunc create mode 100644 gaboshlib/g_compress_video.bashfunc create mode 100644 gaboshlib/g_createvboxvm.bashfunc create mode 100644 gaboshlib/g_cryptdevice-chpass.bashfunc create mode 100644 gaboshlib/g_cryptdevice.bashfunc create mode 100644 gaboshlib/g_date.bashfunc create mode 100644 gaboshlib/g_date_print.bashfunc create mode 100644 gaboshlib/g_echo.bashfunc create mode 100644 gaboshlib/g_echo_error.bashfunc create mode 100644 gaboshlib/g_echo_error_exit.bashfunc create mode 100644 gaboshlib/g_echo_ok.bashfunc create mode 100644 gaboshlib/g_echo_warn.bashfunc create mode 100644 gaboshlib/g_enterend.bashfunc create mode 100644 gaboshlib/g_find_audio.bashfunc create mode 100644 gaboshlib/g_find_image.bashfunc create mode 100644 gaboshlib/g_find_video.bashfunc create mode 100644 gaboshlib/g_gentooupdate.bashfunc create mode 100644 gaboshlib/g_imageaddgps.bashfunc create mode 100644 gaboshlib/g_imagefiledatetocreatedate.bashfunc create mode 100644 gaboshlib/g_imagerenameIMG_createdate.bashfunc create mode 100644 gaboshlib/g_imagesetcreatetimedynminsec.bashfunc create mode 100644 gaboshlib/g_imagesorttonextclouddir.bashfunc create mode 100644 gaboshlib/g_ipsext.bashfunc create mode 100644 gaboshlib/g_iptor.bashfunc create mode 100644 gaboshlib/g_lockfile.bashfunc create mode 100644 gaboshlib/g_logger.bashfunc create mode 100644 gaboshlib/g_newtorip.bashfunc create mode 100644 gaboshlib/g_nice.bashfunc create mode 100644 gaboshlib/g_portagesync.bashfunc create mode 100644 gaboshlib/g_read.bashfunc create mode 100644 gaboshlib/g_select-path.bashfunc create mode 100644 gaboshlib/g_similar.bashfunc create mode 100644 gaboshlib/g_sortAZ09.bashfunc create mode 100644 gaboshlib/g_startvboxvm.bashfunc create mode 100644 gaboshlib/g_test_mediafile.bashfunc create mode 100644 gaboshlib/g_valid_ipv4.bashfunc create mode 100644 gaboshlib/g_valid_ipv6.bashfunc create mode 100644 gaboshlib/g_videorenamecamdateformat.bashfunc create mode 100644 gaboshlib/g_yesno.bashfunc diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/gaboshlib.include b/gaboshlib.include new file mode 100644 index 0000000..e61d32f --- /dev/null +++ b/gaboshlib.include @@ -0,0 +1,36 @@ +#!/bin/bash + +. /etc/profile + +# export all functions +set -a + + +## Include functions +. /etc/bash/gaboshlib/g_*.bashfunc +## + +# if runnign directly from shell +if echo $0 | egrep -q '^-bash$|^-su$' +then + g_scriptname=bash +else + g_scriptname=$(basename $0) +fi + +# TMPDIR +[ -w /tmp ] && g_tmp=/tmp +df -h /tmp | grep -q tmpfs && g_tmp=~/.g_tmp +[ -w /data-crypt/share/tmp ] && g_tmp=/data-crypt/share/tmp +g_tmp="$g_tmp/g_$g_scriptname-$$" +[ -d "$g_tmp" ] || mkdir -p "$g_tmp" + +# START and EXIT Notification +g_trap_exit="g_logger EXITING $g_scriptname ; rm -r $g_tmp" +trap "$g_trap_exit" EXIT +g_syslogtag="g_bash-script:$g_scriptname[$$]" +[ $g_scriptname = "bash" ] || g_logger STARTING $g_scriptname + +# PATH +[ -d /etc/thinclient/scripts ] && PATH=$PATH:/etc/thinclient/scripts + diff --git a/gaboshlib/g_all-to-syslog.bashfunc b/gaboshlib/g_all-to-syslog.bashfunc new file mode 100644 index 0000000..e568573 --- /dev/null +++ b/gaboshlib/g_all-to-syslog.bashfunc @@ -0,0 +1,22 @@ +#!/bin/bash + +function g_all-to-syslog { + [ -z $g_alltosyslog ] || return 0 + g_alltosyslog=1 + g_stdout_pipe=$g_tmp/stdout_pipe + mknod $g_stdout_pipe p + while read line + do + cat <<< $line + cat <<< $line | logger -t "$g_syslogtag:STDOUT" + done <$g_stdout_pipe & + exec 1>$g_stdout_pipe + g_stderr_pipe=$g_tmp/stderr_pipe + mknod $g_stderr_pipe p + while read line + do + cat <<< $line >&2 + cat <<< $line | logger -t "$g_syslogtag:STDERR" + done <$g_stderr_pipe & + exec 2>$g_stderr_pipe +} diff --git a/gaboshlib/g_anonfilesdownload.bashfunc b/gaboshlib/g_anonfilesdownload.bashfunc new file mode 100644 index 0000000..bfb3d50 --- /dev/null +++ b/gaboshlib/g_anonfilesdownload.bashfunc @@ -0,0 +1,52 @@ +#!/bin/bash + +function g_anonfilesdownload { + g_tries=10 + [ -z $1 ] && return 1 + g_anonfileslink=$1 + g_wgetout=$g_tmp/wgetout-$RANDOM + [ -n $2 ] && g_wgetout="$2" + rm -f "$g_wgetout" + unset https_proxy + unset http_proxy + # Get file-Link from Link + [ -f ~/.cache/g_anonfiles-link2file ] && find ~/.cache/g_anonfiles-link2file -cmin +10 -delete + if grep -q "$g_anonfileslink" ~/.cache/g_anonfiles-link2file >/dev/null 2>&1 + then + g_anonfilesfile=$(grep "$g_anonfileslink" ~/.cache/g_anonfiles-link2file | tail -n1 | cut -d'|' -f2) + else + g_anonfilesfile=$(wget -nv --timeout=10 --random-wait --tries=10 -q --proxy localhost:8118 --user-agent="Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" --referer=https://anonfiles.com/ ${g_anonfileslink} -O - | egrep "href.+anonfiles.+rar" | cut -d '"' -f 2) + if [ -z $g_anonfilesfile ] + then + g_echo_error "Fehler beim ermitteln der Anonfiles Datei URL von $g_anonfileslink" + return 1 + fi + echo "$g_anonfileslink|$g_anonfilesfile" >>~/.cache/g_anonfiles-link2file + fi + # Download + g_anonfilesname=$(echo "$g_anonfilesfile" | sed 's/.*\///') + ps ax | grep -v grep | grep -q "$g_anonfilesname" && return 1 + g_echo_ok "Beginne Download von $g_anonfilesfile aus Link $g_anonfileslink - Ausgaben: $g_wgetout" + echo "wget --progress=bar:force:noscroll --timeout=10 --random-wait --tries=1 -c --proxy localhost:8118 --user-agent=\"Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\" --referer=https://anonfiles.com/ \"$g_anonfilesfile\"" + if wget --progress=bar:force:noscroll --timeout=10 --random-wait --tries=1 -c --proxy localhost:8118 --user-agent="Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" --referer=https://anonfiles.com/ "$g_anonfilesfile" > "$g_wgetout" 2>&1 + then + g_echo_ok "Download von $g_anonfilesfile abgeschlossen" + sed -i s,$g_anonfileslink,, *"$dlc.lst" + rm "$g_wgetout" + return 0 + else + if grep -q "The file is already fully retrieved" "$g_wgetout" + then + g_echo_ok "Download von $g_anonfilesfile abgeschlossen" + sed -i s,$g_anonfileslink,, *"$dlc.lst" + rm "$g_wgetout" + return 0 + else + g_echo_warn "Fehler $? beim Download von $g_anonfilesfile" + g_echo_warn "WGET:" $(cat "$g_wgetout") + rm -f ~/.cache/g_anonfiles-link2file + return 1 + fi + fi +} + diff --git a/gaboshlib/g_audiotagsort.bashfunc b/gaboshlib/g_audiotagsort.bashfunc new file mode 100644 index 0000000..b4ec44d --- /dev/null +++ b/gaboshlib/g_audiotagsort.bashfunc @@ -0,0 +1,238 @@ +#!/bin/bash + +function g_audiotagsort { + local g_artist_dirname="artist" + local g_artist_albums_only_dirname="artist-albums_only" + local g_uploaddate_dirname="uploaddate" + local g_genre_dirname="genre" + local g_sampler_dirname="sampler" + local g_year_dirname="year" + local g_album_dirname="album" + local g_uploaddate=$(date "+%Y_%m_%d") + if [ -d "$1" ] + then + g_audiosourcepath="$1" +# g_echo "Audiosource $g_audiosourcepath" + else + g_echo_error echo "No Audiosource defined" + return 1 + fi + mkdir -p "$2" >/dev/null 2>&1 + if [ -d "$2" ] + then + g_sortpath="$2" + else + echo "No sortpath defined" + return 1 + fi + [ -n "$3" ] && g_artist_dirname="$3" + [ -n "$4" ] && g_artist_albums_only_dirname="$4" + [ -n "$5" ] && g_uploaddate_dirname="$5" + [ -n "$6" ] && g_genre_dirname="$6" + [ -n "$7" ] && g_sampler_dirname="$7" + [ -n "$8" ] && g_year_dirname="$8" + + find "$g_audiosourcepath" -iname "*.m4a" -type f | sort | while read g_aud + do + g_echo "Bearbeite $g_aud" + g_test_mediafile "$g_aud" || return 1 + ### Get an clean Tags + cat "$g_tmp"/audinfo | perl -pe ' +# Substitute multiple spaces with one +s/ +/ /g; +# Remove space in line beginning +s/^ /g_/; + +# Unwanted strings in filenames +s/\(/\[/g; +s/\{/\[/g; +s/\/\]/g; +s/^ +//; +s/ +$//; +s/^\./_/; +s/[\"\`]/´/g; +s/\\/_/g; +s/\//_/g; +s/\:/_/g; +s/\*/_/g; +s/\?/_/g; +s/\|/_/g; +s/\$/_/g; +s/\#/_/g; +s/\~/_/g; +s/\&/_/g; +s/^-/_/; +s/\.+$//; +s/^\.+//; +s/_+/_/g; + +# Substitute first " _ " with "=" for variable setting +s/ _ /=\"/; +# " in the end +s/(.+)$/$1\"/; + +# Remove Vars with only one or more _ +s/=\"_+\"//; +' | egrep -a "^g_title=|g_artist=|g_album=|g_date=|g_genre=|g_track=" | perl -pe "s/'/´/g" >$g_tmp/tags + if ! file -b $g_tmp/tags 2>&1 | egrep -q "^UTF-8 Unicode text|Unicode text|UTF-8 text|^ASCII text" + then + file -b $g_tmp/tags + g_echo_error "$g_aud Tags scheinen nicht Unicode (UTF-8) zu sein!" + continue + fi + . $g_tmp/tags + ### Check Tags + if [ -z "$g_title" ] + then + g_echo_error "$g_aud Titel Tag nicht gesetzt" + continue + fi + if [ -z "${g_artist}" ] + then + g_echo_error "$g_aud Artist Tag nicht gesetzt" + continue + else + # Move articles behind + g_artist=$(echo "${g_artist}" | perl -pe " + chomp; + if (/^Die /) { s/^Die //; \$_=\$_ . ', Die' } + if (/^Der /) { s/^Der //; \$_=\$_ . ', Der' } + if (/^Das /) { s/^Das //; \$_=\$_ . ', Das' } + if (/^The /) { s/^The //; \$_=\$_ . ', The' }") + fi + if [ -z "$g_album" ] + then + g_echo_error "$g_aud Album Tag nicht gesetzt" + continue + fi + # Remove all non numerical + g_date=$(echo "$g_date" | perl -pe 's/[^0-9]//g;') + if ! echo "$g_date" | egrep -q "^[12][90][0-9][0-9]$" + then + g_echo_error "$g_aud Year Tag nicht gesetzt oder ungültig" + continue + fi + if [ -z "$g_genre" ] + then + g_echo_error "$g_aud Genre Tag nicht gesetzt" + continue + fi + # Remove all non numerical + g_track=$(echo "$g_track" | perl -pe 's/_.+$//; s/[^0-9]//g;') + if [ -z "$g_track" ] + then + g_echo_error "$g_aud Tracknum Tag nicht gesetzt" + continue + fi + g_track=$(printf '%02d' $g_track) + if ! echo "$g_track" | egrep -q "^[0-9][0-9]$" + then + g_echo_error "$g_aud Tracknum Tag $g_track ungültig" + continue + fi + + ### Sort audio file + # filename + g_audiofilename="${g_track} -- ${g_artist} -- ${g_title}.m4a" + g_alphabeticorderartist=$(echo "${g_artist}" | perl -pe 's/^(.).+$/$1/; chomp; ; $_=uc $_; s/[^[:alnum:]]/_/') + + g_uploaddate_path="${g_sortpath}/${g_uploaddate_dirname}/${g_uploaddate}/${g_artist} -- ${g_album}" + g_album_path="${g_sortpath}/${g_album_dirname}/${g_album}/${g_artist}" + g_artist_path="${g_sortpath}/${g_artist_dirname}/${g_alphabeticorderartist}/${g_artist}/${g_album}" + g_artist_sampler_path="${g_sortpath}/${g_artist_dirname}/${g_alphabeticorderartist}/${g_artist}/SAMPLER -- ${g_album}" + g_genre_path="${g_sortpath}/${g_genre_dirname}/${g_genre}/${g_artist}/${g_album}" + g_year_path="${g_sortpath}/${g_year_dirname}/$g_date/${g_artist}/${g_album}" + + ### Check for already uploaded + if [ -f "${g_artist_path}/${g_audiofilename}" ] || [ -f "${g_artist_sampler_path}/${g_audiofilename}" ] + then + g_echo_warn "Album/Sampler ${g_album}/${g_audiofilename} bereits in Sammlung!" + continue + fi + + # Cover? + g_cover="$(dirname "${g_aud}")"/cover.jpg + + # Uploaddate + mkdir -p "${g_uploaddate_path}" + g_echo "=== 1. Linke nach \"${g_uploaddate_path}/${g_audiofilename}\"" + ln "${g_aud}" "${g_uploaddate_path}/${g_audiofilename}" || continue + [ -f "${g_cover}" ] && ln -f "${g_cover}" "${g_uploaddate_path}/cover.jpg" + + # Album + mkdir -p "${g_album_path}" + ln "${g_aud}" "${g_album_path}/${g_audiofilename}" || continue + [ -f "${g_cover}" ] && ln -f "${g_cover}" "${g_album_path}/cover.jpg" + + # Artist + mkdir -p "${g_artist_path}" + g_echo "=== 2. Linke nach \"${g_artist_path}/${g_audiofilename}\"" + ln "${g_aud}" "${g_artist_path}/${g_audiofilename}" || continue + [ -f "${g_cover}" ] && ln -f "${g_cover}" "${g_artist_path}/cover.jpg" + + # Genre + mkdir -p "${g_genre_path}" + g_echo "=== 3. Linke nach \"${g_genre_path}/${g_audiofilename}\"" + ln "${g_aud}" "${g_genre_path}/${g_audiofilename}" || continue + [ -f "${g_cover}" ] && ln -f "${g_cover}" "${g_genre_path}/cover.jpg" + + # Year + mkdir -p "${g_year_path}" + g_echo "=== 4. Linke nach \"${g_year_path}/${g_audiofilename}\"" + ln "${g_aud}" "${g_year_path}/${g_audiofilename}" || continue + [ -f "${g_cover}" ] && ln -f "${g_cover}" "${g_year_path}/cover.jpg" + + # Remove original after linking + g_echo "Lösche Original ${g_aud}" + rm "${g_aud}" + done + # find, rename and move sampler + if [ -d "${g_sortpath}/${g_album_dirname}" ] + then + ls -1 "${g_sortpath}/${g_album_dirname}" | egrep -iav "^Live$|^Demo$|^Best of$|^The Best of$"| while read g_albumartist + do + if [ $(ls -1 "${g_sortpath}/${g_album_dirname}/${g_albumartist}" | wc -l) -ge 4 ] + then + mkdir -p "${g_sortpath}/${g_sampler_dirname}" + cp -rl "${g_sortpath}/${g_album_dirname}/${g_albumartist}" "${g_sortpath}/${g_sampler_dirname}/" + [ -f "${g_cover}" ] && ln -f "${g_cover}" "${g_sortpath}/${g_sampler_dirname}/cover.jpg" + find "${g_sortpath}/${g_sampler_dirname}" -type f ! -links 5 | sort | while read sampleraudio + do + g_echo "=== 5. Linke Sampler \"$sampleraudio\"" + samplerfileinode=$(ls -i "$sampleraudio" | cut -d" " -f1) + find "${g_sortpath}/${g_uploaddate_dirname}" "${g_sortpath}/${g_artist_dirname}" "${g_sortpath}/${g_genre_dirname}" "${g_sortpath}/${g_year_dirname}" -inum ${samplerfileinode} | egrep -v "\/SAMPLER -- "| sort | while read renamesamplerfile + do + samplerdir="$(dirname "$renamesamplerfile")" + newsamplerdir=$(dirname "$renamesamplerfile" | perl -pe '$_=reverse $_; s/\// -- RELPMAS\//; $_=reverse $_') + # Sampler bei Uploaddatum, Erscheinungsjahr und Genre nicht in Interpretenunterverzeichnisse + echo "$newsamplerdir" | grep -q "${g_sortpath}/${g_uploaddate_dirname}" && newsamplerdir=$(echo "$newsamplerdir" | perl -pe 's/(\/SAMPLER -- ).+ -- (.+$)/$1$2/') + echo "$newsamplerdir" | grep -q "${g_sortpath}/${g_year_dirname}" && newsamplerdir=$(echo "$newsamplerdir" | perl -pe 's/\/[^\/.]+\/SAMPLER -- /\/SAMPLER -- /') + echo "$newsamplerdir" | grep -q "${g_sortpath}/${g_genre_dirname}" && newsamplerdir=$(echo "$newsamplerdir" | perl -pe 's/\/[^\/.]+\/SAMPLER -- /\/SAMPLER -- /') + mkdir -p "$newsamplerdir" + mv "$samplerdir"/* "$newsamplerdir"/ + find "$samplerdir/../.." -type d -empty -delete >/dev/null 2>&1 + done + done + fi + done + fi + [ -d "${g_sortpath}/${g_album_dirname}" ] && rm -r "${g_sortpath}/${g_album_dirname}" + # Create Artist-Albums-only (without Sampler) + mkdir -p "${g_sortpath}/$g_artist_albums_only_dirname" + find "${g_sortpath}/$g_artist_dirname" -type f ! -links 5 | grep -v "SAMPLER -- " | sort | while read g_artist_albums_only_file_source + do + g_artist_albums_only_file_dest=$(echo "$g_artist_albums_only_file_source" | perl -pe "s/\/$g_artist_dirname\//\/$g_artist_albums_only_dirname\//") + mkdir -p "$(dirname "$g_artist_albums_only_file_dest")" + g_echo "=== 5. Linke Album \"$g_artist_albums_only_file_dest\"" + g_cover="$(dirname "$g_artist_albums_only_file_source")/cover.jpg" + ln "$g_artist_albums_only_file_source" "$g_artist_albums_only_file_dest" + [ -f "${g_cover}" ] && ln -f "${g_cover}" "$(dirname "$g_artist_albums_only_file_dest")/cover.jpg" + done + # Cleanup + [ -f "${g_cover}" ] && rm "${g_cover}" + find "$g_audiosourcepath"/ -name cover.jpg -type f -delete + find "$g_audiosourcepath"/ -mindepth 1 -type d -empty -delete +} diff --git a/gaboshlib/g_checkbasicmounts.bashfunc b/gaboshlib/g_checkbasicmounts.bashfunc new file mode 100644 index 0000000..d991cc1 --- /dev/null +++ b/gaboshlib/g_checkbasicmounts.bashfunc @@ -0,0 +1,10 @@ +#!/bin/bash + +function g_checkbasicmounts { + rm -f /usr/portage/distfiles/.mirror-cache.json + mount | grep -q /proc || mount -t proc proc /proc + mount | grep -q /sys || mount -t sysfs sys /sys + mount | grep -q /dev/shm || mount -t tmpfs -o size=20G shm /dev/shm + mount | grep -q /dev/pts || mount -t devpts -o gid=5 devpts /dev/pts + chmod 666 /dev/urandom +} diff --git a/gaboshlib/g_compress_audio.bashfunc b/gaboshlib/g_compress_audio.bashfunc new file mode 100644 index 0000000..9d8dc79 --- /dev/null +++ b/gaboshlib/g_compress_audio.bashfunc @@ -0,0 +1,138 @@ +#!/bin/bash + +function g_compress_audio { + # Datei OK und noch da? + local g_aud=$@ + g_test_mediafile "$g_aud" || return 1 + # File already converted + if egrep -q "HE-AAC.+32 kb" "$g_tmp"/audinfo + then + g_echo "Audio $g_aud bereits bearbeitet - Bearbeite nur Metadata/Tags" + g_audiosettings="-c:a copy" + else + # Audio Mono/Stereo Codec? + if cat "$g_tmp"/audinfo | egrep -q "Stream.+mono" + then + g_echo "Bearbeite Mono Audiodatei $g_aud" + #g_audiosettings="-af loudnorm=I=-16:LRA=11 -ar 44100 -c:a libfdk_aac -profile:a aac_he -b:a 32k" + g_audiosettings="-ar 44100 -c:a libfdk_aac -profile:a aac_he -b:a 64k" + else + g_echo "Bearbeite Audiodatei $g_aud" + #g_audiosettings="-af loudnorm=I=-16:LRA=11 -ar 44100 -ac 2 -c:a libfdk_aac -profile:a aac_he_v2 -b:a 32k" + g_audiosettings="-ar 44100 -ac 2 -c:a libfdk_aac -profile:a aac_he_v2 -b:a 64k" + fi + fi + # Tags/Metadata + # Convert to UTF if ISO + file -b "$g_tmp"/audinfo | grep -q "ISO-8859 text" && iconv -f ISO-8859-15 -t UTF-8 "$g_tmp"/audinfo -o "$g_tmp"/audinfo + # Tag substitutions + cat < ${g_tmp}/perlsubstitutions +## Prepare ffmpeg output +# Ignore Picture/Video/Cover metadata +\$ign='1' if (/Stream .+ Video/); +\$_='' if (\$ign); +# Substitute multiple spaces with one +s/ +/ /g; +# Remove space in line beginning +s/^ //; +# Substitute " : " with "='" for variable setting +s/ : /=/; +s/^(title|album|artist|track|date|genre)= +/\$1=/; +# Case insensitive Tags +s/^title/title/i; +s/^artist/artist/i; +s/^date/date/i; +s/^album/album/i; +s/^genre/genre/i; +s/^track/track/i; + +# Ignore everything but the 6 tags +\$_='' unless (/^(title|album|artist|track|date|genre)=/); +unless (/^\$/) { + ## Work on TAGs + # Remove unwanted stings + s/’/´/g; + s/'/\´/g; + s/\`/\´/g; + s/ +$//; + s/\'/\´/g; + # cyrillic2latin + if (/^(title|album|artist)=/) { + chomp; + \$before_equal=\$_; + \$before_equal=~s/^(title|album|artist)=.+/\$1/; + \$tag=\$_; + \$tag=~s/ - \(.+$//g; + \$tag=~s/^(title|album|artist)=//; + \$_=\$tag; + s/а/a/g; s/А/A/g; s/б/b/g; s/Б/B/g; s/в/w/g; s/В/W/g; s/г/g/g; s/Г/G/g; s/д/d/g; s/Д/D/g; s/ье/je/g; s/ъе/je/g; s/\sе/je/g; s/\sЕ/Je/g; s/е/e/g; s/Е/E/g; s/шё/scho/g; s/жё/sho/g; s/чё/tscho/g; s/щё/schtscho/g; s/ё/jo/g; s/Ё/Jo/g; s/ж/sh/g; s/Ж/Sh/g; s/з/s/g; s/З/S/g; s/ьи/ji/g; s/ьий/ji/g; s/ий/i/g; s/ый/y/g; s/Й/I/g; s/и/i/g; s/И/I/g; s/й/j/g; s/Й/J/g; s/кс/x/g; s/к/k/g; s/К/K/g; s/л/l/g; s/Л/L/g; s/м/m/g; s/М/M/g; s/н/n/g; s/Н/N/g; s/ьо/jo/g; s/ь/´/g; s/о/o/g; s/О/O/g; s/п/p/g; s/П/P/g; s/р/r/g; s/Р/R/g; s/с/s/g; s/С/S/g; s/т/t/g; s/Т/T/g; s/у/u/g; s/У/U/g; s/ф/f/g; s/Ф/F/g; s/х/ch/g; s/Х/Ch/g; s/ц/z/g; s/Ц/Z/g; s/ч/tsch/g; s/Ч/Tsch/g; s/ш/sch/g; s/Ш/Sch/g; s/щ/schtsch/g; s/Щ/Schtsch/g; s/ы/y/g; s/Ы/Y/g; s/э/e/; s/Э/e/; s/ю/ju/g; s/Ю/Ju/g; s/я/ja/g; s/Я/Ja/g; s/ў/w/g; s/Ў/W/g; + \$newtag=\$_; + if (\$tag eq \$newtag) { + \$_="\$before_equal=\$tag\n"; + } + else { + \$_="\$before_equal=\$tag - (\$newtag)\n"; + } + } + # date/year + s/^date.+([1-2][890][0-9][0-9]).+\$/date=\$1/ if (/^date=/); + # track no 0 in the beginning + s/=0+/=/ if (/^track=/); + # Add ' in line end - variable string end and after = + s/^(title|album|artist|track|date|genre)=/\$1='/; + s/(.+)$/\$1\'/; + + ## Prepare commandline for ffmpeg + s/^/-metadata /; + s/\n/ /; +} +EOF +# Script for getting ID3-Tags in the right codepage - ffmpeg doesn't convert some codepages +#echo '#!/usr/bin/perl +#use MP3::Tag; +#$filename = $ARGV[0]; +#$mp3 = MP3::Tag->new($filename); +#$mp3->get_tags(); +#if (exists $mp3->{ID3v2}) { +# $frames = $mp3->{ID3v2}->get_frame_ids(); +# foreach $frame (keys %$frames) { +# ($value, $desc) = $mp3->{ID3v2}->get_frame($frame); +# $frame="date" if ( $frame eq "TDRL" ); +# $frame="date" if ( $frame eq "TYER" ); +# $frame="title" if ( $frame eq "TIT2" ); +# $frame="genre" if ( $frame eq "TCON" ); +# $frame="album" if ( $frame eq "TALB" ); +# $frame="track" if ( $frame eq "TRCK" ); +# $frame="artist" if ( $frame eq "TPE1" ); +# print "$frame : $value\n"; +# } +#} +#$mp3->close(); +#' >"$g_tmp"/id3tags.pl +# perl "$g_tmp"/id3tags.pl "$g_aud" >"$g_tmp"/id3tags 2>/dev/null +# if [ -s "$g_tmp"/id3tags ] +# then +# file -b "$g_tmp"/id3tags | grep -q "ISO-8859 text" && iconv -f ISO-8859-15 -t UTF-8 "$g_tmp"/id3tags -o "$g_tmp"/id3tags +# g_metadata=$(cat "$g_tmp"/id3tags | perl -pe "do \"${g_tmp}/perlsubstitutions\";") +# else + g_metadata=$(cat "$g_tmp"/audinfo | perl -pe "do \"${g_tmp}/perlsubstitutions\";") +# fi + # Convert! + echo "ffmpeg -loglevel warning -threads 1 -i \"$g_aud\" -map_metadata -1 $g_audiosettings $g_metadata -map a:0 -y \"$g_tmp/m4a.m4a\" < /dev/null 2>&1" >"$g_tmp"/cmd + sh "$g_tmp"/cmd + if ffmpeg -i "$g_tmp/m4a.m4a" 2>&1 | egrep -q "Invalid data found when processing input|No such file or directory|Invalid argument|moov atom not found" + then + g_echo "Bearbeitung von $g_aud fehlgeschlagen" + rm -f "$g_tmp/m4a.m4a" + ffmpeg -i "$g_tmp/m4a.m4a" + return 1 + fi + local g_timestamp=$(ls --time-style='+%Y%m%d%H%M' -l "$g_aud" | cut -d" " -f6) + # For update-copy or rsync one second newer file + #g_timestamp=$((g_timestamp+1)) + cat "$g_tmp/m4a.m4a" >"$g_aud" + rm -f "$g_tmp/m4a.m4a" + touch -t $g_timestamp "$g_aud" + g_naud=$(echo "$g_aud" | perl -pe 's/\.....$/.m4a/; s/\....$/.m4a/;') + [ "$g_aud" != "$g_naud" ] && mv -v "$g_aud" "$g_naud" +} diff --git a/gaboshlib/g_compress_image.bashfunc b/gaboshlib/g_compress_image.bashfunc new file mode 100644 index 0000000..e23cf2b --- /dev/null +++ b/gaboshlib/g_compress_image.bashfunc @@ -0,0 +1,22 @@ +#!/bin/bash + +function g_compress_image { + local g_img=$@ + if exiftool "$g_img" | egrep -q "^Comment.+processed by g_compress_image" + then + g_echo "Bild $g_img bereits bearbeitet" + else + g_echo "Bearbeite Bild $g_img" + if convert -quality 85% -resize 1920\>x1920\> -normalize -set comment "processed by g_compress_image" "$g_img" "$g_tmp"/imgdone.jpg + then + local g_timestamp=$(ls --time-style='+%Y%m%d%H%M' -l "$g_img" | cut -d" " -f6) + # For update-copy or rsync one second newer file + #g_timestamp=$((g_timestamp+1)) + cat "$g_tmp"/imgdone.jpg >"$g_img" + touch -t $g_timestamp "$g_img" + else + g_echo_warn "Bearbeitung von $g_img fehlgeschlagen" + fi + fi +} + diff --git a/gaboshlib/g_compress_video.bashfunc b/gaboshlib/g_compress_video.bashfunc new file mode 100644 index 0000000..e6fd94b --- /dev/null +++ b/gaboshlib/g_compress_video.bashfunc @@ -0,0 +1,201 @@ +#!/bin/bash + +function g_compress_video { + local g_vid=$1 + local g_remotedockerffmpeg=$2 + + # Datei OK und noch da? + ffmpeg -i "$g_vid" 2>&1 | perl -pe 's/\[0x...\]//g' >"$g_tmp"/vidinfo + if egrep -q "Invalid data found when processing input|No such file or directory" "$g_tmp"/vidinfo + then + g_echo_warn "Video $g_vid existiert nicht (mehr) oder ist defekt." + return 1 + fi + + + # Bereits bearbeitet? + local g_lines=`cat "$g_tmp"/vidinfo | egrep -v "WARNING: | configuration: |Side data\:|audio service type\: main|Video\:.+hevc.+1280x|Video\:.+hevc.+960x|Video\:.+hevc.+[1-8][0-9][0-9]x|Audio\:.+HE-AAC\).+mono|Audio\:.+HE-AAC.+stereo|Audio\:.+ac3.+5\.1.side.|Input .+mp4.+from|vendor_id" | wc -l` + # Max DVD Quali + [ -e "$g_tmp"/VID-SD ] && g_lines=`cat "$g_tmp"/vidinfo | egrep -v "Side data\:|audio service type\: main|Video\:.+hevc.+[1-8][0-9][0-9]x|Audio\:.+HE-AAC\).+mono|Audio\:.+HE-AAC.+stereo|Audio\:.+ac3.+5\.1.side.|Input .+mp4.+from|vendor_id" | wc -l` + if [ $g_lines -eq '22' ] + then + g_echo "Video $g_vid bereits bearbeitet!" + return 1 + fi + + local g_wait=$(($RANDOM % 60)) + + until ps ax | grep -q md5sum + do + g_echo "md5sum already running - Waiting 2 seconds" + sleep 2 + done + g_echo "Please wait... Creating checksum for $g_vid." + g_vid_md5=$(md5sum "$g_vid" | cut -d" " -f1) + if [ -e /tmp/"$g_vid_md5".g_progressing ] + then + g_echo "File $g_vid seems already be compressing" + return 1 + fi + echo $$ > /tmp/"$g_vid_md5".g_progressing + + + # TMPfile + local g_rnd=`shuf -i 10000-65000 -n 1` + local g_vidbasename=`basename "$g_vid"` + local g_viddone="$g_tmp/$g_vidbasename-$g_rnd-DONE.mp4" + # 5.1/6.1/7.1 Tonspuren nach vorn setzen + + cat "$g_tmp"/vidinfo | egrep "5\.1|6\.1|7\.1" >"$g_tmp"/vidinfo51 + cat "$g_tmp"/vidinfo >>"$g_tmp"/vidinfo51 + cat "$g_tmp"/vidinfo51 >"$g_tmp"/vidinfo + + # Videostream wählen + g_echo "Bearbeite Video $g_vid" + local g_vidstream=`cat "$g_tmp"/vidinfo | grep Stream | grep ": Video: " | perl -pe 's/\#/:/g; s/\(/:/g;' | cut -d: -f 2,3 | head -n1` + g_echo "Videostream ist $g_vidstream" + + # Audiostream wählen + if cat "$g_tmp"/vidinfo | grep Stream | grep ": Audio: " | egrep -q '(ger)|(deu)' + then + local g_audstream=`cat "$g_tmp"/vidinfo | grep Stream | grep ": Audio: " | egrep '(ger)|(deu)' | perl -pe 's/\#/:/g; s/\(/:/g;' | cut -d: -f 2,3 | head -n1` + else + local g_audstream=`cat "$g_tmp"/vidinfo | grep Stream | grep ": Audio: " | perl -pe 's/\#/:/g; s/\(/:/g;' | cut -d: -f 2,3 | head -n1` + fi + if [ -z "$g_audstream" ] + then + g_echo "File $g_vid seems to have no Audio-Stream" + rm /tmp/"$g_vid_md5".g_progressing + return 1 + fi + g_echo "Audiostream ist $g_audstream" + + + # Untertitel + if cat "$g_tmp"/vidinfo | grep Stream | grep ": Subtitle: " | grep -i 'forced' | egrep -q '(ger)|(deu)' + then + local g_substream=`cat "$g_tmp"/vidinfo | grep Stream | grep ": Subtitle: " | grep -i 'forced' | egrep '(ger)|(deu)' | perl -pe 's/\#/:/g; s/\(/:/g;' | cut -d: -f 3 | head -n1` + g_echo "Extrahiere forced Subtitle 0:$g_substream" + cd "$g_tmp" + mkvextract tracks "$g_vid" $g_substream:vidinfo-$g_rnd-sub + if ls "$g_tmp/vidinfo-$g_rnd-sub"* 2>&1 | egrep -q "idx$" + then + export TESSDATA_PREFIX=/usr/local/vobsub2srttessdata + LD_LIBRARY_PATH=/usr/local/vobsub2srtlibs vobsub2srt --blacklist "|" "$g_tmp/vidinfo-$g_rnd-sub" + else + mv "$g_tmp/vidinfo-$g_rnd-sub" "$g_tmp/vidinfo-$g_rnd-sub.srt" + fi + ffmpeg -loglevel error -i "$g_tmp/vidinfo-$g_rnd-sub.srt" -y "$g_viddone.ass" < /dev/null 2>/dev/null 2>&1 + else + local g_viddir=`dirname "$g_vid"` + local g_vidfile=`basename "$g_vid"` + local g_subfile=`echo "$g_vidfile" | perl -pe 's/....$/-forced/'` + if find "$g_viddir" -name "$g_subfile.idx" | grep -q "$g_subfile.idx" + then + g_echo "sub/idx Untertitel gefunden - Konvertiere nach srt -> ass ($g_subfile)" + rm -f `find \"$g_viddir\" -name \"$g_subfile.srt\"` + export TESSDATA_PREFIX=/usr/local/vobsub2srttessdata + LD_LIBRARY_PATH=/usr/local/vobsub2srtlibs vobsub2srt --blacklist "|" "`find \"$g_viddir\" -name \"$g_subfile.idx\" | perl -pe 's/.idx$//'`" + fi + if find "$g_viddir" -name "$g_subfile.srt" | grep -q "$g_subfile.srt" + then + g_echo "srt Untertitel gefunden - Konvertiere nach ass ($g_subfile)" + ffmpeg -loglevel error -i "`find \"$g_viddir\" -name \"$g_subfile.srt\"`" -y "$g_viddone.ass" < /dev/null 2>/dev/null 2>&1 + fi + fi + + # Video Auflösung und Bitrate neu definieren + local g_vidwidth=`cat "$g_tmp"/vidinfo | egrep "Stream.+Video" | perl -pe 's/ /\n/g;' | egrep "[0-9]x[0-9]" | cut -d"x" -f 1 | perl -pe 's/[^0-9]//g'` + local g_vidmaxrate=$(mediainfo -f "$g_vid" | egrep "^Overall bit rate +: .+kb/s" | head -n1 | perl -pe 's/ +//g;' | cut -d: -f2 | cut -d"k" -f1) + if [ -z $g_vidwidth ] + then + g_echo_warn "Konnte Auflösung von Video $g_vid nicht ermitteln." + return 1 + fi + if [ -z $g_vidmaxrate ] + then + g_echo "Konnte maxinale Bitrate von Video $g_vid nicht ermitteln. - Gehe von 3600 kb/s aus" + g_vidmaxrate=3600 + fi + g_echo "Bitrate des Originals $g_vidmaxrate kb/s" + local g_vidwidthnew=$g_vidwidth + # VCD + [ "$g_vidwidth" -lt "420" ] && g_vidmaxratenew="900" + # SVCD + [ "$g_vidwidth" -ge "420" ] && g_vidmaxratenew="1200" + # DVD + [ "$g_vidwidth" -ge "640" ] && g_vidmaxratenew="1800" + if [ -e "$g_tmp"/VID-SD ] + then + [ "$g_vidwidth" -ge "700" ] && g_vidwidthnew=720 + else + # HD720p Anamorphic + [ "$g_vidwidth" -ge "911" ] && g_vidwidthnew=960 + [ "$g_vidwidth" -ge "911" ] && g_vidmaxratenew="2700" + # HD720p + [ "$g_vidwidth" -gt "1250" ] && g_vidwidthnew=1280 + [ "$g_vidwidth" -gt "1250" ] && g_vidmaxratenew="3600" + fi + # Bei 4:3-Videos nicht mehr als 960xX@2700k um Platz zu sparen + if egrep -q "Video.+4:3" "$g_tmp"/vidinfo + then + if [ "$g_vidwidthnew" -gt "960" ] + then + g_vidwidthnew=960 + g_vidmaxratenew="2700" + fi + fi + + # Falls Originalbitrate niedriger ist Bitrate entsprechend anpassen + [ $g_vidmaxrate -lt $g_vidmaxratenew ] && g_vidmaxratenew=$g_vidmaxrate + + # Seitenverhältnis 1:1 + local g_vidscale="scale=$g_vidwidthnew:-2" + + # Audioqualität generell für 5.1 oder andere Formate + local g_audionew="-c:a ac3 -b:a 384k" + #g_audionew="-c:a libfdk_aac -profile:a aac_he -b:a 144k" # <-- Leider schlechte Qualität bei den hinteren Kanälen auf Raspberry + # bei unter 5.1 zu Stereo + cat $g_tmp/vidinfo | grep "Stream #$g_audstream" | egrep -q 'stereo|3\.1|4\.0|5\.0' && g_audionew="-ac 2 -c:a libfdk_aac -profile:a aac_he_v2 -b:a 48k" + # bei Mono + cat $g_tmp/vidinfo | grep "Stream #$g_audstream" | egrep -q "mono" && g_audionew="-ac 1 -c:a libfdk_aac -profile:a aac_he -b:a 24k" + + local g_ass="" + # ASS Untertitel-Dateien + if [ -f "${g_viddone}.ass" ] + then + # Untertitel einbrennen + g_ass="ass=${g_viddone}.ass," + fi + + if [ -z ${g_remotedockerffmpeg} ] + then + g_echo "Baue MP4 ($g_vid)" + # -hwaccel auto + echo "ffmpeg -loglevel warning -stats -i \"$g_vid\" -f mp4 -map_metadata -1 -map_chapters -1 -map $g_vidstream -map $g_audstream -filter:v \"${g_ass}${g_vidscale}\" -c:v libx265 -crf 25 -x265-params \"vbv-maxrate=${g_vidmaxratenew}:vbv-bufsize=${g_vidmaxratenew}:log-level=warning\" -pix_fmt yuv420p -max_muxing_queue_size 9999 $g_audionew -threads 1 -movflags +faststart \"$g_viddone\" < /dev/null 2>&1" >"$g_tmp"/cmd + else + g_echo "Baue MP4 ($g_vid) auf ${g_remotedockerffmpeg}" + echo "cat \"$g_vid\" | ssh -p33 ${g_remotedockerffmpeg} 'cat | docker run -i --rm linuxserver/ffmpeg -loglevel warning -stats -i pipe: -f mp4 -map_metadata -1 -map_chapters -1 -map $g_vidstream -map $g_audstream -filter:v \"${g_ass}${g_vidscale}\" -c:v libx265 -crf 25 -x265-params \"vbv-maxrate=${g_vidmaxratenew}:vbv-bufsize=${g_vidmaxratenew}:log-level=warning\" -pix_fmt yuv420p -max_muxing_queue_size 9999 $g_audionew -threads 1 -movflags +faststart+empty_moov -f mp4 pipe:' >\"${g_viddone}-stream\"" >"$g_tmp"/cmd + echo "ffmpeg -loglevel warning -stats -i \"${g_viddone}-stream\" -c:v copy -c:a copy -movflags +faststart \"$g_viddone\" < /dev/null 2>&1" >>"$g_tmp"/cmd + fi + g_echo $(cat "$g_tmp"/cmd) + sh "$g_tmp"/cmd + # Wiederholen falls schief gelaufen + local g_try=2 + while ffmpeg -i "$g_viddone" 2>&1 | egrep -q "moov atom not found|No such file or directory" + do + g_echo_warn "Fehler in ffmpeg $g_vid" + sleep $g_wait + cat $g_tmp/cmd + sh $g_tmp/cmd + g_try=$((g_try+1)) + [ "$g_try" -gt "3" ] && return 1 + done + local g_timestamp=$(ls --time-style='+%Y%m%d%H%M' -l "$g_vid" | cut -d" " -f6) + # For update-copy or rsync one second newer file + g_timestamp=$((g_timestamp+1)) + cat "$g_viddone" >"$g_vid" + touch -t $g_timestamp "$g_vid" + rm "$g_viddone" + rm /tmp/"$g_vid_md5".g_progressing +} diff --git a/gaboshlib/g_createvboxvm.bashfunc b/gaboshlib/g_createvboxvm.bashfunc new file mode 100644 index 0000000..d99f302 --- /dev/null +++ b/gaboshlib/g_createvboxvm.bashfunc @@ -0,0 +1,28 @@ +#!/bin/bash + +function g_createvboxvm { + set -x + local g_vboxvm=$1 + local g_vboxvmtype=$2 + local g_vboxvmmem=$3 + [ -z "$g_vboxvm" ] && g_echo_error_exit "No VM Name specified" + # Defaults if not specified + g_vboxvmtype=${2:-Linux_64} + g_vboxvmmem=${3:-1024} + # Create VM + echo "$g_vboxvm" + VBoxManage createvm --name "$g_vboxvm" --register --basefolder "${g_vboxvm}" --ostype "$g_vboxvmtype" + # Set memory and network + VBoxManage modifyvm "$g_vboxvm" --ioapic on + VBoxManage modifyvm "$g_vboxvm" --memory "$g_vboxvmmem" --vram 128 + VBoxManage modifyvm "$g_vboxvm" --nic1 nat + VBoxManage modifyvm "$g_vboxvm" --natdnsproxy1 on + # Create Disk and connect + [ -e "${g_vboxvm}/${g_vboxvm}_DISK.vdi" ] || VBoxManage createhd --filename "${g_vboxvm}/${g_vboxvm}_DISK.vdi" --size 80000 --format VDI + VBoxManage internalcommands sethduuid "${g_vboxvm}/${g_vboxvm}_DISK.vdi" + VBoxManage storagectl "$g_vboxvm" --name "SATA Controller" --add sata --controller IntelAhci + VBoxManage storageattach "$g_vboxvm" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$g_vboxvm/${g_vboxvm}_DISK.vdi" + # Boot + VBoxManage modifyvm "$g_vboxvm" --boot1 disk --boot2 net --boot3 none --boot4 none +} + diff --git a/gaboshlib/g_cryptdevice-chpass.bashfunc b/gaboshlib/g_cryptdevice-chpass.bashfunc new file mode 100644 index 0000000..dc07837 --- /dev/null +++ b/gaboshlib/g_cryptdevice-chpass.bashfunc @@ -0,0 +1,20 @@ +#!/bin/bash + +function g_cryptdevice-chpass { + local g_dev=$1 + if [ -z $g_dev ] + then + g_select=$(lsblk -o NAME,FSTYPE,VENDOR,MODEL,SIZE,MOUNTPOINT -l | grep crypto_LUKS | perl -pe 's/ +/ /g' | while read g_line + do + g_dev=$(echo $g_line | cut -d" " -f1) + g_descr="$(echo $g_line | cut -d" " -f3,4,5,6,7,8 | perl -pe 's/ /\-/g')" + echo -n "/dev/$g_dev $g_descr " + done) + g_dev=$(zenity --width=500 --height=300 --list --title="Please select" --text="Please select the cryptdvice which password sould be changed" --column="Device" --column="Description" $g_select) + fi + [ -w "$g_dev" ] || g_echo_error_exit "Device $g_dev does not exist or is not writeable" + g_sudo="sudo" + whoami | egrep "^root$" && g_sudo="" + $g_sudo cryptsetup luksChangeKey $g_dev || g_echo_error_exit "Pass of $g_dev not changed" +} + diff --git a/gaboshlib/g_cryptdevice.bashfunc b/gaboshlib/g_cryptdevice.bashfunc new file mode 100644 index 0000000..89eed0c --- /dev/null +++ b/gaboshlib/g_cryptdevice.bashfunc @@ -0,0 +1,40 @@ +#!/bin/bash + +function g_cryptdevice { + local g_dev=$1 + if [ -z $g_dev ] + then + if [ -z $DISPLAY ] + then + g_echo_error_exit "No device given" + else + g_select=$(lsblk -o NAME,FSTYPE,VENDOR,MODEL,SIZE,MOUNTPOINT -l | egrep -v 'crypt|^NAME|^sr|1K|SWAP' | perl -pe 's/ +/ /g' | while read g_line + do + g_dev=$(echo $g_line | cut -d" " -f1) + g_descr="$(echo $g_line | cut -d" " -f2,3,4,5,6,7,8 | perl -pe 's/ /\-/g')" + [ -z $g_descr ] && g_descr="dev" + echo -n "/dev/$g_dev $g_descr " + done) + g_dev=$(zenity --width=500 --height=300 --list --title="Please select" --text="Please select the device to crypt" --column="Device" --column="Description" $g_select) + fi + fi + [ -w "$g_dev" ] || g_echo_error_exit "Device $g_dev does not exist or is not writeable" + mount | grep -q "$g_dev" && g_echo_error_exit "Device $g_dev seems to be used/mounted" + g_yesno "All data on $g_dev will be deleted while encryption! Sure to proceed?" + g_echo_ok "Encrypting $g_dev" + g_sudo="sudo" + whoami | egrep "^root$" && g_sudo="" + $g_sudo dd if=/dev/urandom of="$g_dev" bs=512 count=4000 >/dev/null || g_echo_error_exit "dd on $g_dev failed" + $g_sudo cryptsetup luksFormat -v -y -c aes-xts-plain64 -s 512 "$g_dev" || g_echo_error_exit "Encrypting $g_dev failed" + g_echo_ok "Opening $g_dev" + $g_sudo cryptsetup luksOpen "$g_dev" g_cryptdev-$$ || g_echo_error_exit "Opening $g_dev faile" + g_echo_ok "Formatting /dev/mapper/g_cryptdev-$$ ($g_dev)" + $g_sudo mkfs.ext4 -m0 /dev/mapper/g_cryptdev-$$ || g_echo_error_exit "Formatting /dev/mapper/g_cryptdev-$$ ($g_dev) failed" + $g_sudo mount /dev/mapper/g_cryptdev-$$ /mnt || g_echo_error_exit "Mounting /dev/mapper/g_cryptdev-$$ ($g_dev) failed" + $g_sudo chmod 777 /mnt + $g_sudo umount /mnt + g_echo_ok "Closinging /dev/mapper/g_cryptdev-$$ ($g_dev)" + $g_sudo cryptsetup luksClose g_cryptdev-$$ || g_echo_error_exit "Closing /dev/mapper/g_cryptdev-$$ ($g_dev) failed" + g_echo_ok "$g_dev successfully encrypted" +} + diff --git a/gaboshlib/g_date.bashfunc b/gaboshlib/g_date.bashfunc new file mode 100644 index 0000000..a57dd34 --- /dev/null +++ b/gaboshlib/g_date.bashfunc @@ -0,0 +1,5 @@ +#!/bin/bash + +function g_date { + g_date=$(printf '%(%Y-%m-%d %H:%M:%S)T\n') +} diff --git a/gaboshlib/g_date_print.bashfunc b/gaboshlib/g_date_print.bashfunc new file mode 100644 index 0000000..45e343c --- /dev/null +++ b/gaboshlib/g_date_print.bashfunc @@ -0,0 +1,6 @@ +#!/bin/bash + +function g_date_print { + g_date + echo $g_date +} diff --git a/gaboshlib/g_echo.bashfunc b/gaboshlib/g_echo.bashfunc new file mode 100644 index 0000000..5ca5aa5 --- /dev/null +++ b/gaboshlib/g_echo.bashfunc @@ -0,0 +1,9 @@ +#!/bin/bash + +function g_echo { + echo -en "\033[97m$(g_date_print) " + cat <<< "$@" + echo -en "\033[0m" + [ -z $g_alltosyslog ] && return 0 + g_logger $@ +} diff --git a/gaboshlib/g_echo_error.bashfunc b/gaboshlib/g_echo_error.bashfunc new file mode 100644 index 0000000..e86d307 --- /dev/null +++ b/gaboshlib/g_echo_error.bashfunc @@ -0,0 +1,19 @@ +#!/bin/bash + +function g_echo_error { + echo -en "\033[97m$(g_date_print) \033[31mERROR:" 1>&2 + cat <<< "$@" 1>&2 + echo -en "\033[0m" 1>&2 + g_logger ERROR: $@ + if ! [ $0 = /usr/local/bin/notify.sh ] + then + if [ -x /data/debian/usr/local/bin/notify.sh ] + then + cat <<< "$(date "+%F %T") $(hostname) $0($$) ERROR: $@ " | debian-chroot.sh /usr/local/bin/notify.sh + elif [ -x /usr/local/bin/notify.sh ] + then + cat <<< "$(date "+%F %T") $(hostname) $0($$) ERROR: $@" | /usr/local/bin/notify.sh + fi + fi + [ -z $DISPLAY ] || zenity --error --ellipsize --text="$@" +} diff --git a/gaboshlib/g_echo_error_exit.bashfunc b/gaboshlib/g_echo_error_exit.bashfunc new file mode 100644 index 0000000..18e50f7 --- /dev/null +++ b/gaboshlib/g_echo_error_exit.bashfunc @@ -0,0 +1,8 @@ +#!/bin/bash + +function g_echo_error_exit { + g_echo_error "$@" + # kill and no exit because exit may be have no fuction if this is started by Subshell + kill -1 $$ +} + diff --git a/gaboshlib/g_echo_ok.bashfunc b/gaboshlib/g_echo_ok.bashfunc new file mode 100644 index 0000000..9f08eb7 --- /dev/null +++ b/gaboshlib/g_echo_ok.bashfunc @@ -0,0 +1,9 @@ +#!/bin/bash + +function g_echo_ok { + echo -en "\033[97m$(g_date_print) \033[32m" + cat <<< "$@" + echo -en "\033[0m" + g_logger OK: $@ + [ -z $DISPLAY ] || zenity --notification --text="$@" +} diff --git a/gaboshlib/g_echo_warn.bashfunc b/gaboshlib/g_echo_warn.bashfunc new file mode 100644 index 0000000..4a820a3 --- /dev/null +++ b/gaboshlib/g_echo_warn.bashfunc @@ -0,0 +1,19 @@ +#!/bin/bash + +function g_echo_warn { + echo -en "\033[97m$(g_date_print) \033[33mWARNING: " 1>&2 + cat <<< "$@" 1>&2 + echo -en "\033[0m" 1>&2 + g_logger WARN: $@ + if ! [ $0 = /usr/local/bin/notify.sh ] + then + if [ -x /data/debian/usr/local/bin/notify.sh ] + then + cat <<< "$(date "+%F %T") $(hostname) $0($$) WARNING: $@" | debian-chroot.sh /usr/local/bin/notify.sh + elif [ -x /usr/local/bin/notify.sh ] + then + cat <<< "$(date "+%F %T") $(hostname) $0($$) WARNING: $@" | /usr/local/bin/notify.sh + fi + fi + [ -z $DISPLAY ] || zenity --notification --text="$@" +} diff --git a/gaboshlib/g_enterend.bashfunc b/gaboshlib/g_enterend.bashfunc new file mode 100644 index 0000000..8e85ce1 --- /dev/null +++ b/gaboshlib/g_enterend.bashfunc @@ -0,0 +1,7 @@ +#!/bin/bash + +function g_enterend { + g_echo "Enter/Return zum Beenden drücken" + read x + exit 0 +} diff --git a/gaboshlib/g_find_audio.bashfunc b/gaboshlib/g_find_audio.bashfunc new file mode 100644 index 0000000..e461f87 --- /dev/null +++ b/gaboshlib/g_find_audio.bashfunc @@ -0,0 +1,12 @@ +#!/bin/bash + +function g_find_audio { + IFS=$'\n' # for space escapes in path + find $@ -type f | sort | while read g_file + do + mediainfo --File_TestContinuousFileNames=0 "$g_file" > "$g_tmp/g_mediainfo" 2>&1 + cat "$g_tmp/g_mediainfo" | egrep -q "^Video$" && continue + cat "$g_tmp/g_mediainfo" | egrep -q "^Audio$" && echo "$g_file" + done +} + diff --git a/gaboshlib/g_find_image.bashfunc b/gaboshlib/g_find_image.bashfunc new file mode 100644 index 0000000..974e0f7 --- /dev/null +++ b/gaboshlib/g_find_image.bashfunc @@ -0,0 +1,13 @@ +#!/bin/bash + +function g_find_image { + IFS=$'\n' # for space escapes in path + find $@ -type f | sort | while read g_file + do + mediainfo --File_TestContinuousFileNames=0 "$g_file" > "$g_tmp/g_mediainfo" 2>&1 + cat "$g_tmp/g_mediainfo" | egrep -q "^Video$" && continue + cat "$g_tmp/g_mediainfo" | egrep -q "^Audio$" && continue + cat "$g_tmp/g_mediainfo" | egrep -q "^Image$" && echo "$g_file" + done +} + diff --git a/gaboshlib/g_find_video.bashfunc b/gaboshlib/g_find_video.bashfunc new file mode 100644 index 0000000..443fd67 --- /dev/null +++ b/gaboshlib/g_find_video.bashfunc @@ -0,0 +1,18 @@ +#!/bin/bash + +function g_find_video { + IFS=$'\n' # for space escapes in path + # lagest first + find $@ -type f ! -name "*.part" -printf '%k %p\n' | sort -rn | perl -pe 's/^[0-9]+ //' | while read g_file + do + mediainfo --File_TestContinuousFileNames=0 "$g_file" > "$g_tmp/g_mediainfo" 2>&1 + if egrep -q "^Video$" "$g_tmp/g_mediainfo" + then + if egrep -q "^Audio$|^Audio #" "$g_tmp/g_mediainfo" + then + echo "$g_file" + fi + fi + done +} + diff --git a/gaboshlib/g_gentooupdate.bashfunc b/gaboshlib/g_gentooupdate.bashfunc new file mode 100644 index 0000000..9c5b8b9 --- /dev/null +++ b/gaboshlib/g_gentooupdate.bashfunc @@ -0,0 +1,30 @@ +#!/bin/bash + +function g_gentooupdate { + g_lockfile + g_nice + g_echo_warn "Starting Gentoo Update on `hostname`" + g_all-to-syslog + g_checkbasicmounts + mount | grep -q /usr/portage/distfiles || mount -t tmpfs -o size=10G tmpfs /usr/portage/distfiles + emerge -uqDvN --with-bdeps=y --ignore-built-slot-operator-deps y --keep-going @world + emerge -uqDnN --with-bdeps=y @world + emerge @preserved-rebuild -1qv --keep-going + emerge --depclean + rm -f /var/cache/revdep-rebuild/*.rr + revdep-rebuild -i -C -- -1qv --keep-going + #perl-cleaner --all -- -1qv --keep-going | grep -v " : /usr/lib/perl" | grep -v " -> " | grep -i -v "^Skipping directory" | grep -i "Updating)" + cat < ${g_tmp}/ignore +!!! /etc +does not exist +has wrong mtime +/usr/share/applications/thunderbird.desktop +/usr/share/applications/firefox.desktop +/var/spool/at/atjobs/.SEQ +EOF + equery -N -C check -o '*' 2>&1 | grep '^!!!' | egrep -vi -f ${g_tmp}/ignore + rm -r /var/tmp/portage/* + touch /etc/netgroup + touch /var/db/services.db +} + diff --git a/gaboshlib/g_imageaddgps.bashfunc b/gaboshlib/g_imageaddgps.bashfunc new file mode 100644 index 0000000..5af10b0 --- /dev/null +++ b/gaboshlib/g_imageaddgps.bashfunc @@ -0,0 +1,26 @@ +#!/bin/bash + +function g_imageaddgps { + local g_gps=$@ + if echo "$g_gps" | egrep -q "^[NS] [0-9\.\-]+ [EW] [0-9\.\-]+$" + then + local ns=$(echo $g_gps | cut -d" " -f1) + local ns_coord=$(echo $g_gps | cut -d" " -f2) + local wo=$(echo $g_gps | cut -d" " -f3) + local wo_coord=$(echo $g_gps | cut -d" " -f4) + ls *.jpg *.JPG | while read g_image + do + ns_coord=$(echo $ns_coord | perl -pe "s/[0-9][0-9][0-9]\$/$((RANDOM%899+100))/") + wo_coord=$(echo $wo_coord | perl -pe "s/[0-9][0-9][0-9]\$/$((RANDOM%899+100))/") + local g_timestamp=$(ls --time-style='+%Y%m%d%H%M' -l "$g_image" | cut -d" " -f6) + # For update-copy or rsync one second newer file + #g_timestamp=$((g_timestamp+1)) + exiftool -overwrite_original -P -GPSLatitudeRef=$ns -GPSLatitude=$ns_coord -GPSLongitudeRef=$wo -GPSLongitude=$wo_coord $g_image + touch -t $g_timestamp "$g_image" + done + else + g_echo_error "$g_glps Fehlerhafte GPS-Koordinaten. Folgendes Format: N 52.241202 E 9.100710" + return 1 + fi +} + diff --git a/gaboshlib/g_imagefiledatetocreatedate.bashfunc b/gaboshlib/g_imagefiledatetocreatedate.bashfunc new file mode 100644 index 0000000..97de259 --- /dev/null +++ b/gaboshlib/g_imagefiledatetocreatedate.bashfunc @@ -0,0 +1,18 @@ +#!/bin/bash + +function g_imagefiledatetocreatedate { + find . -type f | sort | while read g_image + do + exiftool "$g_image" >"$g_tmp/exiftool" + if egrep -q "^Create Date" "$g_tmp/exiftool" + then + local g_dir=$(dirname "$g_image") + local g_date="$(egrep "^Create Date" "$g_tmp/exiftool" | head -n1 | perl -pe 's/^Create Date.+: //; s/://g; s/ //g; s/^(............).+$/$1/')" + g_echo "$g_image" + touch -t "$g_date" "$g_image" + else + g_echo_warn "$g_image hat kein Create Date in den Metadaten" + fi + done +} + diff --git a/gaboshlib/g_imagerenameIMG_createdate.bashfunc b/gaboshlib/g_imagerenameIMG_createdate.bashfunc new file mode 100644 index 0000000..4b4a6a0 --- /dev/null +++ b/gaboshlib/g_imagerenameIMG_createdate.bashfunc @@ -0,0 +1,17 @@ +#!/bin/bash + +function g_imagerenameIMG_createdate { + find . -iname "*.jpg" | egrep -v '\/IMG_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9].jpg$' | while read g_image + do + exiftool "$g_image" >"$g_tmp/exiftool" + if egrep -q "^Create Date" "$g_tmp/exiftool" + then + local g_imgdir=$(dirname "$g_image") + local g_tofile="IMG_$(egrep "^Create Date" "$g_tmp/exiftool" | head -n1 | perl -pe 's/^Create Date.+: //; s/://g; s/ /_/;').jpg" + mv -vn "$g_image" "$g_imgdir/$g_tofile" + else + g_echo_warn "ERR: $g_image no Create Date found" + fi + done +} + diff --git a/gaboshlib/g_imagesetcreatetimedynminsec.bashfunc b/gaboshlib/g_imagesetcreatetimedynminsec.bashfunc new file mode 100644 index 0000000..e28cfac --- /dev/null +++ b/gaboshlib/g_imagesetcreatetimedynminsec.bashfunc @@ -0,0 +1,27 @@ +#!/bin/bash + +function g_imagesetcreatetimedynminsec { + local g_cdate=$@ + if ! echo "$g_cdate" | perl -pe 's/([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9]) /$1:$2:$3 /' | egrep -q '^[0-9][0-9][0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9]$' + then + g_echo_error "CreateDate invalid : \"YYYY:MM:DD hh\"" + return 1 + fi + local g_s=10 + local g_m=10 + ls | egrep -v 'IMG_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9].jpg$' | while read g_image + do + if [ $g_s -eq 59 ] + then + ((g_m++)) + g_s=10 + fi + local g_timestamp=$(ls --time-style='+%Y%m%d%H%M' -l "$g_image" | cut -d" " -f6) + # For update-copy or rsync one second newer file + #g_timestamp=$((g_timestamp+1)) + exiftool -overwrite_original -CreateDate="$g_cdate:$g_m:$g_s" "$g_image" + touch -t $g_timestamp "$g_image" + ((g_s++)) + done +} + diff --git a/gaboshlib/g_imagesorttonextclouddir.bashfunc b/gaboshlib/g_imagesorttonextclouddir.bashfunc new file mode 100644 index 0000000..bdf31e7 --- /dev/null +++ b/gaboshlib/g_imagesorttonextclouddir.bashfunc @@ -0,0 +1,17 @@ +#!/bin/bash + +function g_imagesorttonextclouddir { + if ! [ -d ~/"Nextcloud/Fotos" ] + then + g_echo_error "Verzeichnis ~/Nextcloud/Fotos existiert nicht" + return 1 + fi + find . -name "*_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9].*" | while read g_image + do + local g_bfile=$(basename "$g_image") + local g_dir=$(echo "$g_bfile" | perl -pe 's/^....(....)(..).+$/$1\/$2/') + mkdir -p ~/"Nextcloud/Fotos/$g_dir" + mv -n "$g_image" ~/"Nextcloud/Fotos/$g_dir/" + done +} + diff --git a/gaboshlib/g_ipsext.bashfunc b/gaboshlib/g_ipsext.bashfunc new file mode 100644 index 0000000..e68d4c7 --- /dev/null +++ b/gaboshlib/g_ipsext.bashfunc @@ -0,0 +1,10 @@ +#!/bin/bash + +function g_ipsext { + if ifconfig | grep -q ppp0 + then + g_ipext=$(ifconfig ppp0 | awk '/inet/ { print $2 } ' | sed -e s/addr://) + else + g_ipext=$(curl -s --connect-timeout 3 --noproxy checkip.amazonaws.com http://checkip.amazonaws.com/) + fi +} diff --git a/gaboshlib/g_iptor.bashfunc b/gaboshlib/g_iptor.bashfunc new file mode 100644 index 0000000..65dbfbf --- /dev/null +++ b/gaboshlib/g_iptor.bashfunc @@ -0,0 +1,5 @@ +#!/bin/bash + +function g_iptor { + g_iptor=$(curl -s --connect-timeout 3 --proxy localhost:8118 http://checkip.amazonaws.com/) +} diff --git a/gaboshlib/g_lockfile.bashfunc b/gaboshlib/g_lockfile.bashfunc new file mode 100644 index 0000000..27206bb --- /dev/null +++ b/gaboshlib/g_lockfile.bashfunc @@ -0,0 +1,33 @@ +#!/bin/bash + +function g_lockfile { + # Do not run multiple times in one script + [ -z $g_lockfile ] || return 0 + g_lockfile=/var/lock/${g_scriptname}.lock + if [[ $EUID -ne 0 ]] + then + g_lockfile=~/.${g_scriptname}.lock + fi + if [ $g_scriptname == "bash" ] + then + g_echo_error "Not for interactive bash - scripts only" + else + if [ -f $g_lockfile ] + then + #if ps ax | grep -v grep | perl -pe 's/^ +//g' | grep ^`cat $g_lockfile` >/dev/null 2>&1 + if [ -d /proc/$(cat $g_lockfile) ] + then + g_echo_error "PID in $g_lockfile exists - exiting..." + exit 1 + else + g_echo_warn "Removing Lockfile $g_lockfile" + rm -f $g_lockfile + fi + fi + echo $$ >$g_lockfile + # Remove lockfile when the script exits/ends + g_trap_exit="$g_trap_exit ; rm $g_lockfile" + trap "$g_trap_exit" EXIT + fi +} + diff --git a/gaboshlib/g_logger.bashfunc b/gaboshlib/g_logger.bashfunc new file mode 100644 index 0000000..852b211 --- /dev/null +++ b/gaboshlib/g_logger.bashfunc @@ -0,0 +1,5 @@ +#!/bin/bash + +function g_logger { + cat <<< $@ | logger -t "$g_syslogtag" +} diff --git a/gaboshlib/g_newtorip.bashfunc b/gaboshlib/g_newtorip.bashfunc new file mode 100644 index 0000000..f03d516 --- /dev/null +++ b/gaboshlib/g_newtorip.bashfunc @@ -0,0 +1,13 @@ +#!/bin/bash + +function g_newtorip { + g_echo "Hole per Tor ne neue IP" + g_iptor + g_echo "Aktuelle Tor IP $g_iptor" + (echo authenticate '""'; echo signal newnym; echo quit) | nc localhost 9051 + g_echo "Warte 10 Sekunden" + sleep 10 + g_iptor + g_echo "Neue IP $g_iptor" +} + diff --git a/gaboshlib/g_nice.bashfunc b/gaboshlib/g_nice.bashfunc new file mode 100644 index 0000000..9193a1e --- /dev/null +++ b/gaboshlib/g_nice.bashfunc @@ -0,0 +1,6 @@ +#!/bin/bash + +function g_nice { + which renice 2>&1 >/dev/null && renice -n 19 -p $$ >/dev/null + which ionice 2>&1 >/dev/null && ionice -c 3 -p $$ +} diff --git a/gaboshlib/g_portagesync.bashfunc b/gaboshlib/g_portagesync.bashfunc new file mode 100644 index 0000000..cdfe51a --- /dev/null +++ b/gaboshlib/g_portagesync.bashfunc @@ -0,0 +1,7 @@ +#!/bin/bash + +function g_portagesync { + g_lockfile + g_echo_ok "Syncing Portag Tree" + emerge --sync -q || emerge-webrsync -q +} diff --git a/gaboshlib/g_read.bashfunc b/gaboshlib/g_read.bashfunc new file mode 100644 index 0000000..9ca12f7 --- /dev/null +++ b/gaboshlib/g_read.bashfunc @@ -0,0 +1,16 @@ +#!/bin/bash + +function g_read { + if [ -z $DISPLAY ] + then + echo -n "$1: " + read g_read + else + g_read=$(zenity --entry --text="$1" --title="$1") + fi + g_read_clean=${g_read//[^a-zA-Z0-9 ]/_} + g_read_clean=${g_read_clean/[ ]/ } + g_read_clean=$(echo "$g_read_clean" | sed 's/^[ \t]*//;s/[ \t]*$//') + g_read_numonly=${g_read_clean//[^0-9]/} +} + diff --git a/gaboshlib/g_select-path.bashfunc b/gaboshlib/g_select-path.bashfunc new file mode 100644 index 0000000..91adb39 --- /dev/null +++ b/gaboshlib/g_select-path.bashfunc @@ -0,0 +1,14 @@ +#!/bin/bash + +function g_select-path { + if [ -z $DISPLAY ] + then + read -p "$@: " g_path + else + g_path=$(zenity --title "$@" --file-selection --directory) + fi + [ -z "$g_path" ] && g_echo_error_exit "Weder Pfad noch eine Datei angegeben" + [ -d "$g_path" ] || [ -e "$g_path" ] || g_echo_error_exit "$@ ist weder ein Pfad noch eine Datei" + echo "$g_path" +} + diff --git a/gaboshlib/g_similar.bashfunc b/gaboshlib/g_similar.bashfunc new file mode 100644 index 0000000..412b757 --- /dev/null +++ b/gaboshlib/g_similar.bashfunc @@ -0,0 +1,33 @@ +#!/bin/bash + +function g_similar { + echo '#!/usr/bin/perl -w + +use strict; +use String::Approx "amatch"; + +my @strings=; +my @cstrings=@strings; + +foreach my $string (@strings) { + chomp($string); + my $string_len = length($string); + next if ($string_len <= 5); + foreach my $cstring (@cstrings) { + chomp($cstring); + my $comparestring=$cstring; + $comparestring=substr($comparestring,0,$string_len); + my @match = amatch($string, [ "i", "10%" ], $comparestring); + foreach my $match (@match) { + next if ($match eq $string); + my $cstring_len = length($cstring); + $string_len=~+2; + next if ($cstring_len >= $string_len); + print "\"$string\" = \"$cstring\"?\n"; + } + } +} +' >${g_tmp}/similar.pl + perl -w ${g_tmp}/similar.pl +} + diff --git a/gaboshlib/g_sortAZ09.bashfunc b/gaboshlib/g_sortAZ09.bashfunc new file mode 100644 index 0000000..e236267 --- /dev/null +++ b/gaboshlib/g_sortAZ09.bashfunc @@ -0,0 +1,31 @@ +#!/bin/bash + +function g_sortAZ09 { + if ! [ -d "$@" ] + then + g_echo_error "$@ is no directory" + return 1 + fi + cd "$@" || return 1 + # Sort + for g_dir in {A..Z} {a..z} {0..9} _ + do + if [ $g_dir = "_" ] + then + echo 'ls -1d * | egrep "[^0-9A-Za-z]."' >$g_tmp/lsaz + else + echo 'ls -1d $g_dir?* 2>/dev/null' >$g_tmp/lsaz + fi + . $g_tmp/lsaz | while read g_item + do + mkdir -p "${g_dir^}" + if [ -f "${g_dir^}/$g_item" ] + then + g_echo_error "${g_dir^}/$g_item existiert bereits" + else + mv "$g_item" "${g_dir^}"/ + fi + done + done +} + diff --git a/gaboshlib/g_startvboxvm.bashfunc b/gaboshlib/g_startvboxvm.bashfunc new file mode 100644 index 0000000..308270f --- /dev/null +++ b/gaboshlib/g_startvboxvm.bashfunc @@ -0,0 +1,6 @@ +#!/bin/bash + +function g_startvboxvm { + VBoxHeadless --startvm $1 +} + diff --git a/gaboshlib/g_test_mediafile.bashfunc b/gaboshlib/g_test_mediafile.bashfunc new file mode 100644 index 0000000..3a49bc9 --- /dev/null +++ b/gaboshlib/g_test_mediafile.bashfunc @@ -0,0 +1,11 @@ +#!/bin/bash + +function g_test_mediafile { + local g_mediafile=$@ + ffprobe "$g_mediafile" >"$g_tmp"/audinfo 2>&1 + if egrep -q "Invalid data found when processing input|No such file or directory|Invalid argument|moov atom not found" "$g_tmp"/audinfo + then + g_echo_warn "Video $g_aud existiert nicht (mehr) oder ist defekt." + return 1 + fi +} diff --git a/gaboshlib/g_valid_ipv4.bashfunc b/gaboshlib/g_valid_ipv4.bashfunc new file mode 100644 index 0000000..4d6f4b6 --- /dev/null +++ b/gaboshlib/g_valid_ipv4.bashfunc @@ -0,0 +1,17 @@ +#!/bin/bash + +function g_valid_ipv4 { + local ip=$1 + local stat=1 + if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] + then + OIFS=$IFS + IFS='.' + ip=($ip) + IFS=$OIFS + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + stat=$? + fi + return $stat +} + diff --git a/gaboshlib/g_valid_ipv6.bashfunc b/gaboshlib/g_valid_ipv6.bashfunc new file mode 100644 index 0000000..0af0928 --- /dev/null +++ b/gaboshlib/g_valid_ipv6.bashfunc @@ -0,0 +1,13 @@ +#!/bin/bash + +function g_valid_ipv6 { + local ip=$1 + regex='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$' + if [[ $ip =~ $regex ]] + then + return 0 + else + return 1 + fi +} + diff --git a/gaboshlib/g_videorenamecamdateformat.bashfunc b/gaboshlib/g_videorenamecamdateformat.bashfunc new file mode 100644 index 0000000..2843415 --- /dev/null +++ b/gaboshlib/g_videorenamecamdateformat.bashfunc @@ -0,0 +1,23 @@ +#!/bin/bash + +function g_videorenamecamdateformat { + local g_cdate=$@ + if ! echo "$g_cdate" | egrep -q '^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9]$' + then + g_echo_error "CreateDate invalid : \"YYYYMMDD_HH\"" + return 1 + fi + local g_s=10 + local g_m=10 + ls | while read g_vid + do + if [ $g_s -eq 59 ] + then + ((g_m++)) + g_s=10 + fi + mv -n "$g_vid" "VID_${g_cdate}$g_m$g_s.mp4" + ((g_s++)) + done +} + diff --git a/gaboshlib/g_yesno.bashfunc b/gaboshlib/g_yesno.bashfunc new file mode 100644 index 0000000..15a67bf --- /dev/null +++ b/gaboshlib/g_yesno.bashfunc @@ -0,0 +1,13 @@ +#!/bin/bash + +function g_yesno { + if [ -z $DISPLAY ] + then + read -p "$@ y/n" -n 1 -r g_yesno + echo + [[ ! $g_yesno =~ ^[Yy]$ ]] && g_echo_error_exit "Exited because answer was no!" + else + zenity --question --text="$@" --default-cancel --no-wrap || g_echo_error_exit "Exited because answer was no!" + fi +} +