[原创]系统配置script示例

sh/bash/dash/ksh/zsh等Shell脚本
回复
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京
送出感谢: 0
接收感谢: 2 次

[原创]系统配置script示例

#1

帖子 aBiNg » 2006-11-21 21:13

有什么东西比自己做成一件事情更让人惊喜的呢?

不过,现默认你至少要比我的shell基础扎实得多,不然会有些麻烦!:wink:

但,不必担心的,高手们一般认为我写的这个东东就跟没学shell基础一个级别呢,呵呵

代码: 全选

#! /bin/bash

sudo ifconfig eth0 up

#换源,这里假设在"~/"或者"/media/sda5"下存有sources.list备份文件
echo "changing the sources list, which includes fjtu,cn99,vmmatrix and ubuntu official repositories..."
sources_default="/etc/apt/sources.list"
s_array=(`find {~/,/media/sda5} -iname sources.list`)
sources_backup=${s_array[0]}

#比较一下先
echo "compare the default sources with the backup sources..."
diff -q $sources_default $sources_backup

#异则换,同则否
if [ $? -ne 0 ]
then
	sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup
	sudo cp $sources_backup /etc/apt/sources.list
else
	echo "not necessary to change the repositories."
fi

#更新软件库
echo ' '
echo -e "updating packages from repositories...\nthis may take several minutes, it's up to your network."
sudo apt-get update 2>&1
sudo apt-get upgrade 2>&1

#自定义bash command,终端关闭即unset
export f="-y --force-yes"
export ps="ps -U $USER"
export ins="sudo apt-get install"
export rem="sudo apt-get remove --purge"

#安装fcitx,已有则不执行
echo ' '
echo "fcitx will be installed if not detected..."
$ps | grep -q fcitx
if [ $? -eq 1 ]
then
	$ins fcitx ^scim{,-*}- $f && sudo apt-get autoremove $f
	scim_ID=`pidof scim`
	if [ -z $scim_ID ]
	then
		echo ' '
		echo "scim processing is not found, launch the IM_client fcitx directly."
		break
	else
		kill -9 $scim_ID
	fi
	fcitx &
	echo ' '
	echo "scim has been removed and replaced by fcitx."
else
	echo "fcitx is running."
fi

#安装codecs for MPlayer,不想用MPlayer就注释之
echo ' '
echo "installing MPlayer codecs-20061022..."
if [ ! -d /usr/lib/codecs ]
then
	wget -c http://www1.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2
	tar jxvf essential-*.tar.bz2 -C ./
	sudo mkdir -p /usr/lib/codecs && sudo cp ./essential-20061022/* /usr/lib/codecs/
	echo "MPlayer codecs package has been installed sucessfully. back up the codecs package..."
	mv essential-*.tar.bz2 ~/backup
	rm -rf essential-*
else
	echo "there is MPlayer codecs package installed."
fi

#安装编译环境
echo ' '
echo "installing compiling components..."
if [ ! -d /usr/share/build-essential ]
then
	$ins build-essential make automake autoconf gcc g++ libc6-dev $f
	echo ' '
else
	echo "not necessary to install compiling requirements"
fi

#安装MPlayer主程序,这里从官方下载,编译安装,仅作为一个例子,没有别的意思
echo ' '
echo "installing MPlayer-1.0rc1... "
if [ -z `type mplayer`]
then
	wget -c http://www1.mplayerhq.hu/MPlayer/releases/MPlayer-1.0rc1.tar.bz2
	tar jxvf MPlayer-*.tar.bz2 -C ./
	cd MPlayer-1.0rc1
	./configure --enable-gui --language=zh_CN
	make && sudo make install
	echo ' '
	echo "MPlayer program has been installed successfully. back up the sources package..."
	mv MPlayer-*.tar.bz2 ~/backup/
	rm -rf MPlayer-*
else
	echo "MPlayer has been detected."
fi

#安装MPlayer附件
echo ' '
echo "installing MPlayer attachments..."
$ins mplayer-{fonts,skins} mozilla-mplayer $f
echo "attachments have been completed."

#安装MS-fonts,也只是个例子,旨在说明字体的简单安装配置,也假设MS-fonts文件放在"~/"或者"/media/sda5"下面
echo ' '
echo "installing MS-fonts..."
if [ -f ~/.fonts/tahoma.ttf ]
then
	echo "you have installed MS-fonts."
else
	MS_fonts=(`find {~/,/media/sda5} -iname MS-fonts`)
	mkdir ~/.fonts && cp ${MS_fonts[0]}/* ~/.fonts/
	cd ~/.fonts
	sudo mkfontdir && sudo mkfontscale
	sudo fc-cache -fv
	echo "MS-fonts have been installed successfully."
fi

#安装java,并配置,这里无法做到“无人看管”
echo ' '
echo "java will be installed..."
if [ ! -f `which java` ]
then
	$ins sun-java5-jre $f
	sudo update-alterntives --config java
	echo "have installed the lastest sun-java."
else
	echo "java has existed."
fi

#安装stardict,只举一个词典的例子,有人可能说可以从源安装,it's up to you
echo ' '
echo "installing stardict and its dictionaries...maybe it will take a long time!"
$ins stardict{,-common} $f
wget -c http://easynews.dl.sourceforge.net/sourceforge/stardict/stardict-kdic-computer-gb-2.4.2.tar.bz2
tar jxf stardict-kdic-computer-gb-2.4.2.tar.bz2 -C ~/.stardict/dic

echo ' '
echo "cleaning temporary packages about stardict..."
rm stardict-*.tar.bz2

#其它更简单softwares
echo ' '
echo "install other used-widely softwares..."
$ins xchat xchat-systray amarok amule w32codecs libxine-extracodecs xfonts-wqy flash{plugin,player}-nonfree mozilla-firefox-locale-zh-cn $f
echo ' '
echo -e "config has been finished.enjoy linux world!\nRestarting X-Window is strongly recommended!"

#重启X-Window
#sudo /etc/init.d/gdm restart
明白了么?自己动手,很简单的事情而已。。。有不对或不妥之处望指正,谢谢!
头像
goldfox_79
帖子: 1937
注册时间: 2005-10-16 8:26
来自: 地球
送出感谢: 0
接收感谢: 1 次
联系:

#2

帖子 goldfox_79 » 2006-11-21 21:19

赞!
头像
karron
帖子: 6226
注册时间: 2005-06-11 14:03
来自: 不明真相的群众
送出感谢: 0
接收感谢: 0
联系:

#3

帖子 karron » 2006-11-21 21:19

不错阿.比我的那个技术含量高到不知道那里去了 .
我的blog,关于技术,软件,linux,vim <---- 所有博客均被河蟹.
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京
送出感谢: 0
接收感谢: 2 次

#4

帖子 aBiNg » 2006-11-21 21:24

karron 写了:不错阿.比我的那个技术含量高到不知道那里去了 .
表忽悠我了。。。 :lol:

注一下:貌似发错地儿了。。。汗!
头像
bones7456
论坛版主
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
送出感谢: 0
接收感谢: 8 次
联系:

#5

帖子 bones7456 » 2006-11-21 21:44

确实比较有技术含量,呵呵,又见高手阿!
fjchenq
帖子: 160
注册时间: 2006-12-14 19:14
送出感谢: 0
接收感谢: 0

#6

帖子 fjchenq » 2006-12-28 23:18

收藏。
头像
tianyi210
帖子: 32
注册时间: 2006-03-30 7:30
送出感谢: 0
接收感谢: 0
联系:

#7

帖子 tianyi210 » 2007-01-24 11:43

谢谢了。拉下的shell编程的学习又将开始了。
wellbring
帖子: 20
注册时间: 2007-01-20 15:45
送出感谢: 0
接收感谢: 0

#8

帖子 wellbring » 2007-02-06 10:59

normal
relive
帖子: 39
注册时间: 2007-05-24 14:56
送出感谢: 0
接收感谢: 0

#9

帖子 relive » 2007-05-24 16:29

flew
woodandwood
帖子: 86
注册时间: 2006-07-21 16:15
送出感谢: 0
接收感谢: 0

#10

帖子 woodandwood » 2007-06-18 16:34

好东东,学习一下
头像
adqin
帖子: 1417
注册时间: 2007-01-24 22:07
来自: http://adqin.cn
送出感谢: 0
接收感谢: 0
联系:

#11

帖子 adqin » 2007-06-18 20:38

又一个学习的。。。。
回复

回到 “Shell脚本”