主要有 设置locales 安装中文输入法 更改提示符
还有管道、here文档的一些示例
发现有问题/不好的地方 欢迎 指出 !
代码: 全选
#!/bin/bash
#out=">>/dev/null 2>&1"
brc=~/.bashrc
first(){
if grep -q cxlinux ~/.bashrc 2>/dev/null ;then
# echo "hello"
return 1
fi
return 0
}###查看.bashrc里有没有 cxlinux 这个字
write_bashrc()
{
cat <<eof>>~/.bashrc
if [ "cx\$TERM" == "cxlinux" ] && [ "X\$LANG" != "XC" ];then
echo "\\\$TERM=linux Set LC_ALL=C"
export LC_ALL="C"
fi
eof
}### 如果 bash 在终端(没有x的那个东西)上打开 设置locale 为C
alias_set(){
if grep "apt-search" ~/.bashrc >/dev/null 2>&1;then
return
fi##如果.bashrc 里右apt-search 说明 写过了
cat <<eof>>~/.bashrc
#alias apt-get='sudo apt-get'
alias apt-rm='sudo apt-get --purge remove'
alias apt-install='sudo apt-get install'
alias apt-up='sudo apt-get update'
alias apt-upgrade='sudo apt-get upgrade'
alias apt-search=' apt-cache search'
alias apt-dep='apt-cache depends'
alias apt-rdep='apt-cache rdepends'
export PS1='\[\033[0;0;32m\]\u@\h:\w\n\[\033[0;0;44m\]-\$?-\\\$ \[\033[0;0;0m\]'
export PATH="$PATH:~/scripts:."
alias getfuck='wget -P /tmp http://www.baidu.com/index.html --timeout=5 --tries=1'
### adsl 拨号后 运行getfuck 这样浏览器第一次就不会有 那个东西了
eof
}### 为方便 使用 alias
pcspkr() ## 我不喜欢 按tab 后的响声 需要运行rmmod pcspkr
{
if [ ! -e /etc/rc2.d/S99pcskrs ];then ##没有/etc/rc2.d/S99pcskrs 就创建它
sudo touch /etc/rc2.d/S99pcskrs
fi
{
cat <<eof
cat <<end >>/etc/rc2.d/S99pcskrs ##把下面的 到end前的文本写入etc/rc2.d/S99pcskrs
#!/bin/bash
if [ -e /proc/mounts ] && (cat /proc/modules|grep pcspkr >/dev/null 2>&1);then
/sbin/rmmod pcspkr ## /proc/mounts 且 /proc/mounts 里头含有 pcspkr 才运行这句
fi
end
if [ ! -x /etc/rc2.d/S99pcskrs ];then
chmod uga+x /etc/rc2.d/S99pcskrs ##赋给执行权限
/etc/rc2.d/S99pcskrs ##运行
fi
####以上需要root 权限 所以 用cat <<eof 把它们写到stdout上
#### 通过 管道 作为 sudo /bin/bash 的输入
#### 这跟 sudo /bin/bash 后,我们手动输入没有两样
eof
}|sudo /bin/bash ## cat <<eof output will be input of bash (uid=root) so "cat <<end" run as root
### I feel it funny
}
write_pp(){ ### 这个很简单 我不记得 dsl-provider 所以 每次都很烦就这样了
if ! grep dsl-provider $brc >/dev/null;then
cat <<eof >>$brc
alias pon='sudo pon dsl-provider'
alias poff='sudo poff dsl-provider'
eof
fi
}
set_locales()######## 编译中文locales
{
local locales
locales="/etc/locale.gen" ##debian 默认使用它
if cat /etc/issue.net |grep -q [uU]buntu] ;then
locales="/var/lib/locales/supported.d/locales" ###如果是就用 /var/lib/locales/supported.d/ 下的任意文件
fi ###我选字叫locales
{
cat <<end
echo "Install the inputmethod "
apt-get install --yes im-switch fcitx
echo "Set locales"
if [ "/var/lib/locales/supported.d/locales" == $locales ];then
rm -f /var/lib/locales/supported.d/*
fi ## 节约 locale-gen时的时间
cat <<eof>$locales ##写入$locales 指定的文件
en_US.UTF-8 UTF-8
zh_CN GB2312
zh_CN.GB18030 GB18030
zh_CN.GBK GBK
zh_CN.UTF-8 UTF-8
eof
locale-gen
im-switch -z zh_CN.UTF-8 -s fcitx
end
}|sudo bash ###这里跟上面 pcspkr 一样
echo "locales done"
echo "Done ."
}
do_main() ##所有操作在这里进行
{
if first ;then
write_bashrc
fi
alias_set
pcspkr
write_pp
unset out
set_locales
chmod a+x $0
}
do_main ## 一切从这里开始