#!/bin/sh
if [ "$(id -u)" != 0 ]; then
 echo Error: You must be root to run this script!
 exit 1
fi

# re-enable powerbutton
if [ -f /etc/powersave/events ]; then
 sed -i 's/^\(EVENT_BUTTON_POWER=\).*/\1"wm_shutdown"/' /etc/powersave/events
 pidof powersaved >/dev/null && /etc/init.d/powersaved restart
fi

# vim tuning
if [ -d /etc/vim ]; then
 rm -f /etc/vim/vimrc.local
cat <<EOT > /etc/vim/vimrc.local
syntax on
set background=dark
set showmatch          " Show matching brackets.
set pastetoggle=<F10>
EOT
fi

# fix kdm/gdm/xdm/wdm startup
for x in kdm gdm xdm wdm; do
 if [ -x /etc/init.d/$x ]; then
  update-rc.d -f $x remove
  update-rc.d $x start 99 5 . stop 01 0 1 2 3 4 6 .
 fi
done

# init 5 as default
sed -i s/id:.:initdefault:/id:5:initdefault:/ /etc/inittab

# enable textlogins for runlevel 4/5
sed -i 's/\([1-6]:23\):/\145:/' /etc/inittab

# workarounds to fix old kanotix installs
rm -f /etc/profile /etc/environment /etc/bash.bashrc
cp /usr/share/base-files/profile /etc
rm -rf /etc/sysconfig

# update bash.bashrc
cat <<'EOT' >> /etc/bash.bashrc
# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, overwrite the one in /etc/profile)
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
#    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
#    ;;
#*)
#    ;;
#esac

# enable bash completion in interactive shells
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
EOT

# rm/cp/mv aliases and bash completion for login shell
cat <<EOT >> /etc/profile

# enable bash completion in interactive shells
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
EOT
