Skip to content

Commit

Permalink
V1.1
Browse files Browse the repository at this point in the history
- 增加预装软件 galculator curl python3-numpy
- 预装x11vnc及用来设置开关密码的set-vnc指令
- 增加运行前先对电脑安装的软件
- 安装blinka时增加出错后重试机制
- 多加一些报错即退出的检测位置
  • Loading branch information
sc-bin committed Sep 26, 2023
1 parent f527b9d commit d162f26
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 43 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ walnutpi-build
- 需要在ubuntu22.04上运行
- toolchain会在运行时从清华源下载
- 各种软件也是当场apt安装最新版
- 运行时要全程联网,确保能连接github

- 运行时要从github下载东西,请确保科学上网,科学上网,科学上网


0. 运行本脚本前先安装好两个软件
```
sudo apt install whiptail bc
```

1.clone
1. clone
------
```
git clone -b main --depth 1 https://github.com/walnutpi/walnutpi-build.git
```
2.run

2. run
------
```
sudo ./build.sh
Expand Down
12 changes: 6 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/bash




PATH_PWD="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
# PATH_RESOURCE="${PATH_PWD}/resource"
PATH_SOURCE="${PATH_PWD}/source"
Expand Down Expand Up @@ -87,7 +84,7 @@ source $CONF_DIR/$(basename "$CONF_DIR").conf
FILE_CROSS_COMPILE="${PATH_TOOLCHAIN}/${TOOLCHAIN_FILE_NAME}/bin/${CROSS_COMPILE}"


source "${PATH_PWD}"/scripts/common.sh

source "${PATH_PWD}"/scripts/compile.sh
source "${PATH_PWD}"/scripts/rootfs.sh
source "${PATH_PWD}"/scripts/pack.sh
Expand All @@ -103,9 +100,12 @@ esac

echo "apt install software"

apt update
apt install qemu-user-static debootstrap kpartx git bison flex swig libssl-dev device-tree-compiler u-boot-tools -y
source "${PATH_PWD}"/scripts/common.sh

apt update
exit_if_last_error
apt install qemu-user-static debootstrap kpartx git bison flex swig libssl-dev device-tree-compiler u-boot-tools make python3 python3-dev -y
exit_if_last_error

if [ ! -f "${FILE_CROSS_COMPILE}gcc" ]; then
# echo "解压$FILE_CROSS_COMPILE"
Expand Down
2 changes: 2 additions & 0 deletions fs-build/apt-list/base
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ bash-completion
systemd-timesyncd
parted
wget
curl
fdisk

fbterm
locales
Expand Down
2 changes: 2 additions & 0 deletions fs-build/apt-list/desktop
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ lightdm
xserver-xorg-input-evdev
xserver-xorg-input-synaptics
xinput-calibrator
x11vnc

menulibre
dmz-cursor-theme
Expand All @@ -22,6 +23,7 @@ thonny
geany
ristretto
vlc
galculator

chromium
chromium-driver
Expand Down
1 change: 1 addition & 0 deletions fs-build/pip-list
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
jedi
numpy
21 changes: 3 additions & 18 deletions fs-build/script/base/hcitools.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
#!/bin/bash
set -e
run_as_client_try3() {
local max_attempts=3
local attempt=0
local success=0

while [[ $attempt -lt $max_attempts && $success -eq 0 ]]; do
output=$("$@" 2>&1)
if [ $? -eq 0 ]; then
success=1
else
attempt=$((attempt + 1))
fi
done

if [[ $success -eq 0 ]]; then
echo "$output"
fi
run_as_client() {
$@ > /dev/null 2>&1
}


run_as_client_try3 git clone https://github.com/walnutpi/hcitools.git
git clone https://github.com/walnutpi/hcitools.git

cd hcitools
make
Expand Down
19 changes: 18 additions & 1 deletion fs-build/script/base/set-lcd-install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
#!/bin/bash
set -e
run_as_client_try_many () {
local max_attempts=5
local attempt=0
local success=0

git clone https://github.com/walnutpi/set-lcd.git
while [[ $attempt -lt $max_attempts && $success -eq 0 ]]; do
output=$("$@" 2>&1)
if [ $? -eq 0 ]; then
success=1
else
attempt=$((attempt + 1))
fi
done

echo "$output"
}


run_as_client_try_many git clone https://github.com/walnutpi/set-lcd.git

cd set-lcd
chmod +x install
Expand Down
25 changes: 13 additions & 12 deletions fs-build/script/base/walnut_tool.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -e

run_as_client_try3() {
local max_attempts=3
run_as_client_try_many () {
local max_attempts=5
local attempt=0
local success=0

Expand All @@ -15,26 +15,27 @@ run_as_client_try3() {
fi
done

if [[ $success -eq 0 ]]; then
echo "$output"
fi
echo "$output"
}

chmod 777 /opt

cd /opt

run_as_client_try3 git clone https://github.com/sc-bin/aw.gpio.git
run_as_client_try3 git clone https://github.com/walnutpi/Adafruit_Blinka.git
run_as_client_try3 git clone https://github.com/walnutpi/WiringPi.git
echo "start to clone aw.gpio"
run_as_client_try_many git clone https://github.com/sc-bin/aw.gpio.git
echo "start to clone blinka"
run_as_client_try_many git clone https://github.com/walnutpi/Adafruit_Blinka.git
echo "start to clone WiringPi"
run_as_client_try_many git clone https://github.com/walnutpi/WiringPi.git


echo "Adafruit_Blinka"
pip3 install -e Adafruit_Blinka/
run_as_client_try_many pip3 install -e Adafruit_Blinka/
echo "aw.gpio"
pip3 install -e aw.gpio/
run_as_client_try_many pip3 install -e aw.gpio/
echo "WiringPi"
cd WiringPi/
./build

run_as_client_try_many ./build

echo "end"
12 changes: 12 additions & 0 deletions fs-build/script/desktop/resource/completion-set-vnc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

_set-vnc () {
local cur=${COMP_WORDS[COMP_CWORD]}
if [ $COMP_CWORD -eq 1 ]; then
local functions=$(grep -oP '^[^_]\w+\s*\(\)' /usr/bin/set-vnc | sed 's/()//')
COMPREPLY=($(compgen -W "$functions" -- $cur))
fi
}
complete -F _set-vnc set-vnc


63 changes: 63 additions & 0 deletions fs-build/script/desktop/resource/set-vnc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

-h() {
echo -e "\n"
echo -e "set-vnc enable :"
echo -e " enable the x11vnc service \n"

echo -e "set-vnc disable :"
echo -e " disable the x11vnc service \n"

echo -e "set-vnc password [newpassword] :"
echo -e " set the x11vnc connect password "
echo -e " examples: \n\tset-vnc password pi\n"

echo -e "set-vnc port [newport] :"
echo -e " set the x11vnc connect port"
echo -e " examples: \n\tset-vnc port 5900\n"

}
enable() {
systemctl enable x11vnc.service
echo -e "\n\nplease reboot\n"
}

disable() {
systemctl disable x11vnc.service
echo -e "\n\nplease reboot\n"
}
password() {
if [ ! -z "$1" ]; then
x11vnc -storepasswd $1 /etc/x11vnc.pwd
else
echo "Command error!"
fi
}
port() {

if [[ $1 =~ ^[0-9]{1,5}$ ]]; then
sed -i -r "s/(-rfbport[[:space:]]{1,5})[0-9]{1,5}/\1$1/" /lib/systemd/system/x11vnc.service
echo "ok"
else
echo "Command error!"
fi
echo -e "\n\nplease reboot\n"



}
FUNCTION_NAME=$1
VALUE=$2


# 检查是否有同名的函数
if declare -F "$FUNCTION_NAME" >/dev/null; then
$FUNCTION_NAME $VALUE
else
-h
fi

# set-vnc enable
# set-vnc disable
# set-vnc password
# set-vnc port
12 changes: 12 additions & 0 deletions fs-build/script/desktop/resource/x11vnc.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Expand partition size
After=graphical.target

[Service]
Type=oneshot
ExecStart=x11vnc -display :0 -auth guess -rfbport 5900 -rfbauth /etc/x11vnc.pwd -capslock -nomodtweak -repeat -forever
RemainAfterExit=yes
StandardOutput=null

[Install]
WantedBy=graphical.target
18 changes: 18 additions & 0 deletions fs-build/script/desktop/set-vnc-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

PATH_PWD="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"

mv set-vnc /usr/bin/
chmod +x /usr/bin/set-vnc

mv completion-set-vnc /etc/bash_completion.d/set-vnc
chmod +x /etc/bash_completion.d/set-vnc
# source /etc/bash_completion.d/set-vnc

bash_str="source /etc/bash_completion.d/set-vnc"
if ! grep -q ${bash_str} /etc/bash.bashrc; then
echo ${bash_str} >> /etc/bash.bashrc
fi
mv x11vnc.service /lib/systemd/system/
x11vnc -storepasswd pi /etc/x11vnc.pwd
2 changes: 1 addition & 1 deletion scripts/pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ do_pack() {

# echo "开始格式化"
run_status "format part 1" mkfs.vfat $MAPPER_DEVICE1
run_status "format part 1" mkfs.ext4 $MAPPER_DEVICE2
run_status "format part 2" mkfs.ext4 $MAPPER_DEVICE2


BOOT_UUID=$(blkid -s UUID -o value $MAPPER_DEVICE1)
Expand Down
8 changes: 7 additions & 1 deletion scripts/rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ create_rootfs() {
cp -r $PATH_SAVE_ROOTFS $PATH_ROOTFS
else
run_as_client mkdir ${PATH_ROOTFS} -p
debootstrap --foreign --verbose --arch=${CHIP_ARCH} ${OPT_OS_VER} ${PATH_ROOTFS} http://mirrors.huaweicloud.com/debian/
debootstrap --foreign --verbose --arch=${CHIP_ARCH} ${OPT_OS_VER} ${PATH_ROOTFS} http://mirrors.tuna.tsinghua.edu.cn/debian/
# debootstrap --foreign --verbose --arch=${CHIP_ARCH} ${OPT_OS_VER} ${PATH_ROOTFS} http://ftp.cn.debian.org/debian/
# debootstrap --foreign --verbose --arch=${CHIP_ARCH} ${OPT_OS_VER} ${PATH_ROOTFS} http://mirrors.huaweicloud.com/debian/
exit_if_last_error

qemu_arch=""
case "${CHIP_ARCH}" in
"arm64")
Expand All @@ -100,6 +104,8 @@ create_rootfs() {
cd ${PATH_ROOTFS}
mount_chroot $PATH_ROOTFS
LC_ALL=C LANGUAGE=C LANG=C chroot ${PATH_ROOTFS} /debootstrap/debootstrap --second-stage –verbose
exit_if_last_error

# cd ${PATH_ROOTFS}
umount_chroot $PATH_ROOTFS
cp -r $PATH_ROOTFS $PATH_SAVE_ROOTFS
Expand Down

0 comments on commit d162f26

Please sign in to comment.