#!/bin/bash
#
#  Copyright (c) 2012 Jacek Danecki <jacek.m.danecki@gmail.com>
#
# This file is part of KaNaPi project
#
# KaNaPi 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.
#
# KaNaPi 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 KaNaPi.  If not, see <http://www.gnu.org/licenses/>.
echo "###########################################################"
echo "#                                                         #"
echo "#                                                         #"
echo "#                       Witam w KaNaPi                    #"
echo "#                                                         #"
echo "#                                                         #"
echo "###########################################################"

export LANG=pl_PL.UTF-8
export LC_ALL=pl_PL.UTF-8
export EDITOR=vim

mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devpts devpts /dev/pts
echo "czekam na dysk"
sleep 3

mount -t ext4 /dev/sdb2 -o noatime /kanapi_packages
grep kanapi_packages /proc/mounts
if [ $? != 0 ]
then
	mount -t ext4 /dev/sda2 -o noatime /kanapi_packages
fi

grep kanapi_packages /proc/mounts
if [ $? != 0 ]
then
	echo "#######################################"
	echo "####   Nie moge wystartowac KaNaPi ####"
	echo "#######################################"
	echo "#    Napisz o tym pod adres:          #"
	echo "#   jacek.m.danecki@gmail.com         #"
	echo "#######################################"
	exec /bin/bash
fi

ln -sfn /kanapi_packages/bin /bin
rm -rf /root
ln -sfv /kanapi_packages/config/* /
ln -sfv /kanapi_packages/config/.* /

export USER=root
export HOME=/root
export PATH=/bin:.
depmod -a

ifconfig lo up

export LD_LIBRARY_PATH=/kanapi_packages/libs

/kanapi_packages/udev-175/libexec/udevd --daemon
udevadm trigger
udevadm settle
lsmod
rm -f /kanapi_packages/dbus-1.6.8/var/run/dbus/pid
dbus-daemon --system
alsactl init

wpa_supplicant -B -Dwext -iwlan0 -c /kanapi_packages/wpa_supplicant-1.1/etc/wifi.conf
dhclient wlan0 -cf /kanapi_packages/dhcp-4.2.4-P2/etc/dhclient.conf

wpa_supplicant -B -Dwext -ieth1 -c /kanapi_packages/wpa_supplicant-1.1/etc/wifi.conf
dhclient eth1 -cf /kanapi_packages/dhcp-4.2.4-P2/etc/dhclient.conf

#startx
xinit

sync; sync; sync
mount -o remount,ro /kanapi_packages

