Ubuntu一键配置脚本

转自:http://www.linuxdiyf.com/linux/plus/view.php?aid=13869


经常在网上看到安装完Ubuntu之后应该做的十件事情之类的文章,于是我自己写了一个Ubuntu的配置脚本:
我的Ubuntu版本是14.04LTS

参见我的github地址:https://github.com/adairjun/ubuntu_config


首先获取当前的目录:

#!/bin/bash
# 需要sudo来执行
dir=`pwd`


1,脚本需要sudo来执行,所以需要判断是否具有root权限:

function rootness {
if [[ $EUID -ne 0 ]]
then
echo "Error:This script must be run as root!" 1>&2
exit 1
fi
}


2,apt-get

function apt_conf {
apt-get clean
apt-get autoclean
apt-get update
apt-get -y upgrade
apt-get -y dist-upgrade
}


3,git的配置:

function git_conf {
apt-get -y install git
cp $dir/gitconfig ~/.gitconfig
}

这里简单地把我自己的gitconfig文件作为了.gitconfig

[user]
name = Xiong Jun
email = adairjun@gmail.com
[color]
ui = true
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
[core]
editor = vim


4,ubuntu写代码必备之terminator的配置:
除了下载terminator之外,还有terminator的配色方案以及ls的配色方案就是.dircolors

function term_conf {
apt-get -y install terminator
git clone https://github.com/ghuntley/terminator-solarized.git $dir
mkdir -p ~/.config/terminator/
cp $dir/terminator-solarized/config ~/.config/terminator
#把默认的配色方案设置为solarized-dark
sed -i "{/^\s*#/d; /solarized-dark/d; /solarized-light/,+5d}" ~/.config/terminator/config
git clone https://github.com/seebi/dircolors-solarized.git
cp $dir/dircolors-solarized/dircolors.256dark ~/.dircolors
rm -rf $dir/terminator-solarized/
rm -rf $dir/dircolors-solarized/
}


5,写代码的杀手级编辑器vim怎么能忘记配置呢?

function vim_conf {
cp $dir/vimrc ~/.vimrc
mkdir ~/.vim
cp -R $dir/doc/ ~/.vim/
}

这里的vimrc根据的是我的.vimrc
http://blog.csdn.net/u014120684/article/details/44280211

至于doc这个目录则是汉化版本的help


6,多终端的tmux神器也不能忘了:

function tmux_conf {
apt-get -y install tmux
cp $dir/tmux.conf ~/.tmux.conf
}

同样:这里的tmux.conf用的是:
http://blog.csdn.net/u014120684/article/details/44281197


7,等下可是要安装chrome的,如果不改hosts翻墙的话,GFW可是不会让我下载chrome的deb:

function hosts_conf {
git clone https://github.com/racaljk/hosts.git
cat ./hosts/hosts >> /etc/hosts
rm -rf ./hosts/
}


8,sublime_text也是一个杀手级别的编辑器:

function sublime_conf {
dpkg -i $dir/sublime-text_build-3083_amd64.deb
}

至于sublime_text的deb可以直接访问 http://www.sublimetext.com/3 来下载


9,用JAVA编程JDK是必备的:
不过首先要做的是移除自带的openjdk

function jdk_conf {
apt-get -y autoremove openjdk
cd /usr/local/lib
tar -zxvf $dir/jdk-8u45-linux-x64.tar.gz
cat > /etc/profile <<EOF
export JAVA_HOME=/usr/local/lib/jdk1.8.0_45
export JRE_HOME=\$JAVA_HOME/jre
export CLASSPATH=/usr/local/lib/jdk1.8.0_45/lib
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH=\$JAVA_HOME/bin:\$PATH
EOF
source /etc/profile
cd $dir
}

这里下载的只是jdk的1.8.0_45版本,请配合自己下载的版本修改这个函数


10,有了jdk,不能忘了eclipse:

function eclipse_conf {
cd /opt
tar -zxvf $dir/eclipse-java-luna-SR2-linux-gtk-x86_64.tar.gz
cd $dir
}

linux的/opt目录是 Optional application software packages,就是安装第三方软件的目录啦,以后用tarball安装第三方软件最好解压到这个目录下,方便管理


11,chrome安装:

function chrome_conf {
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb
}

如果先前没有改hosts文件wget可是不会成功的


12,浏览器的flash安装:

function flash_conf {
apt-get -y install flashplugin-nonfree
update-flashplugin-nonfree --install
}


13,搜狗拼音输入法:

function sogou_conf {
dpkg -i $dir/sogoupinyin_1.2.0.0056_amd64.deb
}

下载搜狗拼音的安装包前往:http://pinyin.sogou.com/linux/?r=pinyin


14,接下来的这个配置可厉害,让你的ubuntu更加漂亮:
infinality提供了freetype的patches, 目的是提供最好的字体渲染效果。

function infinality_conf {
add-apt-repository ppa:no1wantdthisname/ppa
apt-get update
apt-get -y upgrade
apt-get -y install fontconfig-infinality
bash /etc/fonts/infinality/infctl.sh setstyle osx2
}

我参考了这篇文章:http://askubuntu.com/questions/527349/font-rendering-problem-in-ubuntu


15,接来下隆重登场的是替代bash的终极Shell: zsh
以及必不可少的oh-my-zsh和autojump

function zsh_conf {
apt-get -y install zsh
chsh -s /bin/zsh
git clone https://github.com/robbyrussell/oh-my-zsh.git /$HOME/.oh-my-zsh
cp /$HOME/.oh-my-zsh/templates/zshrc.zsh-template /$HOME/.zshrc
apt-get -y install autojump
cat > /$HOME/.zshrc <<EOF
PROMPT=$'[%{$fg[white]%}%n@%m%{$reset_color%} %~]%# '

alias ll='ls -l'
alias vi='vim'
alias grep="grep --color=auto"
alias egrep="egrep --color=auto"
alias diff="colordiff"
alias javac="javac -J-Dfile.encoding=utf8"
alias java="java -ea"

export TERM=xterm-256color

if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "\$(dircolors -b ~/.dircolors)" || eval "\$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi

[[ -s /usr/share/autojump/autojump.zsh ]] && . /usr/share/autojump/autojump.zsh
EOF
source /$HOME/.zshrc
}


16,介绍一下我使用的小工具:

function other_conf {
apt-get -y install tree pstree ack-grep colordiff
apt-get -y install unrar unzip
# 安装几个我常用的小工具,秒杀top的htop,两款流量监控工具iftop和nethogs,很好用的下载工具aria2:
apt-get -y install htop iftop nethogs aria2
# Python类工具需要:
apt-get -y install python-dev python-greenlet python-gevent python-vte python-openssl python-crypto python-appindicator python-bs4 libnss3-tools
}


17,如果你的网卡和我一样是bcm43225,那么可能会出现上网很慢的情况,这估计是网卡驱动问题,这样解决:

#如果用的是bcm网卡,用这个来解决网络慢的问题
#如果单独执行这个函数,最后需要重启
function bcm_conf {
apt-get -y install bcmwl-kernel-source  
cat >> /etc/modprobe.d/blacklist.conf <<EOF
blacklist b43
blacklist ssb
blacklist brcmsmac
EOF
}

我参考了这篇文章:http://blog.sina.com.cn/s/blog_73b6331101016haq.html


18,最后的一点配置,就是脚本参数,如果单独执行这个脚本,什么参数都不传:

./build_ubuntu.sh

1

那么就按如下来执行:

if [ -z "$1" ]
then
rootness
apt_conf
git_conf
term_conf
vim_conf
tmux_conf
hosts_conf
sublime_conf
jdk_conf
eclipse_conf
chrome_conf
flash_conf
sogou_conf
infinality_conf
zsh_conf
other_conf

reboot
fi

如果传了参数:

while [ -n "$1" ]
do
case "$1" in
--apt)   apt_conf ;;
--git)   git_conf ;;
--term)  term_conf ;;
--vim)   vim_conf ;;
--tmux)  tmux_conf ;;
--hosts) hosts_conf ;;
--sub)   sublime_conf ;;
--jdk)   jdk_conf ;;
--ecl)   eclipse_conf ;;
--chr)   chrome_conf ;;
--fla)   flash_conf ;;
--sog)   sogou_conf ;;
--inf)   infinality_conf ;;
--zsh)   zsh_conf ;;
--oth)   other_conf ;;
--bcm)   bcm_conf ;;

--) shift #使用shift将当前的参数双破折线移除
break ;;
*)  echo "$1 is not a option" ;;
esac
shift
done

count=1
for param in $@
do
echo "para $count: $param"
count=$[ $count+1 ]
done

分离参数和选项:linux处理这个问题的方式是使用双破折线(–)。bash和其他shell会用双破折线来表明选项结束了。看到双破折线之后,shell会将剩下的命令行参数当作参数来处理,而不是选项。
由于以后可能会扩展脚本,所以这里先使用这个。


CENTOS/UBUNTU一键安装IPSEC/IKEV2 VPN服务器:http://www.linuxdiyf.com/linux/13378.html

CentOS/Debian/Ubuntu系统一键安装LNMP/LAMP/LNMPA网站环境:http://www.linuxdiyf.com/linux/13084.html

centos6.5 lnmp、lamp、lnmpa一键安装包:http://www.linuxdiyf.com/linux/12689.html

Linux下一键安装PowerShell的bash脚本:http://www.linuxdiyf.com/linux/8562.html

rsync+inotify一键安装脚本:http://www.linuxdiyf.com/linux/1462.html


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值