树莓派开发环境自动配置脚本

简介

在安装完树莓派系统之后,总是需要进行各种环境配置和工具的安装,即浪费时间右容易出错,因此将这些配置都写成了脚本自动化执行,现将脚本写下,供以后参考使用。

自动化配置脚本

开发环境自动化配置包括:更换软件源、树莓派升级、配套工具安装、开发环境搭建

文件/文件夹 文件 描述
env dhcpcd.conf
wpa_supplicant.conf
静态网络配置
wifi配置
source raspi.list
sources.list
软件源配置
totalconfig.sh 总脚本
sourcechange.sh 更换源脚本
sourceupdate.sh 树莓派升级脚本
toolinstall.sh 配套工具安装脚本
envsetting.sh 开发环境搭建脚本

如上表所示,通过一个总脚本totalconfig.sh按顺序进行调用,完成所有配置工作:

1
2
3
4
5
6
7
8
9
#!/bin/bash
echo "开始配置..."
basepath=$(cd `dirname $0`; pwd)
source $basepath/sourcechange.sh
source $basepath/sourceupdate.sh
source $basepath/toolinstall.sh
source $basepath/envsetting.sh
echo "结束配置..."
reboot

更换软件源

sourcechange.sh

1
2
3
4
5
6
7
8
#!/bin/bash
echo "启动树莓派源配置..."
basepath=$(cd `dirname $0`; pwd)
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak
sudo cp $basepath/source/sources.list /etc/apt/sources.list
sudo cp $basepath/source/raspi.list /etc/apt/sources.list.d/raspi.list
echo "树莓派配置源成功..."

树莓派升级

sourceupdate.sh

1
2
3
4
#!/bin/bash
echo "启动树莓派软件源更新..."
sudo apt-get update && sudo apt-get -y upgrade
echo "树莓派软件源更新成功..."

配套工具安装

toolinstall.sh

1
2
3
4
#!/bin/bash
echo "安装树莓派应用软件..."
sudo apt-get install -y ttf-wqy-zenhei fcitx fcitx-googlepinyin matchbox-keyboard
echo "树莓派应用软件安装成功..."

开发环境搭建

envsetting.sh

1
2
3
4
5
6
7
8
#!/bin/bash
echo "启动树莓派环境配置..."
basepath=$(cd `dirname $0`; pwd)
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
sudo cp $basepath/env/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
sudo cp $basepath/env/dhcpcd.conf /etc/dhcpcd.conf
echo "树莓派环境配置成功..."

软件源配置文件

raspi.list

1
2
3
4
5
6
7
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspberrypi.org/debian/ stretch main ui
#deb http://archive.raspberrypi.org/debian/ stretch main ui

#清华源test
deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ stretch main ui
deb-src http://mirror.tuna.tsinghua.edu.cn/raspberrypi/ stretch main ui

sources.list

1
2
3
4
5
6
7
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
#deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi

#清华源test
deb https://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi

静态网络配置文件

参考我的另外一篇文档《树莓派内外网连接配置》

wifi配置

参考我的另外一篇文档《树莓派3B+踩坑》