-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·192 lines (156 loc) · 7.12 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
unalias -a
# Find dir of build.sh and go there
current_dir="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
# check for whitespace in ${current_dir} and exit for safety reasons
grep -q "[[:space:]]" <<<"${current_dir}" && { echo "\"${current_dir}\" contains whitespace. Aborting." >&2 ; exit 1 ; }
cd "${current_dir}" || exit
DIALOG_CANCEL=1
DIALOG_ESC=255
BACKTITLE="AP230 kernel build script" #BACKTITLE="WDMC kernel & rootfs build script"
source "${current_dir}"/inc/helpers.sh
source "${current_dir}"/inc/kernel.sh
#source "${current_dir}"/inc/rootfs.sh
############################################################
### (SUB) DIRECTORIES TO USE
############################################################
output_dir="${current_dir}/output"
rootfs_dir="${output_dir}/rootfs"
boot_dir="${output_dir}/boot"
cache_dir="${current_dir}/cache"
current_user="$(stat --format %U "${current_dir}"/.git)"
############################################################
### Begin figuring out configuration
############################################################
GHRUNNER='off'
THREADS=8
EXTRA_PKGS='bash-completion htop'
# start by reading command line arguments
read_arguments "$@"
#if [[ "${EUID}" != "0" ]] && [[ $GHRUNNER != 'on' ]]; then
# echo "This script requires root privileges, please rerun using sudo"
# exit 1
#fi
if [[ $GHRUNNER != 'on' ]]; then
echo "### Will try to use apt to install prerequisites."
apt-get install build-essential bc libncurses5 dialog u-boot-tools git libncurses-dev lib32z1 lib32ncurses5-dev libmpc-dev libmpfr-dev libgmp3-dev flex bison debootstrap debian-archive-keyring qemu-user-static gcc-arm-none-eabi
fi
# calculate dialog sizes
exec 3>&1
dsize=$(dialog --print-maxsize 2>&1 1>&3)
exec 3>&-
dsize=( $(echo "$dsize" | grep -o -E '[0-9]+') )
DIALOG_HEIGHT=$((${dsize[0]} - 12))
DIALOG_WIDTH=$((${dsize[1]} - 8))
# if command line has selected neither kernel nor rootfs we can assume, no selection was done and ask user
if [[ -z $BUILD_KERNEL ]] && [[ -z $BUILD_ROOTFS ]]; then
# set sensible defaults
BUILD_KERNEL='on'
CLEAN_KERNEL_SRC='on'
ALLOW_KERNEL_CONFIG_CHANGES='on'
# BUILD_ROOTFS='on'
# ALLOW_ROOTFS_CHANGES='off'
# ALLOW_CMDLINE_CHANGES='off'
# ASK_EXTRA_PKGS='off'
# ZRAM_ENABLED='on'
# Show user checklist to select
display_checklist "Build setup" "Select components and options for build:" \
"1" "Linux Kernel" "$BUILD_KERNEL" \
"2" "Clean Kernel sources" "$CLEAN_KERNEL_SRC" \
"3" "Allow Kernel config changes" "$ALLOW_KERNEL_CONFIG_CHANGES" \
# "4" "Debian Rootfs" "$BUILD_ROOTFS" \
# "5" "Pause to allow rootfs changes via filesystem" "$ALLOW_ROOTFS_CHANGES" \
# "6" "Enter bash in rootfs for manual changes" "$ALLOW_CMDLINE_CHANGES" \
# "7" "Ask for extra apt pkgs" "$ASK_EXTRA_PKGS" \
# "8" "Enable ZRAM on rootfs" "$ZRAM_ENABLED"
# Accept user choices
BUILD_KERNEL='off'
CLEAN_KERNEL_SRC='off'
ALLOW_KERNEL_CONFIG_CHANGES='off'
BUILD_ROOTFS='off'
ALLOW_ROOTFS_CHANGES='off'
ALLOW_CMDLINE_CHANGES='off'
ASK_EXTRA_PKGS='off'
ZRAM_ENABLED='off'
[[ $selection == *1* ]] && BUILD_KERNEL='on'
[[ $selection == *2* ]] && CLEAN_KERNEL_SRC='on'
[[ $selection == *3* ]] && ALLOW_KERNEL_CONFIG_CHANGES='on'
[[ $selection == *4* ]] && BUILD_ROOTFS='on'
[[ $selection == *5* ]] && ALLOW_ROOTFS_CHANGES='on'
[[ $selection == *6* ]] && ALLOW_CMDLINE_CHANGES='on'
[[ $selection == *7* ]] && ASK_EXTRA_PKGS='on'
[[ $selection == *8* ]] && ZRAM_ENABLED='on'
else # at least kernel or rootfs has been selected via command line, check other options and set defaults
[[ -z $CLEAN_KERNEL_SRC ]] && CLEAN_KERNEL_SRC='on'
[[ -z $ALLOW_KERNEL_CONFIG_CHANGES ]] && ALLOW_KERNEL_CONFIG_CHANGES='off'
[[ -z $ALLOW_ROOTFS_CHANGES ]] && ALLOW_ROOTFS_CHANGES='off'
[[ -z $ASK_EXTRA_PKGS ]] && ASK_EXTRA_PKGS='off'
[[ -z $ZRAM_ENABLED ]] && ZRAM_ENABLED='on'
fi
# inquire about further kernel configuration
if [[ $BUILD_KERNEL == "on" ]] && [ -z "$kernel_branch" ]; then
display_select "Kernel Building" "Please select the Linux Kernel branch to build." \
"v3.16.36" "Vendor kernel" \
"linux-5.17.y" "Linux kernel 5.17" \
############################################################
# Select crosscompiler.
# - For older kernel version use the
# included one in toolchain. It has been generated by
# crosstools for linux 3.16 and old gcc.
# - For newer kernel use gcc-arm-linux-gnueabi from apt
# Adjust makehelp to match path to your gcc...
############################################################
makehelp='make CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- ARCH=arm' # default
if [[ $selection == "v3.16.36" ]]; then
#makehelp='make CROSS_COMPILE=/opt/arm-hsth-linux-gnueabi/bin/arm-hsth-linux-gnueabi- ARCH=arm LOCALVERSION='
display_result "Warning" "You have selected Linux Kernel 3.16, this will be build with older toolchain, make sure you have extracted the txz file available in toolchain folder to /opt/"
fi
kernel_branch="$selection"
fi
BACKTITLE+=" | "${kernel_branch}
# only allow building initramfs if rootfs build is enabled
if [[ $BUILD_ROOTFS == "on" ]] && [[ -z $BUILD_INITRAMFS ]]; then
display_select "Build initramfs" "Do you want to build the initramfs?" \
"y" "yes" \
"n" "no"
BUILD_INITRAMFS='off'
[[ $selection == "y" ]] && BUILD_INITRAMFS='on'
fi
# get details for building the rootfs
if [[ $BUILD_ROOTFS == "on" ]]; then
if [ -z "$release" ]; then
display_select "Rootfs creation" "Please select the Debian release to build." \
"buster" "Debian Buster" \
"bullseye" "Debian Bullseye"
release=$selection
fi
if [[ "$ASK_EXTRA_PKGS" == 'on' ]]; then
display_input "Rootfs creation" "Type in any extra apt packages you want install. (Space seperated)" "$EXTRA_PKGS"
EXTRA_PKGS="$selection"
fi
if [[ -z "$BOOT_DEVICE" ]]; then
display_select "Rootfs creation" "Please select which fstab to setup?" \
"usb" "For usage with USB stick (boot on sdb1, root on sdb2)" \
"hdd" "For usage with internal HDD (boot&root on sda3, data on sda2)"
BOOT_DEVICE="$selection"
fi
if [[ "$BOOT_DEVICE" != "hdd" ]] && [[ "$BOOT_DEVICE" != "usb" ]]; then
display_select "Rootfs creation" "Invalid boot device selected! Please choose:" \
"usb" "For usage with USB stick (boot on sdb1, root on sdb2)" \
"hdd" "For usage with internal HDD (boot&root on sda3, data on sda2)"
BOOT_DEVICE="$selection"
fi
if [ -z "$root_pw" ]; then
# Adjust default root pw
display_input "Rootfs creation" "Type in the root password (Warning, root ssh will be enabled)" "1234"
root_pw="$selection"
fi
if [ -z "$def_hostname" ]; then
# Adjust hostname here
display_input "Rootfs creation" "Type in the hostname for the WDMC" "wdmycloud"
def_hostname="$selection"
fi
fi
BACKTITLE+=" | "${release}
[[ $BUILD_KERNEL == "on" ]] && build_kernel
[[ $BUILD_ROOTFS == "on" ]] && build_root_fs