Shell 脚本小试牛刀(1) -- Debian系统初装后的各种配置

来源:互联网 发布:android 淘宝头条 编辑:程序博客网 时间:2024/05/01 06:47

http://blog.csdn.net/longerzone/article/details/20874311

最近经常重装系统,而刚装完Debian系统的电脑需要各种配置真心有点烦躁,于是乎想写个脚本偷偷懒,解决一下每次装系统都要重新配置的问题(在这分享给大家,也简化了大家装Debian后麻烦的配置过程大笑)。

一、使用方法

1. 下载我打包的文件new_machine.tar (下载地址),然后在我的云盘分享处下载Linux的wps安装包(我自己会在Debian系统中使用WPS,这样可以轻松在Linux中对文档进行修改,如果直接Libreoffice对Windows下的文档进行修改,以后再拿到Windows下打开时排版都会全乱了)

2. cd ~/Download  ---> tar -xvf new_machine.tar 进入下载目录解压new_machine.tar文件

3.cd new_machine 

4.mv ~/Download/wps-office_8.1.0.3724~b1p2_i386.deb  .

5.ifconfig 或者ping www.baidu.com确认电脑是否联网

6.su 切换至 root 用户

7.chmod +x install.sh --->  ./install.sh  好了,脚本会安装很多东西,所以此时你可以去吃饭或者打球去了!


二、脚本展示

初学者写的比较简单,有好的建议还望大家提出来:

[plain] view plain copy 在CODE上查看代码片派生到我的代码片
  1. #!/bin/bash  
  2. # (C) 2014 Yunlong Zhou <reaper888@yeah.net>  
  3. # Under licence  GPL  
  4. # File :    install.sh  
  5. # Introduction:  
  6. #       This script is using for simplify the installing of Debian 5/6/7 new install machine   
  7. # Useage :  
  8. #       1. "su"     -- get root permission  
  9. #       2. "ifconfig" or "ping www.baidu.com "  -- to check if the computer is connecting Internet  
  10. #       3. if have no Internet , "dhclient eth0"    -- to connect the Internet  
  11. #       4. "tar -xvf new_machine.tar"  then "cd new_machine"  
  12. #       5. "chmox +x install.sh"        -- give our script a execution permission  
  13. #       5. "./install.sh"   -- auto install and you can have a coffee now             
  14.   
  15. # firstly ,we set the apt-source, here we just give Debian 5/6/7 set module, if you use older or newer Debian version ,Just do a little change !  
  16.  echo "Now setting apt source"  
  17.  if grep -q "7.*" /etc/debian_version || grep -q -i "wheezy" /etc/debian_version ; [[ $? == 0 ]] ; then   
  18.      echo "deb http://mirrors.163.com/debian wheezy main contrib non-free" >/etc/apt/sources.list  
  19.  elif grep -q "6.*" /etc/debian_version || grep -q -i "squeeze" /etc/debian_version ; [[ $? == 0 ]] ; then   
  20.      echo "deb http://mirrors.163.com/debian squeeze main contrib non-free" >/etc/apt/sources.list     
  21.  elif grep -q "5.*" /etc/debian_version || grep -q -i "lenny" /etc/debian_version ; [[ $? == 0 ]] ; then  
  22.      echo "deb http://mirrors.163.com/debian lenny main contrib non-free" >/etc/apt/sources.list   
  23.  fi   
  24.  apt-get update  
  25.    
  26.  # add chinese fonts and ibus,if you don't need ,just comment it  
  27.  echo "Now doning Chinese install"  
  28.  echo Y | apt-get install ttf-wqy-zenhei xfonts-intl-chinese wqy*   ibus im-switch ibus-pinyin    
  29.    
  30.  # add some useful application ,if you need some changes ,just do it  
  31.  echo " Now doing some application install"  
  32.  echo Y | apt-get install aptitude  dia xournal wireshark ssh unzip  ctags cscope git chromium-browser vim screen linuxlogo libncurses5-dev  build-essential libc6-dbg kernel-package  
  33.   
  34.  # install sudo ,if you don't need just comment it  
  35.  echo "Now install sudo for your system and give your user a sudoer permission"  
  36.  echo Y | apt-get install sudo  
  37.  my_user=`who | head -n 1 | cut -d " " -f 1`   
  38.  echo "$my_user ALL=(ALL:ALL) ALL" >> /etc/sudoers      
  39.   
  40.  # the function is using for check if a application is installed ,if not installed just install it with apt-get install  
  41. function install_app  # para is the func you want to install  
  42. {  
  43.     aptitude search $1 > /tmp/log  
  44.     file_line=`cat /tmp/log | wc -l`  
  45.     for((i=1;i<=$file_line;i++));do   
  46.         sed -n "$i"'p' /tmp/log >/tmp/log1  
  47.         i_status=`awk '{print $1}' /tmp/log1`  
  48.         par2=`awk '{print $2}' /tmp/log1`  
  49.         par3=`awk '{print $3}' /tmp/log1`  
  50.         if [[ $par2 == $1 || $par3 == $1 && $i_status != 'i' ]]; then  
  51.             echo "Sorry ,\"$1\" not installed,we will install it"  
  52.             apt-get install $1  
  53.         elif [[ $par2 == $1 || $par3 == $1 && $i_status == 'i' ]]; then  
  54.             echo "OK ,\"$1\" has been installed "  
  55.             break  
  56.         fi  
  57.     done  
  58.     rm /tmp/log /tmp/log1  
  59. }  
  60.   
  61. # sometimes ,our system have no graphic interfaces,we use these to install GNOME, if no need comment it  
  62.  echo " Now installing gnome"  
  63. install_app  xorg  
  64. install_app  gnome-core  
  65. install_app  gdm3  
  66.   
  67. # add flash support for FireFox and Chrome Browse  
  68. echo " Now add flash support for browse"  
  69. mkdir -p /home/$my_user/.mozilla/plugins/   
  70. mv libflashplayer.so /home/$my_user/.mozilla/plugins/  
  71.   
  72. # add vim config   
  73. echo " Now add vim config"  
  74. mkdir -p /home/$my_user/.vim/plugin  
  75. mv taglist.vim /home/$my_user/.vim/plugin/  
  76. mv vimrc /etc/vim/vimrc   
  77.   
  78. # install WPS for i386/i686 system   
  79. echo "Now installing WPS"  
  80. uname -a >/tmp/system_version  
  81. if grep "i386" /tmp/system_version || grep "i686" /tmp/system_version ; then  
  82.     dpkg -i symbol-fonts_*  
  83.     if [ ! -f wps-office_* ] ;then  
  84.         echo " Now doloading wps for linux ,may need a little long time"  
  85.         wget http://wdl1.cache.wps.cn/wps/download/Linux/unstable/wps-office_8.1.0.3724~b1p2_i386.deb  
  86.     fi  
  87.     dpkg -i wps-office_*  
  88. else  
  89.     echo "Sorry ,your system is not 32 bit system ,we will not install wps"  
  90. fi  
  91.   
  92. # install deepin screenshot  
  93. echo "Now installing deepin screen shot"  
  94. echo Y | apt-get install python-xlib  
  95. dpkg -i deepin-scrot*  



转载请注明:“ 转自 :http://blog.csdn.net/longerzone/article/details/20874311”

===========

注:

文中涉及很多Debian配置方面的东西,如果大家有兴趣欢迎出门右拐看一下我之前的博文:

《Debian安装全攻略》 http://blog.csdn.net/longerzone/article/details/8075079 

《Ubuntu 下安装WPS for Linux》http://blog.csdn.net/longerzone/article/details/9010687 

《Ubuntu下创建vim+Taglist+cscope+ctags组合编辑器》 http://blog.csdn.net/longerzone/article/details/7789581


0 0
原创粉丝点击