#!/bin/bash
### BEGIN INIT INFO
# Provides:          fix 
# Required-Start:    $local_fs 
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: fix xorg.conf..., run once.
# Description:       fix fulong2f.
### END INIT INFO

LANG=C


update-rc.d -f fix remove
echo detect system type			#诊断系统类型,目前支持2e-box,2f-box,notebook-8089,unas
local_arch=unkown_arch
if [ "`grep lemote-fulong /proc/cpuinfo;grep lemote-fuloong /proc/cpuinfo`" ]
then
 update-rc.d -f ssh remove 
 update-rc.d ssh  start 99 1 2 3 4 5 .
 update-rc.d -f wifi-radar remove 
 if [ "`grep -i V0.2 /proc/cpuinfo`" ]
 then
  local_arch=fulong2e				#龙芯2E盒子         
 else
  local_arch=fulong2f				#龙芯2F盒子
 fi
else
 if [ "`grep lemote-notebook /proc/cpuinfo;grep lemote-yeeloong /proc/cpuinfo`" ]
 then
 update-rc.d -f wifi-radar remove 
 update-rc.d wifi-radar  start 20 2 3 4 5 .
 local_arch=yeeloong				#笔记本8089
 fi
fi

echo $local_arch

echo fix hostname
hostname $local_arch
echo $local_arch >/etc/hostname
echo 127.0.0.1 localhost $local_arch >/etc/hosts


echo fix /boot/vmlinux			#修改启动内核 /boot/vmlinux
if [ -s /boot/vmlinux-${local_arch} ]
then 
 rm /boot/vmlinux
 ln /boot/vmlinux-${local_arch} /boot/vmlinux
fi

#诊断debian版本
if [ `grep 5.0 /etc/debian_version;grep lenny /etc/debian_version` ]
then 
ver=lenny
else
ver=squeeze
fi

echo fix sources.list				#修改软件源
echo fix rmvb_codec 				#修改rmvb解码库
mkdir -p /usr/lib/codecs
if [ $local_arch = "fulong2e" ] 
then  
 cd /etc/apt/sources.list.d
 echo deb http://www.anheng.com.cn/loongson/${ver} ./ >/etc/apt/sources.list.d/bjlx.list
 echo deb-src http://www.anheng.com.cn/loongson/${ver} ./ >>/etc/apt/sources.list.d/bjlx.list
 cp /root/rmvb_code_2e.so /usr/lib/codecs/drvc.so
else
 cd /etc/apt/sources.list.d
 echo deb http://www.anheng.com.cn/loongson2f/${ver} ./ >/etc/apt/sources.list.d/bjlx.list
 echo deb-src http://www.anheng.com.cn/loongson2f/${ver} ./ >>/etc/apt/sources.list.d/bjlx.list
 cp /root/rmvb_code_2f.so /usr/lib/codecs/drvc.so
fi

echo fix xorg.conf				#修改xorg.conf
if [ $local_arch = "yeeloong" ]
then
cp /etc/X11/xorg.conf.notebook /etc/X11/xorg.conf
else
cp /etc/X11/xorg.conf.box /etc/X11/xorg.conf		#盒子可以用通用配置文件
fi


echo fix files
chown -R loongson:loongson /home/loongson		#修复一些可能的文件权限
chmod -R u+rw /home/loongson

dpkg-reconfigure  dbus
echo ok!
