raspberry pi 自动初始化脚本

  玩了几天,打算刷一下。但是很多要升级也挺麻烦,直接写了个脚本,自动升级。大家如果还有自己需要的,也可以自行添加,这样初始就方便多了。
  先修改成亚洲的源
$ sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
$ sudo vi /etc/apt/sources.list
deb http://mirror.nus.edu.sg/raspbian/raspbian wheezy main contrib non-free rpi
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ wheezy main contrib non-free rpi

  如果直接用我的脚本命令如下:
$ wget http://www.simonzhang.net/wp-content/uploads/2012/12/pisystemupdate.py_.gz
$ gunzip pisystemupdate.py_.gz ;chmod a+x pisystemupdate.py_;python pisystemupdate.py_
不知道为什么加了个尾巴

  脚本内容如下:

#!/bin/env python
# -*- coding:utf-8 -*-
# Revision:
# Date:        2012-12-10
# Author:      simonzhang
# Email:       simon-zzm@163.com
# Web:         www.simonzhang.net
# -------------------------------
import os
import time

def SystemUpdate():   #系统升级
    try:
        os.system('sudo apt-get -y update')
        _get = 'ok'
    except:
        _get = 'ERROR'
    return _get

def Timing():   #校时
    try:
        os.system('sudo cp /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime')
        os.system('sudo apt-get install -y ntpdate')
        os.system('sudo /usr/sbin/ntpdate stdtime.gov.hk')
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get


def Vncserver():    #远程桌面
    try:
        os.system('sudo apt-get install -y tightvncserver') 
        _get = 'ok'
    except:
        _get = 'ERROR'
    return _get


def DevelopTool():    #开发工具
    try:
        os.system('sudo apt-get install -y gcc make')
        _get = 'ok'
    except:
        _get = 'ERROR'
    return _get

def SystemTools():    #系统常用工具
    try:
        os.system('sudo apt-get install -y bison gawk vim chkconfig') 
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get


def PythonTools():   #python 管理工具
    try:
        os.system('wget -q http://peak.telecommunity.com/dist/ez_setup.py')
        os.system('sudo python ez_setup.py')
        os.system('sudo easy_install pygame')
        _get = 'ok'
    except:
        _get = 'ERROR'
    return _get

	
def PythonImage():    #python的图片处理
    try:
	os.system('sudo apt-get install -y libjpeg*-dev')
	os.system('sudo apt-get install -y python-imaging') 
	os.system('sudo apt-get install -y python-dev')
	os.system('sudo easy_install tornado PIL')
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get


def PythonFrame():    #python框架
    try:
        os.system('sudo easy_install tornado Django')
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get

def OpenCV():   #摄像头
    try:
        os.system('sudo apt-get install -y python-opencv')
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get


def InstallMysql():   #数据库,密码为pi
    try:
	os.system('sudo debconf-set-selections <<< \'mysql-server-5.5 mysql-server/root_password password pi\'')
	os.system('sudo debconf-set-selections <<< \'mysql-server-5.5 mysql-server/root_password_again password pi\'')
	os.system('sudo apt-get -y install mysql-server')
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get


def Installjava():   #java环境
    try:
	os.system('sudo apt-get install -y openjdk-7-jdk')
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get

def ChineseFont():   #中文字体
    try:
	os.system('sudo apt-get install -y ttf-wqy-microhei')
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get
	
def InputMethod():   #输入法
    try:
	os.system('sudo apt-get install -y scim scim-pinyin')
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get

	
def AudioDriver():   #音频
    try:
        os.system('sudo apt-get install -y alsa-utils')
        os.system('sudo modprobe snd_bcm2835')
	_get = 'ok'
    except:
        _get = 'ERROR'
    return _get

	
def main():
    install_list = [SystemUpdate, \
                    Timing, \
                    Vncserver, \
                    DevelopTool, \
                    SystemTools, \
                    PythonTools, \
                    PythonImage, \
                    PythonFrame, \
                    OpenCV, \
                    InstallMysql, \
                    Installjava, \
                    ChineseFont, \
                    InputMethod,  \
                    AudioDriver, \
                    SystemUpdate,
                   ]
    for il in install_list:
        print '*' * 50
        print ': %s start' % il
        print '*' * 50
        install_status = il()
        nt = time.localtime()
        log_time = "%s-%s-%s %s:%s:%s" % (nt[2], nt[2], nt[3], nt[4], nt[5], nt[6])
        log_file = open("pi_install.log", "ab")
        log_file.write("%s %s install %s\n" % (log_time, il, install_status))
        log_file.close()
    os.system('sudo apt-get upgrade -y')
    print "Install all end."


if __name__ == '__main__':
    main()

pisystemupdate.py

发表评论

电子邮件地址不会被公开。 必填项已用*标注