/home/drscream

  • home
  • blog
  • gallery
  • about
  • my bashrc ;)

    Everybody who loves bash are welcome to use my bashrc :)

    #--------------------------------------------------------------------
    # $Id: bashrc,v 1.7 2007/10/08 21:33:00 drscream Exp $
    # Copyright 2007 Frubar Network (drscream@frubar.net)
    #--------------------------------------------------------------------
    
    ##########################################################################
    # Test for an interactive shell.
    if [[ $- != *i* ]] ; then
        # Shell is non-interactive.  Be done now!
        return
    fi
    ##########################################################################
    
    # functions
    function sshs {
        ssh $@ -t screen
    }
    function root {
        sudo su -c \
        '/bin/bash --rcfile /home/${SUDO_USER}/.bashrc'
    }
    
    function runfortune {
        if [[ $(which fortune 2>/dev/null) ]]; then
            echo; fortune -s; echo
        fi
    }
    
    # aliases
    alias ls='ls --color=auto'
    alias ll='ls -l'
    alias la='ls -la'
    alias grep='grep --color=auto'
    alias kwrite='kwrite 2>/dev/null &'
    alias cal='cal -m'
    alias screen='screen -RD'
    #alias ssh='sshs'
    
    # dir colors
    if [[ -f ${HOME}/.dir_colors ]]; then
        eval $(dircolors -b ${HOME}/.dir_colors)
    elif [[ -f /etc/DIR_COLORS ]]; then
        eval $(dircolors -b /etc/DIR_COLORS)
    fi
    
    # change the window title of X terminals
    case ${TERM} in
        xterm*|rxvt*|Eterm|aterm|kterm|gnome)
            PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
            ;;
        screen)
            PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
            ;;
    esac
    
    # set default PS1 PS2
    if [[ ${EUID} == 0 ]] ; then
        PS1='\[\033[0;31m\][\u@\h]\[\033[0m\]:\[\033[0;34m\]\w #\[\033[0m\] '
        PS2='root %> '
    else
        PS1='\[\033[0;33m\][\u@\h]\[\033[0m\] \[\033[0;32m\]\w\[\033[0m\]\n % '
        PS2='%> '
        runfortune
    fi
    
    # nice env variables
    VISUAL=/usr/bin/vim
    EDITOR=${VISUAL}
    PAGER=/usr/bin/less
    LESSSECURE=1
    LANG=en_US.utf8
    LC_ALL=en_US.utf8
    SSL_CERT_DIR=${HOME}/.certs/
    PATH=${HOME}/.bin:$PATH
    HOST=$(hostname | sed 's/[.].*//g')
    
    export PROMPT_COMMAND PS1 PS2 VISUAL EDITOR PAGER LANG LC_ALL PATH LESSSECURE SSL_CERT_DIR
    
    # keychain check and use
    if [[ -x $(which keychain 2>/dev/null) ]]; then
        if [[ -f ${HOME}/.ssh/id_rsa ]]; then
            keychain --host ${HOST} -q ~/.ssh/id_rsa
            . ~/.keychain/${HOST}-sh
        fi
    fi
    
    # load special file if exists
    if [[ -f ${HOME}/.doc.env/etc/bash/${HOST}.bashrc ]]; then
        source ${HOME}/.doc.env/etc/bash/${HOST}.bashrc
    fi
    

    download bashrc

    Posted

    November 17, 2007

    Tags

    bash, bashrc, bsd, linux

  • /etc/inittab erweitern

    Ich hab mir gedacht eigentlich ist es doch toll ein paar mehr Statusinformationen in den vielen ttys wo man hat anzuzeigen. Also habe ich meine /etc/inittab etwas erweitert und zwar um folgende Zeilen:

    # show a clock
    9:2345:respawn:/usr/bin/nice -n 19 -- /usr/bin/klock >&/dev/tty9 </dev/tty9
    
    # show the system load
    10:2345:respawn:/usr/bin/nice -n 19 -- /usr/bin/tload -d 5 /dev/tty10
    
    # show /var/log/allmessages with less
    11:2345:respawn:/usr/bin/nice -n 19 -- /usr/bin/env LESSSECURE=1 /usr/bin/less -iMRS +F /var/log/messages >&/dev/tty11 </dev/tty11
    
    # show htop
    12:2345:respawn:/usr/bin/env HOME=/root /usr/bin/htop >&/dev/tty12 </dev/tty12

    inittab

    Posted

    November 11, 2007

    Tags

    bash, linux

  • CenterIM Umlautproblematik

    Ich verwend jetzt schon seit einigen Monate CenterIM, jedoch hatte ich immer das Problem das es mir Sonderzeichen (wie ö/ü/ä/ß) nicht angezeigt oder sogar ganze Woerter verschluckt wurden.
    Zum Beispiel:
    ‘Österreich’ => ‘terreich’

    Das erleichtert natuerlich nicht gerade das Lesen von Chatnachrichten, nun das Problem laesst sich jedoch recht einfach loesen.
    Man hat bei der locale z.B. UTF-8 Support eingestellt (wie ich auch), leider sendet ICQ aber ISO-Bullshit.

    Nun erst einmal rausfinden welche locale man eingestellt hat:

     % locale
    LANG=en_US.utf8
    LC_ALL=en_US.utf8
    

    Nun wechselt man in die CenterIM config options dort gibt es die Einstellmoeglichkeiten Remote charset und Local charset, tja und die stellt man jetzt einfach nach seinen wuenschen ein. Bei mir waere das:

    • Remote charset : ISO-8859-15
    • Local charset : UTF-8

    Tada und schon funktionieren bei mir die Umlaute :-)

    Posted

    November 3, 2007

    Tags

    bash, bsd, centerim, linux

  • Remove unwanted spaces

    If you have a document thats full of spaces or empty lines, edit it with Vim:

    Eliminate empty lines:

    :v/\S/d

    Eliminate spaces at the beginning of each line:

    :%s/^\s\+//

    Eliminate spaces at the end of the each line:

    :%s/\s\+$//

    Posted

    October 30, 2007

    Tags

    bash, bsd, linux, vim

  • Frucln - a frubar console (sau,frupic) client

    Hi there,

    i have written a small client for sau and frupic, it’s only a small bash script. Have a look at it:

    
    #!/bin/bash
    #--------------------------------------------------------------------
    # $Id: frucln,v 1.7 2007/10/08 18:01:09 drscream Exp $
    # Copyright 2007 Frubar Network (drscream@frubar.net)
    #--------------------------------------------------------------------
    
    # FUNCTIONS
    function pause() {
            i=0;
            echo -n "- pause: "
    
            while [ $i -le $count ]; do
                    echo -n "."
                    sleep 1
                    i=$[$i+1]
            done
            echo
    }
    
    # MAIN
    echo "[ frucln - creative coding ]"
    
    # $1: sau
    #     frupic
    case $1 in
            "sau")
                    if [[ $2 > 0 ]]; then
                        count=$2
                        pause $count
                    fi
    
                    osys=$(uname)
                    if [[ ${osys} == "Linux" ]]; then
                            $(import -window root -pause 0 -quality 100 /tmp/sau.tmp.png)
                    elif [[ ${osys} == "Darwin"  ]]; then
                            $(screencapture -m /tmp/sau.tmp.png)
                    else
                            echo "- Error: Operating System not found"
                            exit
                    fi
    
                    if [[ -f /tmp/sau.tmp.png ]]; then
                            id=$(curl -s -F userfile=@/tmp/sau.tmp.png -F "shooter=$(whoami)" "http://sau.frubar.net/")
                            if [[ $id > 0 ]]; then
                                    echo "- Successfull: SaU"
                                    echo "  http://sau.frubar.net/${id}"
                            else
                                    echo "- Error: Upload failed"
                            fi
                            $(rm /tmp/sau.tmp.png)
                    else
                            echo "- Error: SaU file doesn't exists"
                    fi
            ;;
            "frupic")
                    all=$(echo $2 | grep \*)
                    if [[ $all ]]; then
                            for f in $all; do
                                    id=$(curl -s -F userfile=@$f -F "shooter=$(whoami)" "http://frupic.frubar.net/")
                        if [[ $id > 0 ]]; then
                            echo "- Successfull: frupic"
                        echo "  http://frupic.frubar.net/${id}"
                        else
                        echo "- Error: Upload failed ($f)"
                        fi
                            done
                            exit
                    elif [[ $2 ]]; then
                            id=$(curl -s -F userfile=@$2 -F "shooter=$(whoami)" "http://frupic.frubar.net/")
                if [[ $id < 0 ]]; then
                    echo "- Successfull: frupic"
                    echo "  http://frupic.frubar.net/${id}"
                else
                    echo "- Error: Upload failed"
                fi
                            exit
                    else
                            echo "- Error: No Parameter given"
                    fi
            ;;
            *)
                    echo "frucln:"
                    echo " - use: frucln "
            ;;
    esac
    
    echo $args
    #curl -s -F userfile=@CIMG0885.JPG -F "shooter=`whoami`" "http://frupic.frubar.net/"
    

    frucln download

    Posted

    October 28, 2007

    Tags

    bash, frubar, frucln, linux, macosx

  • My screenrc :)

    I love screen, so here is my ~/.screenrc file:

    #--------------------------------------------------------------------
    # $Id: screenrc,v 1.7 2007/10/08 19:01:09 drscream Exp $
    # Copyright 2007 Frubar Network (drscream@frubar.net)
    #--------------------------------------------------------------------
    
    # DEFAULT
    shell                   bash
    autodetach              on
    defutf8         on
    deflogin        off
    startup_message off
    nethack                 on
    
    activity        "activity in %n (%t)"
    bell_msg        "bell in %n (%t)"
    defhstatus      "screen: ^En (^Et)"
    shelltitle      "$ |sh:"
    
    vbell           on
    vbell_msg       "WHAT ??!!"
    vbellwait       1
    
    msgminwait      1
    msgwait         3
    
    #hardcopy_append on
    #hardcopydir ~/.screen
    
    windowlist title        " Num%+3=| Fl%+3=| Name"
    windowlist string       " %3n%+3=| %f%+3=| %t"
    
    zombie          ^D^C
    escape          ^Aa
    termcapinfo     xterm|xterm-256color|xterms|xs|rxvt ti@:te@
    
    #idle 600 blanker
    #blankerprg nice -n 19 cmatrix -abu9
    
    # BINDINGS
    bind ^r source "${HOME}/.screenrc"
    bind ^e escape ^Xx
    bind ^y escape ^Aa
    bind ^x lockscreen
    bind o  copy
    bind p  paste .
    bind .  number
    bind l  lastmsg
    bind w  windowlist -b
    bind r  resize
    bind s  select
    bind >  split
    bind <  remove
    bind ^f focus down
    bind =  resize =
    bind +  resize +5
    bind -  resize -5
    bind ~  resize max
    
    # STATUSPANEL
    hardstatus alwayslastline
    hardstatus string '%{= kY}[ %{R}%H %{Y}][ %{g}load[%l] %{Y}][ %{B}%d/%m/%Y %c %{Y}][ %{r}%=%?%-w%?(%n%f %t)%?%+w%? %{Y}]'

    my screenrc file

    Posted

    October 8, 2007

    Tags

    bash, bsd, linux, screen

    5 comments

  • Kleines einfaches Backup (Bash-)Script

    Es gibt sicher einiges effektivere und bessere Scripte um ein System und MySQL Backup zu machen. Das ist jetzt auch nur die erste Version des ganzen und evtl. kann es jemand gebrauchen :)

    #####################################################################
    # srv-backup.sh - backup the system and the databases               #
    # @author:  drscream@cyber-tec.org                                  #
    # @version: Thu Oct  4 11:35:39 CEST 2007                           #
    #####################################################################
    
    # CONFIGURATION
    #####################################################################
    # crontab example:
    # 21 4    * * * /opt/av-srv/av-srv-backup.sh mysql
    #  2 3 1,15 * * /opt/av-srv/av-srv-backup.sh system
    #  2 4    * * * /opt/av-srv/av-srv-backup.sh webroot
    #  3 6    * * * /opt/av-srv/av-srv-backup.sh pgsql
    
    ## log information ##################################################
    log_file="/local/backup/backup.log"
    datetime=$(date +%Y%m%d-%H%M%S)
    fqdn=$(hostname -f)
    
    ## select what to backup ############################################
    # => 0/1:          deactivate or activate the backup
    # => /srv/xxx:     path to save the backup
    # => asdf.tar.bz2: file to save the backup
    # => sysdir.txt:   text file with the directories to backup
    # => rsync:        rsync is set the file will rsynced to the backupsrv
    system=(1 '/local/backup/system' 'system.$fqdn.$datetime.tar.gz' './systemdir.txt' 'rsync')
    
    # => 0/1:          deactivate or activate the backup
    # => /srv/xxx:     path to save the backup
    # => asdf.tar.bz2: file to save the backup
    # => /web:         directory to backup
    # => rsync:        rsync is set the file will rsynced to the backupsrv
    webroot=(1 '/local/backup/webroot' 'web.$fqdn.$datetime.tar.gz' '/web' 'rsync')
    
    # => 0/1:          deactivate or activate the backup
    # => /srv/xxx:     path to save the backup
    # => user:         sql user (root)
    # => password:     sql password
    # => rsync:        rsync is set the file will rsynced to the backupsrv
    mysql=(1 '/local/backup/mysql' 'root' 'qwe123' 'rsync')
    
    # => 0/1:          deactivate or activate the backup
    # => /srv/xxx:     path to save the backup
    # => asdf.tar.bz2: file to save the backup
    # => user:         sql user (root)
    # => rsync:        rsync is set the file will rsynced to the backupsrv
    pgsql=(0 '/local/backup/pgsql' 'pgsql.$fqdn.$datetime.sql.gz' 'postgres' 'rsync')
    
    # => 0/1:                       rsync to the specified server
    # => username:      username for rsync
    # => hostname:      specified backup server host
    # => /path:                     path to save the backup ($fqdn is added)
    rsync=(1 'username' 'hostname' '/backup')
    rsync_args="--archive"
    
    ## delete the files after  days #################################
    delete_files=20
    
    ## global variables #################################################
    export LANG="en_US.utf8"
    PARAM=$1
    
    # FUNCTIONS
    #####################################################################
    function delete() {
            find $1 -type f -mtime +$delete_files | xargs rm 2>/dev/null
    }
    
    function log() {
            echo $1 >> $log_file
    }
    
    function backuprsync() {
            if [[ ${rsync[0]} == 1 && ${1} == "rsync" ]]; then
            log "($datetime) rsync to server ---------------------------"
    
                    rsync ${rsync_args} $2 ${rsync[1]}@${rsync[2]}:${rsync[3]}/${fqdn} >> $log_file
    
                    log "end rsync to server -----------------------------------"
            fi
    }
    
    # MAIN
    #####################################################################
    
    ## system ###########################################################
    if [[ ${system[0]} == 1 && ${PARAM} == "system" ]]; then
            # cleanup system backup
            delete ${system[1]}
    
            # start system backup
            log "($datetime) systembackup: ---------------------------------"
            log "backup following files:"
    
            dir_backup=$(cat ${system[3]})
            log "$dir_backup"
    
            # compress the files
            cd /
            tar cvpzf "${system[1]}/${system[2]}" $dir_backup
    
            # rsync if it is set
            backuprsync ${system[4]} ${system[1]}/${system[2]}
    
            log "end systembackup ------------------------------------------"
    fi
    
    ## webroot ##########################################################
    if [[ ${webroot[0]} == 1 && ${PARAM} == "webroot" ]]; then
        # cleanup webroot backup
        delete ${webroot[1]}
    
        # start webroot backup
        log "($datetime) webrootbackup: --------------------------------"
        log "backup following dir:"
    
        dir_backup=$(ls -la ${webroot[3]})
        log "$dir_backup"
    
        # compress the files
        cd ${webroot[3]}
        tar cvpzf "${webroot[1]}/${webroot[2]}" *
    
        # rsync if it is set
            backuprsync ${webroot[4]} ${webroot[1]}/${webroot[2]}
    
        log "end webrootbackup -----------------------------------------"
    fi
    
    ## mysql ############################################################
    if [[ ${mysql[0]} == 1 && ${PARAM} == "mysql" ]]; then
            # cleanup mysql backup
            delete ${mysql[1]}
    
            # start mysql backup
            log "($datetime) mysqlbackup -----------------------------------"
    
            mysqlshow -u ${mysql[2]} --password=${mysql[3]} |  tr -d '|' |  tr -d '+' |  tr -d ' ' | tr -d '-' > /tmp/sql-backup-list.tmp
    
            list=/tmp/sql-backup-list.tmp
            ig=3
            xr_lines=$(wc -l $list | awk '{ print $1 }')
            while [ "$ig" -le $xr_lines ];  do
                    ig=$(expr $ig + 1)
                    item=$(awk "NR == $ig {print}" $list)
    
                    mysqldump --add-drop-table --allow-keywords -q -a -c -u ${mysql[2]} --password=${mysql[3]} $item | gzip > ${mysql[1]}/$item.sql.gz
    
                    echo $item >> $dir_backup
            done
    
            # Remove a temp file
            rm -f /tmp/sql-backup-list.tmp
    
        # rsync if it is set
            backuprsync ${mysql[4]} ${mysql[1]}
    
            log "end mysqlbackup -------------------------------------------"
    fi
    
    ## pgsql ############################################################
    if [[ ${pgsql[0]} == 1 && ${PARAM} == "pgsql" ]]; then
            # cleanup pgsql backup
            delete ${pgsql[1]}
    
            # start pgsql backup
            log "($datetime) pgsqlbackup -----------------------------------"
    
            pg_dumpall -U${pgsql[3]} | gzip > "${pgsql[1]}/${pgsql[2]}.gz"
    
        # rsync if it is set
            backuprsync ${pgsql[4]} ${pgsql[1]}
    
            log "end pgsqlbackup -------------------------------------------"
    fi

    Server Backup Script Download

    Posted

    October 6, 2007

    Tags

    Backup, bash, bsd, linux, sql

  • Kontact / KMail und der GnuPG Cache

    Ich hatte unter KDE – Kontact / Kmail zwar (fast) nie Probleme mit meinem GnuPG, jedoch hat es mich doch immer etwas gestoert das das Passphrases caching nie richtig funktioniert hat.
    Wenn man KDE allg. als Desktop Environment verwendet ist das ganze ganz einfach. Man muss einfach nur den gpg-agent vor dem eigentlichen KDE laden. Hierzu geht man wie folgt vor:

    Wichtige Abhaenigkeiten sind hierbei:

    • kmail :P
    • gnupg
    • gpg-agent
    • pinentry
    1. Verzeichnis erstellen ~/.kde/env
    2. Datei in diesem Verzeichnis erstellen z.b.: gpg-agent.sh (soviel ich weis ist das .sh noetig da KDE sonst diese Script beim starten nicht ausfuehrt).
    3. In diese Datei schreibt man dann:
      eval `gpg-agent --daemon`

    4. Nicht vergessen die Datei ausfuehrbar zu machen:
      chmod +x gpg-agent.sh

    Nun sollte der GnuPG Agent schoneinmal schoen funktionieren. Nun stellt man noch in der Datei ~/.gnupg/gpg-agent.conf seinen gewuenschten Cache Wert ein. Einfach die Zeile ‘default-cache-ttl XXXX’ hinzufuegen, wobei XXXX der Cache Zeit in Sekunden ist.

    Eine alternative moeglichkeit das ganze zu Cachen bietet keychain (Keychain Homepage), jedoch hab ich das noch nicht getestet. Falls jemand mal Lust und Zeit hat dies zu tun kann mir ja das Ergebnis mitteilen.

    Posted

    June 25, 2006

    Tags

    bash, gpg, kde, kmail, kontact, linux

  • apt-key / GPG error

    Ab Debian etch gibt es apt in der Version 0.6.xx, welches als grandiose Neuerung die Absicherung der Echtheit der Update-Server durch GPG mitbringt.
    Was ansich ja eine gute Sache ist, jedoch erhaellst der Benutzer direkt nach dem Updaten auf die neue apt-get – Version folgende Fehlermeldung:

    W: GPG error: http://update.server testing Release: The following signatures couldn't be
    verified because the public key is not available: NO_PUBKEY 010908312D230C5F

    Loesung folgedes Problems konnte bis jetzt so behoben werden:
    Die Datei /usr/bin/apt-key zeigt:

    ...
    ARCHIVE_KEYRING=/usr/share/keyrings/debian-archive-keyring.gpg
    REMOVED_KEYS=/usr/share/keyrings/debian-archive-removed-keys.gpg
    ...

    Diese Dateien sollten ersteinmal mit touche angelegt werden, damit apt-key auch arbeiten kann:

    touch /usr/share/keyrings/debian-archive-keyring.gpg
    touch /usr/share/keyrings/debian-archive-removed-keys.gpg

    Um die TrustDB anzulegen muss man nun noch apt-get mit dem Parameter list ausfuehren:

    apt-key list

    Damit wird die Datei /etc/apt/trustdb.gpg erzeugt und auch gleich mit dem Schluessel fuer die Debian Standardarchive gefuellt. Nun muessen nurnoch die gewuenschten Schluessel eingepflegt werden (damit auch apt-get update keinen Fehler mehr bringt):

    gpg --recv-keys --keyserver KEYSERVER bemaengelter_Schluessel
    gpg --armor --export bemaengelter_Schluessel | apt-key add -

    Dabei bindet der erste Befehl den Schluessel in den Keyring ein. Die zweite Zeile exportiert den Schluessel dann wieder und uebergibt ihn direkt an apt-key.
    Ein passender KEYSERVER ist zum Beispiel hkp://pgp.mit.edu.

    Posted

    June 5, 2006

    Tags

    apt-get, bash, debian, gpg, linux

  • Konqueror als Browser

    Nunja irgendwie geht mir zurzeit der Mozilla Firefox etwas auf die Nerven, da einige sachen nicht so funktionieren wie ich will. Leider fehlen bei Konqueror auch noch einige sachen jedoch habe ich schonmal ein kleines Script geschriebe n das etwas kleines schonmal “fixed”.

    Das Problem bei Konqueror ist das man falls man einen Link hat dieser in irgendeinem Konqueror-Fenster oeffnet und nicht explezit in diesem das man als Browser verwenden will. Jedoch kann man diesem abhilfe schaffen, und zwar stellt man bei einem Konqueror-Fenster das Profil auf “Webbrowsing”. Danach kann man vollgendes Script zum oeffnen von URLs verwenden.

    Script: kopenurl

    Posted

    April 14, 2006

    Tags

    bash, kde, konqueror, kopenurl, linux

« Previous Entries
Next Entries »