Montag, 10. Dezember 2012

This is my bashrc ...

based on debian 7 (wheezy) with systemd


# Dont Save duplicated history lines and remove these form the history file
HISTCONTROL=irgnoredups:erasedups

# show the date and time when the command was actually executed
HISTTIMEFORMAT="%F-%M-%S --> "

# ignore these command and receord them never to the history
HISTIGNORE="su":"su *":"sudo *":"sudo":"his":"his *":"history":"history *":"halt":"reboot":"apt-get *":"apt-cache *":"aptitude *":"dpkg *"

#CDPATH can be confgiured to have a list of fast available and often used paths
#use colons to add more , make sure using the . and .. so you always can cd into a directory whenver it is present in your $PWD and in another
CDPATH=.:..:/usr/share/:/media/:/home/l1zard/workspace/:/media/

# #functions
# this function is to search certain keywords in certain section
section()
{
if [ $# -eq 2 ]
then
apropos $1|grep \^\.\*[[:blank:]]\($2\) || echo "sorry no entry for $1 in section $2"
else
echo "Usgae: section word number"
fi
}


# function traffic lists open ports for user
traffic()
{
ping -c3 google.de && watch -n 10 lsof -i || echo "no network connecttivity"
}

# function to list kernel threads
showthreads()
{
if [ -z "$1" ]
then
ps -A u |sort -k5 -n|awk '{if($5 == 0){print}}'
else

ps -A u|sort -k5 -n|awk '{ if($5 == 0){print }}'| grep $1
fi
}


# function returns status information about the battery health (which is how good the baateries live is in general) and its status (which return how long it takes until the battery needs the next charge)
battery ()
{
case "$1" in
# returns the percentage of battery charge when discharging
"load")
now=$(cat /sys/class/power_supply/BAT0/energy_now)
full=$(cat /sys/class/power_supply/BAT0/energy_full)
out=$(echo $now/$full*100 | bc -l | cut -c 1-5)
echo "Charge: "$out"%"
;;

# returns the battery health. that is the percenatge of the maximal capacity
"health")
design=$(cat /sys/class/power_supply/BAT0/energy_full_design)
current=$(cat /sys/class/power_supply/BAT0/energy_full)
out=$(echo $current/$design*100 | bc -l | cut -c 1-5)
echo "Capacity: "$out"%"
;;

*) echo "Usage: battery load|health"
esac
}


# function cl to list and cd into a directory at the same time
cl()
{
if [ -z $1 ]
then
cd $HOME
ls
else
cd "$1"
ls
fi
echo "Content of $PWD:^^^"
}


# top 10 processes consuming the most cpu-time
top10()
{
if [[ -n $1 && $1 == "-m" ]]
then
ps auxf | sort -nr -k 4 | head -10
else
ps auxf | sort -nr -k 3 | head -10
fi
}

# function to get translate from dings default dictionary
translate ()
{
clear
tr \| \n < /usr/share/trans/de-en|grep --color $1
}

# little function to search for words in rfcs installed locally
rfcfind()
{
zgrep --color $* /usr/share/doc/RFC/rfc-index.txt.gz || echo "no subject found in rfc for $*"
}

# little function to access locally installed rfcs easily
rfc()
{
find /usr/share/doc/RFC/ -name rfc${1}.txt.gz -exec zless {} \; || echo "rfc ${1} does not exist"
}

# function to create and change into a directory in one step
# function adopted from O'Reilly Coookbook
mcd()
{
local NEW_DIR='_command_failed_'
if [ -z "$1" ]
then
echo "mcd: <Datei> [nnn]"
return 1
fi

if [ -d "$1" ]
then
echo "$1 exists"
NEW_DIR="$1"
else
if [ -n "$2" ]
then
mkdir -p -m $1 "$2" && NEW_DIR="$1" || return 1
else
mkdir -p "$1" && NEW_DIR="$1" || return 1
fi
fi

cd "$NEW_DIR"
}


##
# funkctions for systemctl
all()
{
echo "Functions for systemctl to handle more easily:"
echo "failed"
echo "loaded"
echo "masked"
echo "active"
echo "inactive"
echo "waiting"
echo "running"
echo "plugged"
echo "mounted"
echo "exited"
echo "dead"
echo "elpased"
}

failed ()
{
systemctl --no-pager --all|grep --color failed
systemctl --no-pager --all|grep --color error
}

loaded ()
{
systemctl --no-pager --all|grep --color loaded
}

masked ()
{
systemctl --no-pager --all|grep --color masked
}

active ()
{
systemctl --no-pager --all|grep --color active
}

inactive ()
{
systemctl --no-pager --all|grep --color inactive
}

waiting ()
{
systemctl --no-pager --all|grep --color waiting
}

running ()
{
systemctl --no-pager --all|grep --color running
}

plugged ()
{
systemctl --no-pager --all|grep --color plugged
}

mounted ()
{
systemctl --no-pager --all|grep --color mounted
}

exited ()
{
systemctl --no-pager --all|grep --color exited
}

dead ()
{
systemctl --no-pager --all|grep --color dead
}

elapsed ()
{
systemctl --no-pager --all|grep --color elapsed
}
##


# add /sbin to PATH to avoid anoying message
# add ~/bin to PATH
export PATH=$PATH:/sbin:/usr/local/sbin:/usr/sbin:~/bin

test -s ~/.alias && . ~/.alias || true


## make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi

## Nice greeting
echo -e '\E[32m Viel Spaß am Gerät!'; tput sgr0
## show the todo script i wrote everytime i open a shell
todo

## aliases set by user
alias df='dfc -sWT'
alias pine='alpine'
alias vimpdf='apvlv'
alias his='history'
alias last10='tail ~/.bash_history'
alias del='rm -i'
alias emacs='/usr/bin/emacs-nox'
alias fstat='stat -c "%a %n"'
alias hd='hexdump -C'
alias nameservers='grep 'nameserver' /etc/resolv.conf'
alias route='route -n'
alias vusers='cut -d: -f1 /etc/passwd'
# aliasses make the live with python more easier
alias py='/usr/bin/python3'
alias pydoc='pydoc3'
alias pyhelp='w3m /usr/share/doc/python3.2/html/index.html || echo "E: python documentation not installed, linked to wrong location or w4m not installed"'
alias ntpdate='/usr/bin/ntpq -p'
alias h='man'
alias lconfig='cd ~/.local_gitrc'
alias release='cat /etc/debian_version'
alias halt='sudo shutdown -P now'
alias reboot='sudo reboot'
alias update='sudo apt-get -y update && sudo apt-get -y --ignore-hold upgrade && sudo apt-get clean && sudo update-command-not-found && sudo  freshclam && sudo -k'
alias netstat='sudo /usr/bin/watch /bin/netstat -patunel'
# aliasses for systemctl
alias systemctl='systemctl --no-pager --all'
alias india='TZ=Asia/Kolkata date'
alias synaptic='gksu synaptic &'
alias deborphan='sudo gtkorphan'
alias gtkorphan='sudo gtkorphan'
alias fusebundlegen='avira_fusebundlegen'
alias howto='w3m /usr/local/share/doc/HOWTO/index.html'

Samstag, 15. September 2012

Color your df command

Working with the shell is good, right?!  It unleashes the power of your operating system and enables you to communicate and interact with the kernel to get informations managed by your system or to tell the system exactly what you want. One information i use quite frequent is how much disk space each file system has left using the df command.

This program shows you a summary on how much disk space you have available on each mounted file system and how much space in total can be used on each mounted file system.

The dfc (df color) command which can be downloaded from here  makes the output of df more colorful and more human readable than the old df one.

df -sW

Once you have finished downloading the the file unpack it:

tar  xvfz dfc-3.0.0.tar.gz

and change into the directory dfc-3.0.0. To install dfc

(1) first create the "build "directory beneath:

(2) Using opensuse install patterns-openSUSE-devel_C_C++ and cmake by issuing

    zypper in patterns-openSUSE-devel_C_C++ cmake

(3) Change into the build directory and issue the following command instructing cmake to create the the make files and configure the source code:

    cmake .. -DPREFIX=/usr/local -DSYSSCONFDIR=/etc -DCMAKE_BUILD_TYPE=RELEASE

(4) Finally compile and install the program by typing:

    make && sudo make instal

(5) If you need Manpages. And i suggest you install them as root user copy the man files from the directory  you unpacked to /usr/local/share/man/man1/ and change the permissions of the dfc.1 file to 755.

    cp /home/hansel/playground/dfc3.0.0/man/dfc.1 /usr/local/man/man1/dfc.1
    chown root:root /usr/local/man/man1/dfc.1 && chmod 755 /usr/local/man/man1/dfc.1

To finally replace the dfc command with the one from the coreutils package you can use an alias. Setting:

    alias df='dfc -sW'

will give you an output like in the picture. Note that the -h option no longer gives you the so called human readable since it is human readable already but does show you the help for dfc. The nice thing is that dfc can actually determine cgroups and so called kernel pseudo file systems which are created by the kernel itself when the system boots up and does'nt show them. To show all File systems including cgroups and kernel pseudo filesystms you can use the -aoption. Also you are able to filter the file system types. For example -t ext4.vfat,ntfs only shows the disk statistics for those particular file systems.

Options:

-h  help
-s  shows a summary and sums up all values used in by the filter
-W displays the full text path of both the mount points and the device files used by the devices
-a show information about all (psuedo file systems included) file systems
-t  filter the output by file system

Also i will build a rpm which unfortunately i am not allowed to provide to due the authors strict copyright. Maybe i can post or link to the spec file.

Donnerstag, 13. September 2012

Getting frozenbyte games to run in opensuse 12.2

For those of you who running opensuse 12.2 and have bought the humble frozenbyte bundle this is a short instruction how you are able to run these games.

Basics:
(1) Install the game in $HOME/trine for example. You have to make sure that the installer is marked executable.  (In fact i will use trine here as my example for this short guide but it works for all other frozenbyte games as well.)

(2) After installing the game go to the destination folder and copy your lib32 folder to lib32_bak
and create a new lib32 folder using mkdir. Replace all libraries in lib32 folder with the one installed
by zypper/yast. Usually these libraries are found in /usr/lib/ and /lib according to FHS and LSB.

    a) If you cannot find a library try to install them natively with zypper and copy them from there
       original places into the lib32 directory.
    b) If  a library is called /usr/lib/libboost_regex.so.1.49.0 but in lib32 libboost_regex.so.1.35.0
       is required just copy /usr/lib/libboost_regex.so.1.49.0 to lib32/libboost_regex.so.1.35.0 in the trine
       install folder.

Most of the addidional libraries can be found in the addidional opensuse repositories. Only libNxCharacter.so, libNxCooking.so, libPhysXCore.so and libPhysXLoader.so.1 are leaved as original. These are the Nvidia PhysX libraries.   

Setting LD_LIBRARY_PATH="/usr/bin:/lib/$HOME/trine/lib32" should also work but causes the game to crash. Also you may want to create symbolic links to these particular libraries instead  of copying them. But i didn't trie this out.

Trine does not save games by default. To get this working you must delete $HOME/.frozenbyte/trine/profile and replace this directory with the one you find in the games destination path which you have had chosen when you issued the installer.

When you start the game do not use the launcher. Just start the game by executing trine-bin32. If you need to make changes use the .frozenbyte/trine/configs/options.txt and configure this file.

To install the games globally i recommend you moving the game folder to /usr/local/games and create the following startscript in /usr/local/bin:

#!/bin/bash
/home/l1zard/bin/trine/trine-bin32

exit 0


For survivor you need a different script:

#!/bin/bash
cd /usr/local/games/survivor
./survivor-bin

exit 0


I don't know why is that

If you want to debug more missing or failed libraries you can issue strace -o trace.log -f -e trace=open,read trine.

What works: Starting and Playing the game.
What does not work: Some Pictures are not rendered and therefore are not shown in sequences.

Freitag, 7. September 2012

Imho Mein erster Eindruck von opensuse 12.2

Alte - und neue Ärgernisse:

Bei der Installation stolpert der Yast Installationsassistent erst einmal wie üblich über meine externe Festplatte
und möchte die auch gerne formatieren statt mein bisheriges Festplattensetup automatisch einzulesen. Gut das war bei vorherigen Versionen auch schon so. Das dann jedoch, nachdem ich dies wie üblich im erweiterten Partitionssetup geändert und entsprechende Mountpunkte für externe Festplatten gesetzt habe, über Softwareauswahl steht "Zugriff auf /media/Pladde1" nicht möglich macht mir das Angst und ich entferne vorsorglich alle externen Festplatten  und USB Sticks. Anschleißend starte ich den Installer noch einmal.

Dabei stelle ich fest dass es keinerlei Setup Möglichkeiten mehr für den Bootmanager gibt. Die eigentliche Installation verläuft dann wie immer so schnell oder so langsam wie immer. Je nachdem ob man mit oder ohne Abbilder installiert. 

Nach der Installation versuche ich die Softwareauswahl anzupassen. Die meiner Meinung nach in der Softwarevorauswahl angewählten überflüssigen Spiele werden deinstalliert. Am Yast2 scheint sich so gut wie nichts geändert zu haben. Und das Gtk-Frontend schmiert mir auch erst einmal ab. Der Fehler lässt sich übrigens reproduzieren und tritt immer dann auf wenn ich meine Software anpassen möchte und mich das Programm darauf aufmerksam macht, dass für eine Aktion weitere Pakete gelöscht bzw. hinzugefügt werden müssen. Neu ist der Fehler auch nicht. Trat er doch zwischenzeitlich nach einem Patch bereits in den Vorgänger-Versionen 11.2 und 12.1 auf. Fenster die vom Yast2 aus aufgerufen werden, werden genau wie in der Vorgängerversion nicht in der vollen Größe geöffnet. Immerhin habe ich jetzt die Möglichkeit diese mit der Maus in die rechte Größe zu zerren, was ich als störend bei der Systemadministration empfinde. So bleibt mir als Workaround vorerst nichts anderes übrig, als auf das Qt-Frontend auszuweichen. Ich deinstalliere yast2-gnome über den Konsolenbefehl und installiere stattdessen yast2-kde4. Dieses Frontend wurde jedoch seit meinem Einsteig in SuSE (damals hieß das noch so)  9.0 kaum verbessert und bei der Softwareauswahl dauern Konfliktlösungen nachwievor unnötig lange und ist meiner bescheidenen Meinung nach lange nicht so komfortabel. Aber das mag auch Geschmackssache sein.

Neues- und Bewährtes

Opensuse  dürfte mit zu den "Early Adoptern" der Software eines gewissen Herrn Poettering gehören. Dessen Systemd mit Journal nun in Version 44 SystemV Init vollständig ersetzt hat. Was nicht so unproblematisch ist wie ich zunächst gedacht hat. In den Releasenotes wird zudem ausdrücklich darauf hingewisen dass System V Init nicht mehr unterstützt wird. Was mich doch ein wenig verwirrt, denn angeblich sollte es doch Abwärtskompatibel sein.

Für den Bootvorgang wird nun Grub 2.0 mit Plymouth eingesetzt, was das den Bootprozess nun wie ein anderes Betriebssystem aus Redmond ausschauen lässt. Ich empfinde das als unnötige Spielerei, da ich beim Booten gerne sehe, was passiert. Zumal ich auch gar nicht so oft boote. Das Yast2 Modul zur Konfiguration von Grub2 wirkt wie mit der heißen Nadel gestrickt und bietet leider keinen Passwortschutz für denselben an. Kein Problem denke ich, wechsele ich auf Grub Legacy und nutze das dort bewährte Tool grub-md5crypt. Ein Wechsel auf dieses Bootsystem führte bei mir allerdings dazu dass das System gar nicht mehr hochkam und den Grub mittels Rescuesystem reparieren  gestaltet sich mit vollverschlüsselten Festplatten doch als schwierig. Um Grub2 besser einzurichten hat Community Member
jdmcdaniel3 das Script grub2cmd geschrieben.. 
Cryptoloop wird ebenfalls als obsolet erklärt und nicht mehr verwendet. Was auch nachzuvollziehen
ist, da es einige bekannte Schwachstellen aufweist.. Wer im übrigen die Mountpunkte seines Usbsticks
sucht findet diese nun unter /run/media/$USER/$LABEL. Hier werden beim Mounten sogenannte Cgroups verwendet um die Sicherheit für vom User angeschlossene USB-Sticks zu erhöhen. Ein Link nach /media zu setzen bringt hier nichts. Da hilft nur die .bashrc anzupassen und die Variable CDPATH=/var/run/media/$USER zu setzen um sich die Tipparbeit zu sparen.

Zypper sieht jetzt schöner aus mit dem Paket zypper-aptitude nun auch komplett kompatibel mit Debians aptitude. Das bedeutde dass sich die komplette Softwareverwaltung nun mit aptitude bewerkstelligen
lässt. Das teste ich auch gleich aus und aptittude search zypper zeigt mir die installierten Pakete in der bekannten "aptitude-Formatierung". Damit zeigen die Entwickler dass auch opensuse schon seit längerem eine schnelle und brauchbare Paketverwaltung besitzt. 

Die Repositorystruktur wurde verändert. So findet man neben updates auch ein extra Verzeichnis für updates-nonoss. Was meines erachtens nur konsequent ist wenn man diese Unterscheidung schon auch im Hauptdistributionsverzeichnis macht. Allerdings will mir nicht in den Kopf was der Gnu(!) Debugger, auch bekannt als ddd in non-free zu suchen hat. Und warum wird autoconf und automake in die Standardauswahl mit einbezogen. Da ich auf Sicherheit setze werden diese Tools erst einmal entfernt. Genauso sinnbefreit finde ich auch die Auswahl von fortune. Dieses Programm erfüllt nun wirklich keinen sinnvollen Zweck. Hier wäre ein Gremium wünschenswert was darüber entscheidet welche Software in die Standardauswahl reingehört und welche nicht wie das von anderen Distributionen bereits gemacht wird.
Fazit:
Die vom Community Manager  Jos Poortvielt angekündigte stabilste Opensuse aller Zeiten bleibt leider aus. In einer als Release markierten Distribution dürfen wichtige Programme nicht mehr reproduzierbar abstürzen. Schon gar nicht wenn sie zum Kern der Distribution als solches gehören. Den User ohne zu fragen auf Grub2 umzuschwenken finde ich fahrlässig. Hier wäre eine Auswahlmenü für den Bootloader sicher hilfreich. Bleibt zu hoffen dass die gröbsten und ärgerlichsten Fehler so schnell wie möglich behoben werden und dann in den nächsten Wochen endlich ein wirklich stabiles Endprodukt abliefert wird. Einige Patches sind auch schon da.

Freitag, 10. August 2012

Autostart a terminal at gnome startup with several tools running

The first thing i do when my linux system is up i open a new terminal and start several tools to monitor my system. Can we start the desktop environment with a shell already running these tools?

Yes we can.

I used this command line:
gnome-terminal --tab-with-profile="Default" -e "systemd-journalctl -f -a" --tab-with-profile="Default" -e htop --tab-with-profile="Default"

and added it as a gnome-session-properties autostart program.
This opens a gnome-terminal with 3 tabs. In each tab running systemd-journalctl, htop and a clear one for further tasks like updating the system. Each tab uses the "Default" profile. The --tab-with-profile="Default" uses this profile in each new tab. The -e Option specifies the program you want to start in this particular tab. Note that if you want to parse options to one of these tools you have to quote them.

You also can combine these tools with pipes and logic operators. If you want for example an autoupdate on a debian based system you could do this by using this autostart command-line:

gnome-terminal -e "sudo apt-get update && sudo apt-get upgrade && sudo apt-get clean && sudo update-command-not-found && sudo -k"

This will update your system as root,- if you have configured your /etc/sudoers file correlatively,- and will close the shell or the tab when the update is finished or cannot be issued.

One last thing that may annoy you is that every time the gnome-terminal does not start in full maximized mode by default. Using gnome-terminal --help-window-options reveals that you simply have to append --maximize to your options.

And it works perfect.

Summary gnome-terminal options:

-e "<Command>" Starts the gnome Terminal with this command executed. Using Quotes is only neccessary if you want to use options or links
several programs together with logical operators.

--tab-with-profile="<Profile>" opens a new tab with the Profile for each time this option is used. After each Option you can pass on the -e to sepcify which
program should be running in each tab.

--maximize start the gnome-terminal maximzed.