diff options
| -rwxr-xr-x | any2flac.sh | 524 | ||||
| -rwxr-xr-x | colortest | 365 | ||||
| -rwxr-xr-x | new-mail-notify | 50 | ||||
| -rwxr-xr-x | psgrep | 3 | ||||
| -rwxr-xr-x | router | 70 | ||||
| -rwxr-xr-x | setup_proxy | 15 | ||||
| -rwxr-xr-x | sign-images | 6 | ||||
| -rwxr-xr-x | xcf2jpeg | 116 |
8 files changed, 1149 insertions, 0 deletions
diff --git a/any2flac.sh b/any2flac.sh new file mode 100755 index 0000000..4d64094 --- /dev/null +++ b/any2flac.sh @@ -0,0 +1,524 @@ +#!/bin/bash + +# +# Version 0.2 +# +# +# + +# debug mode +# set -u +# set -o nounset + +# options +FLAC_SEEK=5s +NICE_PRIORITY=15 +TEST_AFTER_ENCODING=1 +CUE_ENCODING="WINDOWS-1251" + + +# executable +FLAC_BIN=`which flac` +METAFLAC_BIN=`which metaflac` +MAC_BIN=`which mac` +WVUNPACK_BIN=`which wvunpack` +SHNTOOL_BIN=`which shntool` +CUEPRINT_BIN=`which cueprint` +RECODE_BIN=`which recode` +ICONV_BIN=`which iconv` +NICE_BIN=`which nice` + +# =================== DONT EDIT ANYTHING BELOW THIS LINE ======================= +# +NEED_WRITE_TAGS=0 +FORMAT="" +FORMAT_EXT="" +CUE_FILE="" +TMP_WORKING_DIR="" +CANT_RECODE=0 + +# --== COLORS ==-- +#Tnx to cue2tracks project for idea +COLOR_DEFAULT='\033[00m' +COLOR_RED='\033[01;31m' +COLOR_GREEN='\033[01;32m' +COLOR_YELLOW='\033[01;33m' +COLOR_MAGENTA='\033[01;35m' +COLOR_CYAN='\033[01;36m' + + +# +[ -x "$NICE_BIN" ] && NICE="$NICE_BIN --adjustment=$NICE_PRIORITY" || NICE="" + + + + + + +# +# +# +e_warning() +{ + echo -e "${COLOR_YELLOW}WARNING:${COLOR_DEFAULT} $@" +} + + +# +# +# +e_error() +{ + echo -e "${COLOR_RED}ERROR:${COLOR_DEFAULT} $@" >&2 +} + + +# +# +# +e_die() +{ + echo -e "${COLOR_RED}CRITICAL ERROR:${COLOR_DEFAULT} $2" >&2 + exit $1 +} + + + +# +# +# +check_format() +{ + #FORMATS="ape wv wav flac" + for frm in "[Aa][Pp][Ee] ape" "[Ww][Vv] wv" "[Ww][Aa][Vv] wav" "[Ff][Ll][Aa][Cc] flac" + do + set -- $frm + NUM_FILES=`ls -1 ./*.$1 2>/dev/null | wc -l` + + if [[ "$NUM_FILES" -ge "1" ]] + then + [ ! -z "$FORMAT" ] && e_die "2" "Error: more than one format detected. Game over." + + FORMAT_EXT="$1" + FORMAT="$2" + fi + done + + [ -z "$FORMAT" ] && e_die "2" "Error: cant detect any format. Game over." +} + + +# +# +# +test_flac_files() +{ + if [[ $TEST_AFTER_ENCODING -eq 1 ]] + then + echo -e "\n=========== Start testing FLAC-files ============" + $NICE $FLAC_BIN --test ${TMP_WORKING_DIR}/*.flac + echo -e "\n================== Test is done ==================" + fi +} + + +# +# +# used from cuetag code (cuetools) +# Vorbis Comments +# for FLAC and Ogg Vorbis files +write_flac_tags() +{ + if [ $# -eq 3 ] + then + echo -n "Writing tags for '$2'... " + + fields='TITLE VERSION ALBUM TRACKNUMBER TRACKTOTAL ARTIST PERFORMER COPYRIGHT LICENSE ORGANIZATION DESCRIPTION GENRE DATE LOCATION CONTACT ISRC' + + + TITLE='%t' + VERSION='' + ALBUM='%T' + TRACKNUMBER='%n' + TRACKTOTAL='%N' + ARTIST='%c %p' + PERFORMER='%p' + COPYRIGHT='' + LICENSE='' + ORGANIZATION='' + DESCRIPTION='%m' + GENRE='%G' + DATE='' + LOCATION='' + CONTACT='' + ISRC='%i %u' + + # make tmp file for tags + TMP_TAGS_FILE=`mktemp -q -p "./" tags_tmp_XXXXXX` + + [[ ! -f "$TMP_TAGS_FILE" ]] && e_die "2" "Cant create temporary files: '$TMP_TAGS_FILE'" + + METAFLAC="$METAFLAC_BIN --remove-all-tags --no-utf8-convert --import-tags-from=$TMP_TAGS_FILE" + + # date + ALBUM_DATE=`grep -m 1 DATE "$3" | sed -r -e 's/(.?*)REM\ DATE\ //g'` + [ -n "${ALBUM_DATE}" ] || ALBUM_DATE=0000 + echo "DATE=$ALBUM_DATE" > "$TMP_TAGS_FILE" + + (for field in $fields + do + value="" + for conv in `eval echo \\$$field` + do + value=`$CUEPRINT_BIN -n "$1" -t "$conv\n" "$3"` + + if [ -n "$value" ] + then + echo "$field=$value" >> "$TMP_TAGS_FILE" + break + fi + done + done) && $METAFLAC "$2" + + rm -f "$TMP_TAGS_FILE" + + echo "done" + fi +} + + +# +# +# +recode_to_utf8() +{ + # recode + if [ -x "$RECODE_BIN" ] + then + $RECODE_BIN $CUE_ENCODING..UTF-8 "$1" + return $? + elif [ -x "$ICONV_BIN" ] + then + local TMP_CUE=`mktemp -q -p "./" cue_utf8_tmp_XXXXXX` && + { + $ICONV_BIN --from-code=$CUE_ENCODING --to-code=UTF-8 --output=$TMP_CUE "$1" + + if [[ $? -eq 0 ]] + then + mv -f "$TMP_CUE" "$1" + return $? + fi + } + fi + + return 2 +} + + +# +# +# +find_cue_file() +{ + CUE_FILE="${1/.$2}".cue + + if [[ ! -f "$CUE_FILE" ]] + then + CUE_FILE="$1.cue" + fi + + if [[ ! -f "$CUE_FILE" ]] + then + CUE_FILE=`ls -1 *.[Cc][Uu][Ee] | head -n 1` + fi + + if [[ -f "$CUE_FILE" && -s "$CUE_FILE" ]] + then + echo "Found CUE: '$CUE_FILE'" + + # check encodings of cue + if [[ `file "$CUE_FILE" | grep "ISO-8859 text"` ]] + then + echo -n "Converting CUE ($CUE_FILE) to UTF-8... " + recode_to_utf8 "$CUE_FILE" && echo "done" || { echo "error"; CANT_RECODE=1; } + fi + + # + LASTLINE=`tail -n 1 "$CUE_FILE" | tr -d [:blank:] | tr -d [:cntrl:]` + if [[ "$LASTLINE" != "" ]] + then + echo -e "\n" >> "$CUE_FILE" + fi + + else + unset CUE_FILE + fi + + +} + + +# +# +# +trap_int_cb() +{ + if [ -d "$TMP_WORKING_DIR" ] + then + echo -e -n "\n\n *** Got INT signal ***\nDeleting TMP dir... " + rm -f ${TMP_WORKING_DIR}/* && rmdir "$TMP_WORKING_DIR" + echo -e "done\nFinished work.\n\n" + exit 13 + fi +} + + +# +# +# +create_temp_dir() +{ + + TMP_WORKING_DIR=`mktemp -q -d -p "./" tmp_XXXXX` + + [[ ! -d "$TMP_WORKING_DIR" ]] && e_die "5" "Cant create temporary dir: '$TMP_WORKING_DIR'" || trap 'trap_int_cb' TERM INT +} + + +# +# +# +rename_temp_dir() +{ + if [[ -d "$TMP_WORKING_DIR" ]] + then + if [[ -n "$CUE_FILE" ]] + then + local NEW_DIR_NAME=`$CUEPRINT_BIN -d '%T' "$CUE_FILE"` + if [[ -n "$NEW_DIR_NAME" && ! -d "$NEW_DIR_NAME" && ! -f "$NEW_DIR_NAME" ]] + then + mv "$TMP_WORKING_DIR" "$NEW_DIR_NAME" && echo -e "\nYou can find converted files in '$NEW_DIR_NAME' directory" + return + fi + fi + + echo -e "\nYou can find converted files in '$TMP_WORKING_DIR'" + fi +} + + +# +# +# +bin_require() +{ + local FLAG=0 + + for P in "$@" + do + set -- $P + local BIN=$1 + local MAND=$2 + + case $BIN in + ape ) + if [[ ! -x "$MAC_BIN" && $MAND -eq 1 ]] + then + e_error "cant find 'mac' program -- install it" + FLAG=1 + fi + ;; + wv ) + if [[ ! -x "$WVUNPACK_BIN" && $MAND -eq 1 ]] + then + e_error "cant find 'wvunpack' program -- install it" + FLAG=1 + fi + ;; + flac ) + if [[ ! -x "$FLAC_BIN" && $MAND -eq 1 ]] + then + e_error "cant find 'flac' program -- install it" + FLAG=1 + fi + ;; + metaflac ) + if [[ ! -x "$METAFLAC_BIN" && $MAND -eq 1 ]] + then + e_error "cant find 'metaflac' program -- install it" + FLAG=1 + fi + ;; + cueprint ) + if [[ ! -x "$CUEPRINT_BIN" && $MAND -eq 1 ]] + then + e_error "cant find 'cueprint' program -- install it" + FLAG=1 + fi + ;; + shntool ) + if [[ ! -x "$SHNTOOL_BIN" && $MAND -eq 1 ]] + then + e_error "cant find 'shntool' program -- install it" + FLAG=1 + fi + ;; + + esac + done + + [[ $FLAG -ne 0 ]] && exit 5 +} + + +# +# +# +check_bin_require() +{ + [[ $2 -eq 1 ]] && SHN_MAND=1 || SHN_MAND=0 + + case $FORMAT in + ape ) bin_require "ape 1" "shntool $SHN_MAND" "flac 1";; + wv ) bin_require "wv 1" "shntool $SHN_MAND" "flac 1";; + wav ) bin_require "flac 1";; + flac ) bin_require "flac 1";; + * ) e_error "unknown format '$FORMAT'";; + esac + +} + + + + + + +# +# ================================================= +# # Let`s getting starting our party # # +# ================================================= +# + +# +check_format + + +NUM_W_FILES=`ls -1 ./*.$FORMAT_EXT 2>/dev/null | wc -l` + +[[ "$NUM_W_FILES" -lt "1" ]] && e_die "2" "Not found files for convert (detected format is '$FORMAT');-(" + + +if [[ "$NUM_W_FILES" -eq 1 ]] +then + W_FILE=`ls *.$FORMAT_EXT 2>&1` + echo "Found file: '$W_FILE'" + + # cue + find_cue_file "$W_FILE" "$FORMAT" + + if [[ -n "$CUE_FILE" ]] + then + if [[ -f "$W_FILE" && -s "$W_FILE" && -f "$CUE_FILE" && -s "$CUE_FILE" ]] + then + # + check_bin_require "$FORMAT" "$NUM_W_FILES" + + create_temp_dir + + if [[ $CANT_RECODE -eq 0 ]] + then + TRACK_FORMAT="%n - %t" + else + TRACK_FORMAT="%n" + echo "** Warning ** CUE file canot be converted to Unicode. No tags will be writed" + fi + + echo "" + # Converting and Spliting W->FLAC + $NICE $SHNTOOL_BIN split "$W_FILE" -d "$TMP_WORKING_DIR" -t "$TRACK_FORMAT" -o "flac" -f "$CUE_FILE" + NEED_WRITE_TAGS="1" + + # delete pregap + if [[ -f "${TMP_WORKING_DIR}/00 - pregap.flac" ]] + then + echo -e "Found and removed '00 - pregap.flac'... " + rm -f "${TMP_WORKING_DIR}/00 - pregap.flac" && echo "done" || echo "error" + fi + else + e_die "2" "not found valid $FORMAT file" + fi + else + e_die "2" "not found valid CUE file. Cant split file." + fi +else + # + check_bin_require "$FORMAT" "$NUM_W_FILES" + + # + create_temp_dir + + # Converting W->FLAC + for W_FILE in *.${FORMAT_EXT} + do + echo -n "Converting '$W_FILE' to FLAC... " + case $FORMAT in + ape ) + $NICE $MAC_BIN "$W_FILE" - -d | $NICE $FLAC_BIN --silent --seekpoint="$FLAC_SEEK" --output-name="${W_FILE/.${FORMAT_EXT}/.flac}" - + rm -f "$j" + NEED_WRITE_TAGS=1 + ;; + wv ) + $NICE $WVUNPACK_BIN -q -d -o - "$W_FILE" | $NICE $FLAC_BIN --silent --seekpoint="$FLAC_SEEK" --output-name="${TMP_WORKING_DIR}/${W_FILE/.${FORMAT_EXT}/.flac}" - + NEED_WRITE_TAGS=1 + ;; + + wav ) + $NICE $FLAC_BIN --silent --delete-input-file --seekpoint="$FLAC_SEEK" --output-name="${W_FILE/.${FORMAT_EXT}/.flac}" "$W_FILE" + NEED_WRITE_TAGS=1 + ;; + * ) + e_die "2" "unknown format" + ;; + esac + + [ $? -eq 0 ] && echo "done" + done +fi + +# ================================= + +if [[ "$NEED_WRITE_TAGS" -eq 1 && -n "$CUE_FILE" && $CANT_RECODE -eq 0 ]] +then + echo "" + # + bin_require "metaflac 1" "cueprint 1" + + NTRACK=`$CUEPRINT_BIN -d '%N' "$CUE_FILE"` + TRACKNO=1 + + + NUM_FLAC_FILES=`ls -1 ${TMP_WORKING_DIR}/*.flac 2>/dev/null | wc -l` + if [[ "$NUM_FLAC_FILES" -gt "0" ]] + then + if [[ "$NUM_FLAC_FILES" != "$NTRACK" ]] + then + e_warning "number of flac files ($NUM_FLAC_FILES) does not match number of tracks in cue file ($NTRACK)" + fi + + for FLAC_FILE in ${TMP_WORKING_DIR}/*.flac + do + write_flac_tags $TRACKNO "$FLAC_FILE" "$CUE_FILE" + TRACKNO=$(($TRACKNO + 1)) + done + + # test + test_flac_files + fi +fi + +# +rename_temp_dir + +echo -e "\nWork complete! Have a nice day ;-)\n" +exit 0 + diff --git a/colortest b/colortest new file mode 100755 index 0000000..5762112 --- /dev/null +++ b/colortest @@ -0,0 +1,365 @@ +#!/usr/bin/perl + +# by entheon, do whatever the hell you want with this file + +print "\n"; +print "**************************\n"; +print "*XTERM 256Color Test Chart\n"; +print "**************************\n"; +print "* 16 = black\n"; +print "* 255 = white\n"; +print "*\n"; +print "* Usage:\n"; +print "* colortest -w\n"; +print "* wide display\n"; +print "*\n"; +print "* colortest -w -r\n"; +print "* wide display reversed\n"; +print "*\n"; +print "* colortest -w -s\n"; +print "* extra spaces padding\n"; +print "*\n"; +print "* colortest -w -r -s\n"; +print "* available combination\n"; +print "*\n"; +print "**************************\n"; + +if( $ARGV[0] eq "-w" || $ARGV[1] eq "-w" || $ARGV[2] eq "-w" ) { + push(@arr, [( "[38;5;16m 16: 00/00/00", "[38;5;17m 17: 00/00/5f", "[38;5;18m 18: 00/00/87", "[38;5;19m 19: 00/00/af", "[38;5;20m 20: 00/00/d7", "[38;5;21m 21: 00/00/ff")] ); + push(@arr, [( "[38;5;22m 22: 00/5f/00", "[38;5;23m 23: 00/5f/5f", "[38;5;24m 24: 00/5f/87", "[38;5;25m 25: 00/5f/af", "[38;5;26m 26: 00/5f/d7", "[38;5;27m 27: 00/5f/ff")] ); + push(@arr, [( "[38;5;28m 28: 00/87/00", "[38;5;29m 29: 00/87/5f", "[38;5;30m 30: 00/87/87", "[38;5;31m 31: 00/87/af", "[38;5;32m 32: 00/87/d7", "[38;5;33m 33: 00/87/ff")] ); + push(@arr, [( "[38;5;34m 34: 00/af/00", "[38;5;35m 35: 00/af/5f", "[38;5;36m 36: 00/af/87", "[38;5;37m 37: 00/af/af", "[38;5;38m 38: 00/af/d7", "[38;5;39m 39: 00/af/ff")] ); + push(@arr, [( "[38;5;40m 40: 00/d7/00", "[38;5;41m 41: 00/d7/5f", "[38;5;42m 42: 00/d7/87", "[38;5;43m 43: 00/d7/af", "[38;5;44m 44: 00/d7/d7", "[38;5;45m 45: 00/d7/ff")] ); + push(@arr, [( "[38;5;46m 46: 00/ff/00", "[38;5;47m 47: 00/ff/5f", "[38;5;48m 48: 00/ff/87", "[38;5;49m 49: 00/ff/af", "[38;5;50m 50: 00/ff/d7", "[38;5;51m 51: 00/ff/ff")] ); + push(@arr, [( "[38;5;52m 52: 5f/00/00", "[38;5;53m 53: 5f/00/5f", "[38;5;54m 54: 5f/00/87", "[38;5;55m 55: 5f/00/af", "[38;5;56m 56: 5f/00/d7", "[38;5;57m 57: 5f/00/ff")] ); + push(@arr, [( "[38;5;58m 58: 5f/5f/00", "[38;5;59m 59: 5f/5f/5f", "[38;5;60m 60: 5f/5f/87", "[38;5;61m 61: 5f/5f/af", "[38;5;62m 62: 5f/5f/d7", "[38;5;63m 63: 5f/5f/ff")] ); + push(@arr, [( "[38;5;64m 64: 5f/87/00", "[38;5;65m 65: 5f/87/5f", "[38;5;66m 66: 5f/87/87", "[38;5;67m 67: 5f/87/af", "[38;5;68m 68: 5f/87/d7", "[38;5;69m 69: 5f/87/ff")] ); + push(@arr, [( "[38;5;70m 70: 5f/af/00", "[38;5;71m 71: 5f/af/5f", "[38;5;72m 72: 5f/af/87", "[38;5;73m 73: 5f/af/af", "[38;5;74m 74: 5f/af/d7", "[38;5;75m 75: 5f/af/ff")] ); + push(@arr, [( "[38;5;76m 76: 5f/d7/00", "[38;5;77m 77: 5f/d7/5f", "[38;5;78m 78: 5f/d7/87", "[38;5;79m 79: 5f/d7/af", "[38;5;80m 80: 5f/d7/d7", "[38;5;81m 81: 5f/d7/ff")] ); + push(@arr, [( "[38;5;82m 82: 5f/ff/00", "[38;5;83m 83: 5f/ff/5f", "[38;5;84m 84: 5f/ff/87", "[38;5;85m 85: 5f/ff/af", "[38;5;86m 86: 5f/ff/d7", "[38;5;87m 87: 5f/ff/ff")] ); + push(@arr, [( "[38;5;88m 88: 87/00/00", "[38;5;89m 89: 87/00/5f", "[38;5;90m 90: 87/00/87", "[38;5;91m 91: 87/00/af", "[38;5;92m 92: 87/00/d7", "[38;5;93m 93: 87/00/ff")] ); + push(@arr, [( "[38;5;94m 94: 87/5f/00", "[38;5;95m 95: 87/5f/5f", "[38;5;96m 96: 87/5f/87", "[38;5;97m 97: 87/5f/af", "[38;5;98m 98: 87/5f/d7", "[38;5;99m 99: 87/5f/ff")] ); + push(@arr, [( "[38;5;100m 100: 87/87/00", "[38;5;101m 101: 87/87/5f", "[38;5;102m 102: 87/87/87", "[38;5;103m 103: 87/87/af", "[38;5;104m 104: 87/87/d7", "[38;5;105m 105: 87/87/ff")] ); + push(@arr, [( "[38;5;106m 106: 87/af/00", "[38;5;107m 107: 87/af/5f", "[38;5;108m 108: 87/af/87", "[38;5;109m 109: 87/af/af", "[38;5;110m 110: 87/af/d7", "[38;5;111m 111: 87/af/ff")] ); + push(@arr, [( "[38;5;112m 112: 87/d7/00", "[38;5;113m 113: 87/d7/5f", "[38;5;114m 114: 87/d7/87", "[38;5;115m 115: 87/d7/af", "[38;5;116m 116: 87/d7/d7", "[38;5;117m 117: 87/d7/ff")] ); + push(@arr, [( "[38;5;118m 118: 87/ff/00", "[38;5;119m 119: 87/ff/5f", "[38;5;120m 120: 87/ff/87", "[38;5;121m 121: 87/ff/af", "[38;5;122m 122: 87/ff/d7", "[38;5;123m 123: 87/ff/ff")] ); + push(@arr, [( "[38;5;124m 124: af/00/00", "[38;5;125m 125: af/00/5f", "[38;5;126m 126: af/00/87", "[38;5;127m 127: af/00/af", "[38;5;128m 128: af/00/d7", "[38;5;129m 129: af/00/ff")] ); + push(@arr, [( "[38;5;130m 130: af/5f/00", "[38;5;131m 131: af/5f/5f", "[38;5;132m 132: af/5f/87", "[38;5;133m 133: af/5f/af", "[38;5;134m 134: af/5f/d7", "[38;5;135m 135: af/5f/ff")] ); + push(@arr, [( "[38;5;136m 136: af/87/00", "[38;5;137m 137: af/87/5f", "[38;5;138m 138: af/87/87", "[38;5;139m 139: af/87/af", "[38;5;140m 140: af/87/d7", "[38;5;141m 141: af/87/ff")] ); + push(@arr, [( "[38;5;142m 142: af/af/00", "[38;5;143m 143: af/af/5f", "[38;5;144m 144: af/af/87", "[38;5;145m 145: af/af/af", "[38;5;146m 146: af/af/d7", "[38;5;147m 147: af/af/ff")] ); + push(@arr, [( "[38;5;148m 148: af/d7/00", "[38;5;149m 149: af/d7/5f", "[38;5;150m 150: af/d7/87", "[38;5;151m 151: af/d7/af", "[38;5;152m 152: af/d7/d7", "[38;5;153m 153: af/d7/ff")] ); + push(@arr, [( "[38;5;154m 154: af/ff/00", "[38;5;155m 155: af/ff/5f", "[38;5;156m 156: af/ff/87", "[38;5;157m 157: af/ff/af", "[38;5;158m 158: af/ff/d7", "[38;5;159m 159: af/ff/ff")] ); + push(@arr, [( "[38;5;160m 160: d7/00/00", "[38;5;161m 161: d7/00/5f", "[38;5;162m 162: d7/00/87", "[38;5;163m 163: d7/00/af", "[38;5;164m 164: d7/00/d7", "[38;5;165m 165: d7/00/ff")] ); + push(@arr, [( "[38;5;166m 166: d7/5f/00", "[38;5;167m 167: d7/5f/5f", "[38;5;168m 168: d7/5f/87", "[38;5;169m 169: d7/5f/af", "[38;5;170m 170: d7/5f/d7", "[38;5;171m 171: d7/5f/ff")] ); + push(@arr, [( "[38;5;172m 172: d7/87/00", "[38;5;173m 173: d7/87/5f", "[38;5;174m 174: d7/87/87", "[38;5;175m 175: d7/87/af", "[38;5;176m 176: d7/87/d7", "[38;5;177m 177: d7/87/ff")] ); + push(@arr, [( "[38;5;178m 178: d7/af/00", "[38;5;179m 179: d7/af/5f", "[38;5;180m 180: d7/af/87", "[38;5;181m 181: d7/af/af", "[38;5;182m 182: d7/af/d7", "[38;5;183m 183: d7/af/ff")] ); + push(@arr, [( "[38;5;184m 184: d7/d7/00", "[38;5;185m 185: d7/d7/5f", "[38;5;186m 186: d7/d7/87", "[38;5;187m 187: d7/d7/af", "[38;5;188m 188: d7/d7/d7", "[38;5;189m 189: d7/d7/ff")] ); + push(@arr, [( "[38;5;190m 190: d7/ff/00", "[38;5;191m 191: d7/ff/5f", "[38;5;192m 192: d7/ff/87", "[38;5;193m 193: d7/ff/af", "[38;5;194m 194: d7/ff/d7", "[38;5;195m 195: d7/ff/ff")] ); + push(@arr, [( "[38;5;196m 196: ff/00/00", "[38;5;197m 197: ff/00/5f", "[38;5;198m 198: ff/00/87", "[38;5;199m 199: ff/00/af", "[38;5;200m 200: ff/00/d7", "[38;5;201m 201: ff/00/ff")] ); + push(@arr, [( "[38;5;202m 202: ff/5f/00", "[38;5;203m 203: ff/5f/5f", "[38;5;204m 204: ff/5f/87", "[38;5;205m 205: ff/5f/af", "[38;5;206m 206: ff/5f/d7", "[38;5;207m 207: ff/5f/ff")] ); + push(@arr, [( "[38;5;208m 208: ff/87/00", "[38;5;209m 209: ff/87/5f", "[38;5;210m 210: ff/87/87", "[38;5;211m 211: ff/87/af", "[38;5;212m 212: ff/87/d7", "[38;5;213m 213: ff/87/ff")] ); + push(@arr, [( "[38;5;214m 214: ff/af/00", "[38;5;215m 215: ff/af/5f", "[38;5;216m 216: ff/af/87", "[38;5;217m 217: ff/af/af", "[38;5;218m 218: ff/af/d7", "[38;5;219m 219: ff/af/ff")] ); + push(@arr, [( "[38;5;220m 220: ff/d7/00", "[38;5;221m 221: ff/d7/5f", "[38;5;222m 222: ff/d7/87", "[38;5;223m 223: ff/d7/af", "[38;5;224m 224: ff/d7/d7", "[38;5;225m 225: ff/d7/ff")] ); + push(@arr, [( "[38;5;226m 226: ff/ff/00", "[38;5;227m 227: ff/ff/5f", "[38;5;228m 228: ff/ff/87", "[38;5;229m 229: ff/ff/af", "[38;5;230m 230: ff/ff/d7", "[38;5;231m 231: ff/ff/ff")] ); + push(@arr, [( "[38;5;232m 232: 08/08/08", "[38;5;233m 233: 12/12/12", "[38;5;234m 234: 1c/1c/1c", "[38;5;235m 235: 26/26/26", "[38;5;236m 236: 30/30/30", "[38;5;237m 237: 3a/3a/3a")] ); + push(@arr, [( "[38;5;238m 238: 44/44/44", "[38;5;239m 239: 4e/4e/4e", "[38;5;240m 240: 58/58/58", "[38;5;241m 241: 62/62/62", "[38;5;242m 242: 6c/6c/6c", "[38;5;243m 243: 76/76/76")] ); + push(@arr, [( "[38;5;244m 244: 80/80/80", "[38;5;245m 245: 8a/8a/8a", "[38;5;246m 246: 94/94/94", "[38;5;247m 247: 9e/9e/9e", "[38;5;248m 248: a8/a8/a8", "[38;5;249m 249: b2/b2/b2")] ); + push(@arr, [( "[38;5;250m 250: bc/bc/bc", "[38;5;251m 251: c6/c6/c6", "[38;5;252m 252: d0/d0/d0", "[38;5;253m 253: da/da/da", "[38;5;254m 254: e4/e4/e4", "[38;5;255m 255: ee/ee/ee")] ); + + if( $ARGV[0] eq "-s" || $ARGV[1] eq "-s" || $ARGV[2] eq "-s" ){ + $padding = " "; + } + else { + + } + + # display in reverse order + if( $ARGV[0] eq "-r" || $ARGV[1] eq "-r" || $ARGV[2] eq "-r" ){ + for( $dimone = 0; $dimone < scalar @arr; $dimone++ ) { + + $seed = ($dimone % 6) * -1; + for( $dimtwo = 0; $dimtwo < 6; $dimtwo++ ) { + + $movone = $seed; + $movtwo = $seed * -1; + + print $arr[$dimone][$dimtwo] . $padding; + + $seed = $seed+1; + } + + print "\n"; + } + } + else { + for( $dimone = 0; $dimone < scalar @arr; $dimone++ ) { + + $seed = ($dimone % 6) * -1; + for( $dimtwo = 0; $dimtwo < 6; $dimtwo++ ) { + + $movone = $seed; + $movtwo = $seed * -1; + + $newone = $dimone+$movone; + $newtwo = $dimtwo+$movtwo; + + if( $newone < scalar @arr ){ + print $arr[$newone][$newtwo] . $padding; + } + + $seed = $seed+1; + } + + print "\n"; + } + } + print "\n"; + print "\n"; + +} +else { + print "[38;5;16m 16: 00/00/00\n"; + print "[38;5;17m 17: 00/00/5f\n"; + print "[38;5;18m 18: 00/00/87\n"; + print "[38;5;19m 19: 00/00/af\n"; + print "[38;5;20m 20: 00/00/d7\n"; + print "[38;5;21m 21: 00/00/ff\n"; + print "[38;5;22m 22: 00/5f/00\n"; + print "[38;5;23m 23: 00/5f/5f\n"; + print "[38;5;24m 24: 00/5f/87\n"; + print "[38;5;25m 25: 00/5f/af\n"; + print "[38;5;26m 26: 00/5f/d7\n"; + print "[38;5;27m 27: 00/5f/ff\n"; + print "[38;5;28m 28: 00/87/00\n"; + print "[38;5;29m 29: 00/87/5f\n"; + print "[38;5;30m 30: 00/87/87\n"; + print "[38;5;31m 31: 00/87/af\n"; + print "[38;5;32m 32: 00/87/d7\n"; + print "[38;5;33m 33: 00/87/ff\n"; + print "[38;5;34m 34: 00/af/00\n"; + print "[38;5;35m 35: 00/af/5f\n"; + print "[38;5;36m 36: 00/af/87\n"; + print "[38;5;37m 37: 00/af/af\n"; + print "[38;5;38m 38: 00/af/d7\n"; + print "[38;5;39m 39: 00/af/ff\n"; + print "[38;5;40m 40: 00/d7/00\n"; + print "[38;5;41m 41: 00/d7/5f\n"; + print "[38;5;42m 42: 00/d7/87\n"; + print "[38;5;43m 43: 00/d7/af\n"; + print "[38;5;44m 44: 00/d7/d7\n"; + print "[38;5;45m 45: 00/d7/ff\n"; + print "[38;5;46m 46: 00/ff/00\n"; + print "[38;5;47m 47: 00/ff/5f\n"; + print "[38;5;48m 48: 00/ff/87\n"; + print "[38;5;49m 49: 00/ff/af\n"; + print "[38;5;50m 50: 00/ff/d7\n"; + print "[38;5;51m 51: 00/ff/ff\n"; + print "[38;5;52m 52: 5f/00/00\n"; + print "[38;5;53m 53: 5f/00/5f\n"; + print "[38;5;54m 54: 5f/00/87\n"; + print "[38;5;55m 55: 5f/00/af\n"; + print "[38;5;56m 56: 5f/00/d7\n"; + print "[38;5;57m 57: 5f/00/ff\n"; + print "[38;5;58m 58: 5f/5f/00\n"; + print "[38;5;59m 59: 5f/5f/5f\n"; + print "[38;5;60m 60: 5f/5f/87\n"; + print "[38;5;61m 61: 5f/5f/af\n"; + print "[38;5;62m 62: 5f/5f/d7\n"; + print "[38;5;63m 63: 5f/5f/ff\n"; + print "[38;5;64m 64: 5f/87/00\n"; + print "[38;5;65m 65: 5f/87/5f\n"; + print "[38;5;66m 66: 5f/87/87\n"; + print "[38;5;67m 67: 5f/87/af\n"; + print "[38;5;68m 68: 5f/87/d7\n"; + print "[38;5;69m 69: 5f/87/ff\n"; + print "[38;5;70m 70: 5f/af/00\n"; + print "[38;5;71m 71: 5f/af/5f\n"; + print "[38;5;72m 72: 5f/af/87\n"; + print "[38;5;73m 73: 5f/af/af\n"; + print "[38;5;74m 74: 5f/af/d7\n"; + print "[38;5;75m 75: 5f/af/ff\n"; + print "[38;5;76m 76: 5f/d7/00\n"; + print "[38;5;77m 77: 5f/d7/5f\n"; + print "[38;5;78m 78: 5f/d7/87\n"; + print "[38;5;79m 79: 5f/d7/af\n"; + print "[38;5;80m 80: 5f/d7/d7\n"; + print "[38;5;81m 81: 5f/d7/ff\n"; + print "[38;5;82m 82: 5f/ff/00\n"; + print "[38;5;83m 83: 5f/ff/5f\n"; + print "[38;5;84m 84: 5f/ff/87\n"; + print "[38;5;85m 85: 5f/ff/af\n"; + print "[38;5;86m 86: 5f/ff/d7\n"; + print "[38;5;87m 87: 5f/ff/ff\n"; + print "[38;5;88m 88: 87/00/00\n"; + print "[38;5;89m 89: 87/00/5f\n"; + print "[38;5;90m 90: 87/00/87\n"; + print "[38;5;91m 91: 87/00/af\n"; + print "[38;5;92m 92: 87/00/d7\n"; + print "[38;5;93m 93: 87/00/ff\n"; + print "[38;5;94m 94: 87/5f/00\n"; + print "[38;5;95m 95: 87/5f/5f\n"; + print "[38;5;96m 96: 87/5f/87\n"; + print "[38;5;97m 97: 87/5f/af\n"; + print "[38;5;98m 98: 87/5f/d7\n"; + print "[38;5;99m 99: 87/5f/ff\n"; + print "[38;5;100m 100 :87/87/00\n"; + print "[38;5;101m 101 :87/87/5f\n"; + print "[38;5;102m 102 :87/87/87\n"; + print "[38;5;103m 103 :87/87/af\n"; + print "[38;5;104m 104 :87/87/d7\n"; + print "[38;5;105m 105 :87/87/ff\n"; + print "[38;5;106m 106 :87/af/00\n"; + print "[38;5;107m 107 :87/af/5f\n"; + print "[38;5;108m 108 :87/af/87\n"; + print "[38;5;109m 109 :87/af/af\n"; + print "[38;5;110m 110 :87/af/d7\n"; + print "[38;5;111m 111 :87/af/ff\n"; + print "[38;5;112m 112 :87/d7/00\n"; + print "[38;5;113m 113 :87/d7/5f\n"; + print "[38;5;114m 114 :87/d7/87\n"; + print "[38;5;115m 115 :87/d7/af\n"; + print "[38;5;116m 116 :87/d7/d7\n"; + print "[38;5;117m 117 :87/d7/ff\n"; + print "[38;5;118m 118 :87/ff/00\n"; + print "[38;5;119m 119 :87/ff/5f\n"; + print "[38;5;120m 120 :87/ff/87\n"; + print "[38;5;121m 121 :87/ff/af\n"; + print "[38;5;122m 122 :87/ff/d7\n"; + print "[38;5;123m 123 :87/ff/ff\n"; + print "[38;5;124m 124 :af/00/00\n"; + print "[38;5;125m 125 :af/00/5f\n"; + print "[38;5;126m 126 :af/00/87\n"; + print "[38;5;127m 127 :af/00/af\n"; + print "[38;5;128m 128 :af/00/d7\n"; + print "[38;5;129m 129 :af/00/ff\n"; + print "[38;5;130m 130 :af/5f/00\n"; + print "[38;5;131m 131 :af/5f/5f\n"; + print "[38;5;132m 132 :af/5f/87\n"; + print "[38;5;133m 133 :af/5f/af\n"; + print "[38;5;134m 134 :af/5f/d7\n"; + print "[38;5;135m 135 :af/5f/ff\n"; + print "[38;5;136m 136 :af/87/00\n"; + print "[38;5;137m 137 :af/87/5f\n"; + print "[38;5;138m 138 :af/87/87\n"; + print "[38;5;139m 139 :af/87/af\n"; + print "[38;5;140m 140 :af/87/d7\n"; + print "[38;5;141m 141 :af/87/ff\n"; + print "[38;5;142m 142 :af/af/00\n"; + print "[38;5;143m 143 :af/af/5f\n"; + print "[38;5;144m 144 :af/af/87\n"; + print "[38;5;145m 145 :af/af/af\n"; + print "[38;5;146m 146 :af/af/d7\n"; + print "[38;5;147m 147 :af/af/ff\n"; + print "[38;5;148m 148 :af/d7/00\n"; + print "[38;5;149m 149 :af/d7/5f\n"; + print "[38;5;150m 150 :af/d7/87\n"; + print "[38;5;151m 151 :af/d7/af\n"; + print "[38;5;152m 152 :af/d7/d7\n"; + print "[38;5;153m 153 :af/d7/ff\n"; + print "[38;5;154m 154 :af/ff/00\n"; + print "[38;5;155m 155 :af/ff/5f\n"; + print "[38;5;156m 156 :af/ff/87\n"; + print "[38;5;157m 157 :af/ff/af\n"; + print "[38;5;158m 158 :af/ff/d7\n"; + print "[38;5;159m 159 :af/ff/ff\n"; + print "[38;5;160m 160 :d7/00/00\n"; + print "[38;5;161m 161 :d7/00/5f\n"; + print "[38;5;162m 162 :d7/00/87\n"; + print "[38;5;163m 163 :d7/00/af\n"; + print "[38;5;164m 164 :d7/00/d7\n"; + print "[38;5;165m 165 :d7/00/ff\n"; + print "[38;5;166m 166 :d7/5f/00\n"; + print "[38;5;167m 167 :d7/5f/5f\n"; + print "[38;5;168m 168 :d7/5f/87\n"; + print "[38;5;169m 169 :d7/5f/af\n"; + print "[38;5;170m 170 :d7/5f/d7\n"; + print "[38;5;171m 171 :d7/5f/ff\n"; + print "[38;5;172m 172 :d7/87/00\n"; + print "[38;5;173m 173 :d7/87/5f\n"; + print "[38;5;174m 174 :d7/87/87\n"; + print "[38;5;175m 175 :d7/87/af\n"; + print "[38;5;176m 176 :d7/87/d7\n"; + print "[38;5;177m 177 :d7/87/ff\n"; + print "[38;5;178m 178 :d7/af/00\n"; + print "[38;5;179m 179 :d7/af/5f\n"; + print "[38;5;180m 180 :d7/af/87\n"; + print "[38;5;181m 181 :d7/af/af\n"; + print "[38;5;182m 182 :d7/af/d7\n"; + print "[38;5;183m 183 :d7/af/ff\n"; + print "[38;5;184m 184 :d7/d7/00\n"; + print "[38;5;185m 185 :d7/d7/5f\n"; + print "[38;5;186m 186 :d7/d7/87\n"; + print "[38;5;187m 187 :d7/d7/af\n"; + print "[38;5;188m 188 :d7/d7/d7\n"; + print "[38;5;189m 189 :d7/d7/ff\n"; + print "[38;5;190m 190 :d7/ff/00\n"; + print "[38;5;191m 191 :d7/ff/5f\n"; + print "[38;5;192m 192 :d7/ff/87\n"; + print "[38;5;193m 193 :d7/ff/af\n"; + print "[38;5;194m 194 :d7/ff/d7\n"; + print "[38;5;195m 195 :d7/ff/ff\n"; + print "[38;5;196m 196 :ff/00/00\n"; + print "[38;5;197m 197 :ff/00/5f\n"; + print "[38;5;198m 198 :ff/00/87\n"; + print "[38;5;199m 199 :ff/00/af\n"; + print "[38;5;200m 200 :ff/00/d7\n"; + print "[38;5;201m 201 :ff/00/ff\n"; + print "[38;5;202m 202 :ff/5f/00\n"; + print "[38;5;203m 203 :ff/5f/5f\n"; + print "[38;5;204m 204 :ff/5f/87\n"; + print "[38;5;205m 205 :ff/5f/af\n"; + print "[38;5;206m 206 :ff/5f/d7\n"; + print "[38;5;207m 207 :ff/5f/ff\n"; + print "[38;5;208m 208 :ff/87/00\n"; + print "[38;5;209m 209 :ff/87/5f\n"; + print "[38;5;210m 210 :ff/87/87\n"; + print "[38;5;211m 211 :ff/87/af\n"; + print "[38;5;212m 212 :ff/87/d7\n"; + print "[38;5;213m 213 :ff/87/ff\n"; + print "[38;5;214m 214 :ff/af/00\n"; + print "[38;5;215m 215 :ff/af/5f\n"; + print "[38;5;216m 216 :ff/af/87\n"; + print "[38;5;217m 217 :ff/af/af\n"; + print "[38;5;218m 218 :ff/af/d7\n"; + print "[38;5;219m 219 :ff/af/ff\n"; + print "[38;5;220m 220 :ff/d7/00\n"; + print "[38;5;221m 221 :ff/d7/5f\n"; + print "[38;5;222m 222 :ff/d7/87\n"; + print "[38;5;223m 223 :ff/d7/af\n"; + print "[38;5;224m 224 :ff/d7/d7\n"; + print "[38;5;225m 225 :ff/d7/ff\n"; + print "[38;5;226m 226 :ff/ff/00\n"; + print "[38;5;227m 227 :ff/ff/5f\n"; + print "[38;5;228m 228 :ff/ff/87\n"; + print "[38;5;229m 229 :ff/ff/af\n"; + print "[38;5;230m 230 :ff/ff/d7\n"; + print "[38;5;231m 231 :ff/ff/ff\n"; + print "[38;5;232m 232 :08/08/08\n"; + print "[38;5;233m 233 :12/12/12\n"; + print "[38;5;234m 234 :1c/1c/1c\n"; + print "[38;5;235m 235 :26/26/26\n"; + print "[38;5;236m 236 :30/30/30\n"; + print "[38;5;237m 237 :3a/3a/3a\n"; + print "[38;5;238m 238 :44/44/44\n"; + print "[38;5;239m 239 :4e/4e/4e\n"; + print "[38;5;240m 240 :58/58/58\n"; + print "[38;5;241m 241 :62/62/62\n"; + print "[38;5;242m 242 :6c/6c/6c\n"; + print "[38;5;243m 243 :76/76/76\n"; + print "[38;5;244m 244 :80/80/80\n"; + print "[38;5;245m 245 :8a/8a/8a\n"; + print "[38;5;246m 246 :94/94/94\n"; + print "[38;5;247m 247 :9e/9e/9e\n"; + print "[38;5;248m 248 :a8/a8/a8\n"; + print "[38;5;249m 249 :b2/b2/b2\n"; + print "[38;5;250m 250 :bc/bc/bc\n"; + print "[38;5;251m 251 :c6/c6/c6\n"; + print "[38;5;252m 252 :d0/d0/d0\n"; + print "[38;5;253m 253 :da/da/da\n"; + print "[38;5;254m 254 :e4/e4/e4\n"; + print "[38;5;255m 255 :ee/ee/ee\n"; + print "\n"; + print "\n"; +} +print "0m"; +exit; diff --git a/new-mail-notify b/new-mail-notify new file mode 100755 index 0000000..92f8bcf --- /dev/null +++ b/new-mail-notify @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from email.header import decode_header +from os import execlp +from xml.sax.saxutils import escape +import email +import mailbox +import sys +import re + +INBOX_DIR = '~/Mail/Gmail/INBOX' +N_ICON = '~/.icons/email.svg' +N_TIME = 15 * 1000 # 15 seconds +MAX_DETAIL = 6 + +def decode(string, charset = 'utf8'): + return ' '.join(d[0].decode(d[1] or charset) for d in decode_header(string)) + +def notify(messages): + if len(messages) == 0: + sys.exit(0) + title = "Новая почта (%d)" % len(messages) + m = [] + for message in messages[:MAX_DETAIL]: + detail = '<b>' + escape(message['Subject']) + '</b>\n' + detail += '<i>' + escape(message['From']) + '</i>' + m.append(detail) + details = '\n\n'.join(m) + details += '\n' + execlp('notify-send', 'notify-send', '-t', str(N_TIME), '-i', N_ICON, title, details) + +def get_messages(inbox): + box = mailbox.Maildir(inbox, factory=None) + msgs = [] + for key in sorted(box.iterkeys(), reverse=True): + try: + message = box[key] + except email.Errors.MessageParseError: + continue + if 'S' in message.get_flags(): + continue + + msgs += [{ + 'From': decode(message.get('From')), + 'Subject': decode(message.get('Subject')) + },] + return msgs + +if __name__ == '__main__': + notify(get_messages(INBOX_DIR)) @@ -0,0 +1,3 @@ +#!/bin/bash + +ps aux | grep -e "$1" | grep -v grep @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +import argparse +import telnetlib +import getpass + +CMD_SYSTEM_MAINTENANCE = 24 +CMD_DIAGNOSTIC = 4 +CMD_RESET_XDSL = 1 +CMD_REBOOT_SYSTEM = 21 + +class Router(): + def __init__(self, host, timeout=5): + self.timeout = timeout + self.tc = telnetlib.Telnet(host, timeout=timeout) + + def login(self, password): + self._command('Password: ', password) + + def reboot(self): + cmds = [CMD_SYSTEM_MAINTENANCE, CMD_DIAGNOSTIC, CMD_REBOOT_SYSTEM] + [self._menu(c) for c in cmds] + + def reset(self): + cmds = [CMD_SYSTEM_MAINTENANCE, CMD_DIAGNOSTIC, CMD_RESET_XDSL] + [self._menu(c) for c in cmds] + + def _command(self, prompt, command): + self.tc.read_until(prompt, self.timeout) + self.tc.write(str(command) + '\n') + + def _menu(self, menu): + self._command('Enter Menu Selection Number: ', menu) + + def __enter__(self): + return self + + def __exit__(self, *args): + self.tc.close() + +def setup_parser(): +# TODO write usage +# TODO add config reader + parser = argparse.ArgumentParser() + parser.add_argument('-c', '--config', dest='config', default='~/.router', + help='config file destination') + parser.add_argument('-p', '--password', dest='password', + help='you router admin password') + parser.add_argument('-t', '--timeout', dest='timeout', default=3, type=int, + help='timeout in seconds') + parser.add_argument('host', help='host name or IP address') + parser.add_argument('command', choices=['reboot', 'reset'], + help='command to execute') + return parser + +def main(): + parser = setup_parser() + args = parser.parse_args() + + password = args.password or getpass.getpass() + + with Router(args.host, args.timeout) as r: + r.login(password) + if args.command == 'reboot': + r.reboot() + elif args.command == 'reset': + r.reset() + +if __name__ == '__main__': + main() diff --git a/setup_proxy b/setup_proxy new file mode 100755 index 0000000..f707ac0 --- /dev/null +++ b/setup_proxy @@ -0,0 +1,15 @@ +#!/bin/bash + +gconftool=gconftool-2 + +http_proxy= +no_proxy= + +if [[ 'true' = "$($gconftool -g /system/http_proxy/use_http_proxy)" ]] ; then + host=$($gconftool -g /system/http_proxy/host) + port=$($gconftool -g /system/http_proxy/port) + http_proxy=http://$host:$port/ + no_proxy=$($gconftool -g /system/http_proxy/ignore_hosts | tr -d '[]') +fi + +echo http_proxy no_proxy diff --git a/sign-images b/sign-images new file mode 100755 index 0000000..a8950b6 --- /dev/null +++ b/sign-images @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e + +exiftool -overwrite_original -Artist='Bobov Anton' -Copyright='Bobov Anton' -UserComment='http://dexter-tmn.livejournal.com/' $* + diff --git a/xcf2jpeg b/xcf2jpeg new file mode 100755 index 0000000..5f460b3 --- /dev/null +++ b/xcf2jpeg @@ -0,0 +1,116 @@ +#!/bin/bash +# Taken from: http://billauer.co.il/blog/2009/07/gimp-xcf-jpg-jpeg-convert-bash-script/ + +SELFNAME=$(basename $0) +SIZE=800 +QUALITY=95 +OVERWRITE=0 +GIMP="gimp" + +die() +{ + printf "%s\n" "$1" >&2 + exit 1 +} + +print_help() +{ + cat >&2 << EOF +Usage: ./$SELFNAME [OPTION]... [FILE]... + + Convert XCF images to JPEG. + +Options: + -s, --size size in pixels of biggest size of image (default: $SIZE) + -q, --quality JPEG image quality in percents (0-100) (default: $QUALITY) + -f, --force force convert, even if result file exists + -h, --help print this help + +Example: + Convert all XCF files in directory + ./$SELFNAME *.xcf + + Convert XCF file to 900px image + ./$SELFNAME -s 900 image.xcf +EOF +} + +while [[ $1 = -* ]] +do + case "$1" in + -s|--size) + SIZE="$2" + [[ "$SIZE" -gt 0 ]] || die "Error: Size not integer: $SIZE" + shift + ;; + -q|--quality) + QUALITY="$2" + [[ "$QUALITY" -gt 0 && "$QUALITY" -le 100 ]] || die "Error: Quality not percent: $QUALITY" + shift + ;; + -h|--help) + print_help + exit + ;; + -f|--force) + OVERWRITE=1 + ;; + *) + die "Error: Unknown option: $1" + ;; + esac + shift +done + +RATE_STEP=${RATE_STEP:=.7} + +{ +cat << EOF +(define (resize image size) + (let* ( + (rate-step $RATE_STEP) + (cur-width (car (gimp-image-width image))) + (cur-height (car (gimp-image-height image))) + ) + (while (> (max cur-width cur-height) $SIZE) + (if (< (max (* cur-width rate-step) (* cur-height rate-step)) $SIZE) + (set! rate-step (min (/ $SIZE cur-height) (/ $SIZE cur-width))) + 1 + ) + (set! cur-width (* cur-width rate-step)) + (set! cur-height (* cur-height rate-step)) + + (gimp-image-scale image cur-width cur-height) + ) + ) +) + +(define (convert-xcf-to-jpeg filename outfile) + (let* ( + (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) + (drawable (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE))) + ) + + (resize image $SIZE) + + (file-jpeg-save RUN-NONINTERACTIVE image drawable outfile outfile (/ $QUALITY 100) 0 0 0 " " 0 1 0 1) + (gimp-image-delete image) ; ... or memory will explode + ) + ) +(gimp-message-set-handler 1) ; Message to standart output +EOF + +for file +do + FILENAME=$file + OUT_FILENAME=${FILENAME%%.xcf}.jpg + if [[ $OVERWRITE = 0 && -f "$OUT_FILENAME" ]] + then + printf "Warning: File $OUT_FILENAME exists, skipping.\n" >&2 + return + fi + echo "(convert-xcf-to-jpeg \"$FILENAME\" \"$OUT_FILENAME\")" +done + +echo "(gimp-quit 0)" +} | "$GIMP" -i -b - |
