From b5485475de82ac0743c37e3eb0c35e877f7213ff Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 22 Feb 2009 21:56:40 +0100 Subject: updated --- #upload-image.sh | 23 ------ a | 108 ++++++++++++++++++++++++ bashrun.sh | 107 +++++++++++++++++++++++- drop.sh | 16 ++-- fix_ntfs.sh | 19 ----- gvim | 2 + python/openbox-shutdown.conf | 40 +++++++++ python/openbox-shutdown.py | 190 +++++++++++++++++++++++++++++++++++++++++++ python/shutdown.py | 99 +++++++++++----------- screen.sh | 1 - set-background.sh | 1 - ssh-mount.sh | 2 +- upload-image.sh | 22 +++++ xup.sh | 1 - 14 files changed, 527 insertions(+), 104 deletions(-) delete mode 100755 #upload-image.sh create mode 100755 a mode change 120000 => 100755 bashrun.sh delete mode 100755 fix_ntfs.sh create mode 100755 gvim create mode 100644 python/openbox-shutdown.conf create mode 100755 python/openbox-shutdown.py create mode 100644 upload-image.sh diff --git a/#upload-image.sh b/#upload-image.sh deleted file mode 100755 index 4fbb0f8..0000000 --- a/#upload-image.sh +++ /dev/null @@ -1,23 +0,0 @@ -#/bin/bash -#---------------------------------------------------- -# File: upload-image.sh -# Version: 0.1.1 -# Date: 2009-01-20 -# Author: Florian "Bluewind" Pritz -# Upload image to imagebanana and output url -#---------------------------------------------------- -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -curl -F img="@$1" -F "send=Hochladen" -F 'resize=320x240' -H "Expect: " www.imagebanana.com -L | ack -o -n '(http.*?\/view\/.*?\..{3})' | tail -n 1 diff --git a/a b/a new file mode 100755 index 0000000..998fe6e --- /dev/null +++ b/a @@ -0,0 +1,108 @@ +#!/bin/bash +###################################################### +#+ Simple archive script with multiple backends +#+ Rev. 3 - 2/07/09 - optimum.reflex@gmail.com +###################################################### +hlp () { # Help function + echo "usage: $0 [--help] [archive] [sources]" + echo "[sources] is the files or folder you want added to the archive." + echo + echo "[archive] is the name of the archive generated, including extension." + echo "Extensions are: .7z .zip .bz2 .gz .lzma .tar.*" + exit 0 +} + +if [ $# -lt 2 ]; then # Need atleast an archive and one source + hlp +fi + +tarfunc () { # function that does the work + MSG="packing [$SRCD] to [$DIR/$TAR]... " + case "$TAR" in + *.7z ) + echo -n $MSG + /usr/bin/7z a -mx=9 $DIR/$TAR $SRC + ;; + *.t* ) + echo -n $MSG + /bin/tar -acZf $DIR/$TAR $SRC + ;; + *.bz2 ) + echo -n $MSG + /bin/bzip2 -cq9 $SRC > $DIR/$TAR + ;; + *.gz ) + echo -n $MSG + /bin/gzip -cq9 $SRC > $DIR/$TAR + ;; + *.zip ) + echo -n $MSG + /usr/bin/zip -qr9 $DIR/$TAR $SRC + ;; + *.lzma ) + echo -n $MSG + /usr/bin/lzma -cq9 $SRC > $DIR/$TAR + ;; + *) + hlp;; + esac +} + +tdir () { # Determin target directory for archive + if [ -d $1 ]; then + if [ "$1" == "." ]; then + DIR="$PWD" + else + DIR="$1" + fi + else + DIR="$PWD" + fi +} + +case "$@" in + *--help*) hlp;; +esac + +TAR="`basename $1`" +tdir `dirname $1` && shift + +if [ $# -gt 1 ]; then # If more than one source + SRCD="$@" # all sources to $SRCD + i=0 # counter + while [ "$1" ]; do + if [ $i -eq 0 ]; then # only if the first source + SRC="$1" && shift + if [ ! -r "$SRC" ]; then + echo "Location [$SRC] does not exist or is unreadable." + exit 1 + fi + ((i++)) # increment + else # if sources after the first + if [ ! -r "$1" ]; then + echo "Location [$1] does not exist or is unreadable." + exit 1 + fi + SRC="$SRC $1" && shift # copy current $SRC and append next source + fi + done + tarfunc # do the work +else # else if there is only one source + SRC="$1" + SRCD="$SRC" # copy $SRC + if [ ! -r "$SRC" ]; then + echo "Location [$SRC] does not exist or is unreadable."; exit 1 + elif [ -d "$SRC" ]; then # if source is a directory + cd `dirname $SRC` # goto the directory one up from $SRC + SRC="`basename $SRC`/" # change $SRC for correct directory packing structure + fi + tarfunc # do the work +fi + +if [ $? -ne 0 ]; then # if last command failed + cd $DIR + rm -f $TAR && echo "failure detected, archive deleted." + exit 1 +else + echo "success!"; exit 0 +fi diff --git a/bashrun.sh b/bashrun.sh deleted file mode 120000 index b37f7f0..0000000 --- a/bashrun.sh +++ /dev/null @@ -1 +0,0 @@ -bashrun \ No newline at end of file diff --git a/bashrun.sh b/bashrun.sh new file mode 100755 index 0000000..b571a52 --- /dev/null +++ b/bashrun.sh @@ -0,0 +1,106 @@ +#!/bin/bash +# +# usage: bashrun [geometry] (default: 40x1) +# +# NOTE: commands entered will have an '&' appended before being run, +# so don't append it yourself, it will fail silently. +# +# rcfile: $HOME/.bashrunrc +# +# --------------------------------------------------------------------- + +GEOM=${1:-40x1} + +# create .bashrunrc unless present +BASHRUNRC=$HOME/.bashrunrc +if [ ! -f $BASHRUNRC ]; then +( +cat <<'EOF' +# which X terminal to use: +# (xterm|rxvt|urxvt|mrxvt|aterm|mlterm) +XTERM=urxvtc + +# history file and options: +HISTFILE=$HOME/.bashrun_history +HISTCONTROL=ignoredups:erasedups + +# bind to menu-complete. Makes cycle through completions on +# the current line instead of paging all possible completions +bind '"\t": menu-complete' + +# bind to send ^D +# ( is the default quit-chain-key in emacs, ratpoison, etc) +bind '"\C-g"':"\"\x04\"" + +# set a simple prompt +PS1=">" + +# ***DO NOT EDIT BEYOND THIS LINE*** +# +# bind ENTER to add ' &' to command +bind '"\x0d"':"\" &\n\"" +EOF +) > $BASHRUNRC +fi + +. $BASHRUNRC + +error() { + if [ `which zenity` ]; then + zenity --title bashrun --error --text "$@" + elif [ `which kdialog` ]; then + kdialog --title bashrun --error "$@" + elif [ `which xmessage` ]; then + xmessage "$@" + fi + echo -en "\007" + echo $@ +} + +# run bash terminal +if [ "$XTERM" = "xterm" ]; then + $XTERM -name 'bashrun' \ + -title 'bashrun' \ + -geometry $GEOM \ + -e "/bin/bash --rcfile $BASHRUNRC -i -t" + +elif [[ "$XTERM" = "aterm" || "$XTERM" = "mlterm" ]]; then + $XTERM -name 'bashrun' \ + -title 'bashrun' \ + -geometry $GEOM +sb \ + -e /bin/bash --rcfile $BASHRUNRC -i -t + +elif [[ "$XTERM" = "urxvt" || "$XTERM" = "rxvt" ]] || [ "$XTERM" = "urxvtc" ]; then + $XTERM -name 'bashrun' \ + -title 'bashrun' \ + -geometry $GEOM \ + -e sh -c "/bin/bash --rcfile $HOME/.bashrunrc -i -t" + + +elif [ "$XTERM" = "mrxvt" ]; then + $XTERM -name 'bashrun' \ + -title 'bashrun' \ + -geometry $GEOM +sb -ht \ + -e sh -c "/bin/bash --rcfile $BASHRUNRC -i -t" +else + error "$XTERM is not supported. Please check $BASHRUNRC" + exit 1 +fi + +# history cleanup... +# remove trailing whitespace and '&' from the last history line +tac $HISTFILE | sed "1s/\&//;s/ *$//" | tac > $HISTFILE + +# HISTCONTROL won't work on its own because bash applies the +# 'ignoredups' and 'erasedups' rules to 'command &'. + +# apply 'ignoredups' if set +if [[ "$HISTCONTROL" =~ "ignoredups" || "$HISTCONTROL" =~ "ignoreboth" ]]; then + uniq $HISTFILE $HISTFILE.tmp + mv $HISTFILE.tmp $HISTFILE +fi + +# apply 'erasedups' if set +if [[ "$HISTCONTROL" =~ "erasedups" ]]; then + tac $HISTFILE | gawk '!x[$0]++' - | tac > $HISTFILE +fi diff --git a/drop.sh b/drop.sh index 848cd31..c37106a 100755 --- a/drop.sh +++ b/drop.sh @@ -1,5 +1,11 @@ -#!/bin/sh -if echo "$1" | grep ".torrent$" > /dev/null -then - mv "$1" /mnt/mistral/flo/torrent/watch -fi +#!/bin/bash +for file; do + case $(file -b --mime-type "$file") in + application/x-bittorrent) + mv "$file" /mnt/mistral/flo/torrent/watch + ;; + *) + # nothing + ;; + esac +done diff --git a/fix_ntfs.sh b/fix_ntfs.sh deleted file mode 100755 index f386717..0000000 --- a/fix_ntfs.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -gksu -S true - -sudo -n true &> /dev/null -exitcode=$? -if [ $exitcode -gt 0 ]; then - exit -fi - -DRIVE=$(dmesg | grep -o "sd.: sd.." | grep "sd.." | tail -n 1) -DEVICE=$(echo $DRIVE | grep -o "sd.") - -sudo fdisk -l $DEVICE | grep "$DRIVE.*NTFS" -exitcode=$? - -if [ $exitcode -eq 0 ]; then - xterm -geometry "40x10" -title "Fixing..." -e "sudo ntfsfix $DRIVE && sleep 2" -fi diff --git a/gvim b/gvim new file mode 100755 index 0000000..852827e --- /dev/null +++ b/gvim @@ -0,0 +1,2 @@ +#!/bin/sh +urxvtc -e vim "$@" diff --git a/python/openbox-shutdown.conf b/python/openbox-shutdown.conf new file mode 100644 index 0000000..7448640 --- /dev/null +++ b/python/openbox-shutdown.conf @@ -0,0 +1,40 @@ +# configuration for openbox-shutdown +# +# buttons are shown in the order they are listed in this file +# +# each section contains the following values: +# command - command to execute when button is pressed +# can be used several times to execute more commands +# commands are executed in the order they are listed in this +# file +# image - location of the image for the button +# absolute path is recommended +# set to None if no image should be shown +# info_text - small text to show in the footer +# set to None if not requested +# label - label for the button +# uses mnemics +# set to None to disable + +[reboot] +command = openbox --exit +command = sudo shutdown -r now +image = /usr/share/icons/hydroxygen/72x72/apps/gnome-session-reboot.png +info_text = Reboot +#label = _Neu starten +label = None + +[shutdown] +command = openbox --exit +command = sudo shutdown -h now +image = /usr/share/icons/hydroxygen/72x72/apps/gnome-session-halt.png +info_text = Halt +#label = _Herunterfahren +label = None + +[suspend] +command = sudo pm-suspend +image = /usr/share/icons/hydroxygen/72x72/apps/gnome-session-suspend.png +info_text = Suspend2Ram +#label = _Suspend +label = None diff --git a/python/openbox-shutdown.py b/python/openbox-shutdown.py new file mode 100755 index 0000000..cfdd67b --- /dev/null +++ b/python/openbox-shutdown.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python +""" + +shutdown script for Openbox with configurable buttons and actions +needs pygtk for gui +""" + +# standard stuff +import os +import re +import sys + +# gui modules +try: + import gtk + import pygtk +except ImportError: + sys.stderr.write('pygtk is needed for using this script') + sys.exit(1) + +if sys.version_info < (2, 5, 0): + sys.stderr.write('Python 2.5.0 or higher is needed') + sys.exit(1) + +# a simple parser for the configuration +class ConfigParser(dict): + """ + ConfigParser(file) -> dict + + reads file and creates dict object containing corresponding + configuration + """ + + def __init__(self, filename): + self._section_match_regexp = re.compile(r'\[(\w+)\]') + self._key_val_match_regexp = re.compile(r'\s*=\s*') + self._comment_remov_regexp = re.compile(r'#.*') + try: + config_handle = open(filename, 'r') + except IOError: + sys.stderr.write('Could not read %s. Aborting ...\n' % filename) + sys.exit(1) + linecount = 0 + for line in config_handle.readlines(): + linecount += 1 + line = self._comment_remov_regexp.sub('', line.strip()) + if len(line) == 0: + continue + if self._section_match_regexp.match(line): + section = self._section_match_regexp.match(line).groups()[0] + self[section] = {} + continue + try: + (key, value) = self._key_val_match_regexp.split(line) + except ValueError: + sys.stderr.write('Syntax error in line %d of %s.' % (linecount, + filename)) + sys.exit(1) + if key == 'command' and not key in self[section]: + self[section][key] = [value] + continue + if key in self[section] and key == 'command': + self[section][key].append(value) + else: + self[section][key] = value + + def check(self): + """ + checks if configuration is complete + """ + for section in self: + for needed_key in ['command', 'image', 'info_text', 'label']: + if not needed_key in self[section]: + sys.stderr.write('Missing option %s in %s.' % (needed_key, section)) + sys.exit(1) + +# the main class for this script +class OpenBoxShutdown(object): + """ + main class for this script + + reads configuration and displays buttons as requested + + on click, the specified actions are made + """ + + def __init__(self, basedir): + self._config = ConfigParser(os.path.join(basedir, 'openbox-shutdown.conf')) + self._config.check() + # button box on top for the action buttons + button_box = gtk.HButtonBox() + for key in self._config: + button_box.pack_start(self._create_button(key, + self._config[key]['label'], + self._config[key]['info_text'], + self._config[key]['image'])) + button_box.show() + # create cancel button + cancel_button = gtk.Button(stock = gtk.STOCK_CANCEL) + cancel_button.connect('clicked', self._click_callback, 'cancel') + cancel_button.show() + # label widget for small hints + self._label = gtk.Label() + self._label.show() + # frame widget to contain label + frame = gtk.Frame() + frame.set_shadow_type(gtk.SHADOW_NONE) + frame.add(self._label) + frame.show() + # area containing hints and cancel button + action_area = gtk.HBox() + action_area.pack_end(cancel_button, expand=False) + action_area.pack_end(frame) + action_area.show() + # box containing button box and action area + vbox = gtk.VBox() + vbox.pack_start(button_box) + vbox.pack_end(action_area) + vbox.show() + # the main window with all widgets + # always on top and on all desktops + window = gtk.Window() + window.set_position('center') + window.set_decorated(False) + window.stick() + window.set_keep_above(True) + window.set_skip_pager_hint(True) + window.set_skip_taskbar_hint(True) + window.add(vbox) + window.show() + # give control to gtk + gtk.main() + + def _click_callback(self, event, action): + """ + _click_callback(event, action) + + executes commands on button click + """ + gtk.main_quit() + if action == 'cancel': + sys.exit(0) + for command in self._config[action]['command']: + os.system(command) + + def _create_button(self, key, label_text, info_text, image_file): + """ + _create_button(key, label, info, image) -> button + + creates a button widget with key (used for handling actions), + a label for the button, a small text as hint and an image + """ + button = gtk.Button() + if label_text != 'None': + button.set_label(label_text) + if image_file != 'None': + button.set_image(self._create_image(image_file)) + button.set_image_position(gtk.POS_TOP) + button.connect('clicked', self._click_callback, key) + button.connect('leave', lambda event: self._label.set_text('')) + button.connect('enter', self._set_label, info_text) + button.show() + return button + + def _create_image(self, image_file): + """ + _create_image(image) -> image + + creates an image widget from the specified file + """ + image = gtk.Image() + image.set_from_file(image_file) + return image + + def _set_label(self, event, info_text): + """ + _set_label(event, info_text) + + set label on entering the widget + """ + if info_text != 'None': + self._label.set_markup('%s' % info_text) + +# start the script if called standalone +if __name__ == '__main__': + # get the real path for the configuration file + conf_path = os.path.realpath(os.path.dirname(os.readlink(__file__))) \ + if os.path.islink(__file__) \ + else os.path.realpath(os.path.dirname(__file__)) + shutdown = OpenBoxShutdown(conf_path) diff --git a/python/shutdown.py b/python/shutdown.py index 5f350bb..2888394 100755 --- a/python/shutdown.py +++ b/python/shutdown.py @@ -1,8 +1,8 @@ #!/usr/bin/env python #----------------------------------------------------# # File: shutdown.py -# Version: 0.1 -# Date: 2009-01-17 +# Version: 0.1.1 +# Date: 2009-02-15 # Author: Florian "Bluewind" Pritz # Display a small shutdown Dialog # Please change the image paths @@ -24,27 +24,27 @@ import gtk import os def create_bbox(title=None, spacing=0, layout=gtk.BUTTONBOX_SPREAD): - bbox = gtk.VButtonBox() + bbox = gtk.VButtonBox() - bbox.set_spacing(spacing) + bbox.set_spacing(spacing) - buttons = (('Cancel', 'gtk-cancel'), - ('Suspend', 'gnome-session-suspend'), - ('Reboot', 'gnome-session-reboot'), - ('Halt', 'gnome-session-halt') - ) - for text, stock_id in buttons: - image = gtk.Image() - image.set_from_stock(stock_id, gtk.ICON_SIZE_LARGE_TOOLBAR) - b = gtk.Button(text) - b.set_image(image) - b.set_data("user_data", text) - b.connect("clicked", click, b) - b.set_size_request(100, -1) - b.set_alignment(0,1) - bbox.add(b) + buttons = (('Cancel', 'gtk-cancel'), + ('Suspend', 'gnome-session-suspend'), + ('Reboot', 'gnome-session-reboot'), + ('Halt', 'gnome-session-halt') + ) + for text, stock_id in buttons: + image = gtk.Image() + image.set_from_stock(stock_id, gtk.ICON_SIZE_LARGE_TOOLBAR) + b = gtk.Button(text) + b.set_image(image) + b.set_data("user_data", text) + b.connect("clicked", click, b) + b.set_size_request(100, -1) + b.set_alignment(0,1) + bbox.add(b) - return bbox + return bbox def click(self, button): ret = button.get_data("user_data") @@ -60,47 +60,42 @@ def click(self, button): os.system("sudo shutdown -h now") class ButtonBox(gtk.Window): - def __init__(self, parent=None): - # Create the toplevel window - gtk.Window.__init__(self) - try: - self.set_screen(parent.get_screen()) - except AttributeError: - self.connect('destroy', lambda *w: gtk.main_quit()) + def __init__(self, parent=None): + # Create the toplevel window + gtk.Window.__init__(self) + try: + self.set_screen(parent.get_screen()) + except AttributeError: + self.connect('destroy', lambda *w: gtk.main_quit()) - self.set_title("Shutdown") - self.set_decorated(False) - self.set_position(gtk.WIN_POS_CENTER) + self.set_title("Shutdown") + #self.set_decorated(False) + self.set_position(gtk.WIN_POS_CENTER) - hbox = gtk.HBox() - hbox.set_border_width(10) - - self.add(hbox) - hbox.pack_start(create_bbox(None, 8, gtk.BUTTONBOX_START), - padding=0) + hbox = gtk.HBox() + hbox.set_border_width(10) - self.show_all() + self.add(hbox) + hbox.pack_start(create_bbox(None, 8, gtk.BUTTONBOX_START), + padding=0) -def main(): - ButtonBox() - gtk.main() + self.show_all() def register_iconsets(icon_info): - iconfactory = gtk.IconFactory() - stock_ids = gtk.stock_list_ids() - for stock_id, file in icon_info: - # only load image files when our stock_id is not present - if stock_id not in stock_ids: - pixbuf = gtk.gdk.pixbuf_new_from_file(file) - iconset = gtk.IconSet(pixbuf) - iconfactory.add(stock_id, iconset) - iconfactory.add_default() + iconfactory = gtk.IconFactory() + stock_ids = gtk.stock_list_ids() + for stock_id, file in icon_info: + # only load image files when our stock_id is not present + if stock_id not in stock_ids: + pixbuf = gtk.gdk.pixbuf_new_from_file(file) + iconset = gtk.IconSet(pixbuf) + iconfactory.add(stock_id, iconset) + iconfactory.add_default() register_iconsets([('gnome-session-suspend', '/usr/share/icons/hydroxygen/128x128/apps/gnome-session-suspend.png'), ('gnome-session-halt', '/usr/share/icons/hydroxygen/128x128/apps/gnome-session-halt.png'), ('gnome-session-reboot', '/usr/share/icons/hydroxygen/128x128/apps/gnome-session-reboot.png') ]) - -if __name__ == '__main__': - main() +ButtonBox() +gtk.main() diff --git a/screen.sh b/screen.sh index ee679a2..ed5c3f2 100755 --- a/screen.sh +++ b/screen.sh @@ -2,7 +2,6 @@ #----------------------------------------------------# # File: ~/bin/screen.sh # # Version: 0.1.2 # -# Date: 2008-10-16 # # Author: Florian "Bluewind" Pritz # # start screen with a combined config file # #----------------------------------------------------# diff --git a/set-background.sh b/set-background.sh index bce00f5..8d20468 100755 --- a/set-background.sh +++ b/set-background.sh @@ -2,7 +2,6 @@ #---------------------------------------------------- # File: ~/bin/set-background.sh # Version: 0.1.2 -# Date: 2009-01-18 # Author: Florian "Bluewind" Pritz # start screen with a combined config file #---------------------------------------------------- diff --git a/ssh-mount.sh b/ssh-mount.sh index c69783e..4c8cb30 100755 --- a/ssh-mount.sh +++ b/ssh-mount.sh @@ -21,7 +21,7 @@ else df) DIR="/mnt/df_ssh" mkdir -p "${DIR}" - sshfs 105012-ftp@seitznet2.at: -o reconnect -p 22 "${DIR}" && + sshfs 105012-ftp@seitznet2.at: -p 22 "${DIR}" && echo -e "${GREEN}DF mounted.$NC" ;; wf) diff --git a/upload-image.sh b/upload-image.sh new file mode 100644 index 0000000..5db598b --- /dev/null +++ b/upload-image.sh @@ -0,0 +1,22 @@ +#/bin/bash +#---------------------------------------------------- +# File: upload-image.sh +# Version: 0.1.1 +# Author: Florian "Bluewind" Pritz +# Upload image to imagebanana and output url +#---------------------------------------------------- +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +curl -F img="@$1" -F "send=Hochladen" -F 'resize=320x240' -H "Expect: " www.imagebanana.com -L | ack -o -n '(http.*?\/view\/.*?\..{3})' | tail -n 1 diff --git a/xup.sh b/xup.sh index c548ad4..b30c11c 100755 --- a/xup.sh +++ b/xup.sh @@ -2,7 +2,6 @@ #----------------------------------------------------# # File: xup.sh # Version: 0.1.4 -# Date: 2009-01-14 # Author: Florian "Bluewind" Pritz # Upload file to XUP, copy URL to clipboard and # save to historyfile -- cgit v1.2.3-24-g4f1b