-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_custom_linux_os.sh
executable file
·229 lines (195 loc) · 7.02 KB
/
build_custom_linux_os.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env bash
# Set current working directory as that of the script
cd "$(dirname "$0")"
# Function to pause the script in between so that user can confirm or read values from screen & enter them as input
pause() {
local arg=""
if [ -z "$1" ]; then
arg=""
else
arg=$1
fi
read -s -n 1 -p "$arg"
}
# Function to clean up and leave the state of the directory exactly how it was before script ran
cleanup() {
linebreak
pause "Going to cleanup. Press any key to continue.."
# Delete picore directory
[ -d picore ] && rm -r picore
}
# statuscode() {
# if [ $1 -e 0 ]; then
# printf "\nSuccess!!\n"
# else
# printf "\nError!!\n"
# fi
# }
linebreak() {
printf "\n\n"
}
# Lets create a folder in which we will download stuff
if [ ! -d picore ]; then
mkdir picore
fi
cd picore
# Download picore archive, extract & verify md5sum
# Reuse zip file its already downloaded
[ -f piCore-11.0.zip ] && echo "Reusing already downloaded piCore-11.0.zip file" || wget http://tinycorelinux.net/11.x/armv7/releases/RPi/piCore-11.0.zip
unzip -o piCore-11.0.zip # overwrite existing files during unzip
printf "MD5 verification of IMG file:"
md5sum -c piCore-11.0.img.md5.txt
####################################################
# Expand second partition to accomodate extensions #
####################################################
linebreak
pause "Going to expand second partition. Press any key to continue.."
# create destination image about 350MB (will trim once the build finishes based on how much space it occupies)
dd if=/dev/zero of=1.img bs=1K count=$((350*1024))
# loop mount the file as a device
devicePath=`losetup --show --find --partscan 1.img`
# copy original image over it
dd if=piCore-11.0.img of=$devicePath
# this is how it looks now
fdisk -l $devicePath
# expand partition 2 to the end of the file:
sudo parted -s $devicePath resizepart 2 100%
# this needs to be done before expanding the filesystem to inform the kernel the MBR changed:
e2fsck -f "${devicePath}p2"
# finally, we expand the filesystem:
resize2fs -p "${devicePath}p2"
# this is how it looks
fdisk -l 1.img
# release loop device
losetup -d $devicePath
# replace the img file we working with
rm piCore-11.0.img && mv 1.img piCore-11.0.img
# Get block start for specifying in the mount commands
linebreak
fdisk -l piCore-11.0.img
printf "\nEnter block start value of 1st partition: "
read blockstart1
printf "Enter block start value of 2nd partition: "
read blockstart2
# Create mounting points
printf "\nCreating mounting points..\n"
if [ ! -d mountpoint1 ]; then
mkdir mountpoint1
fi
if [ ! -d mountpoint2 ]; then
mkdir mountpoint2
fi
# Mount first partition
printf "Mounting 1st partition\n"
mount -o loop,offset=$((512*blockstart1)) piCore-11.0.img mountpoint1
test $? -eq 0 || ( echo "Error mounting 1st partition!!" && exit 1 )
# Modify bootcodes
# Simply copy contents, concatentate string (additional bootcodes) and overwrite the file
bootcodes=`cat mountpoint1/cmdline.txt`
bootcodes3=`cat mountpoint1/cmdline3.txt`
# Add norestore,noswap bootcode
addbootcodes="norestore noswap nozswap nodhcp waitusb=5 fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo"
bootcodes="${bootcodes} ${addbootcodes}"
bootcodes3="${bootcodes3} ${addbootcodes}"
echo $bootcodes > mountpoint1/cmdline.txt
echo $bootcodes3 > mountpoint1/cmdline3.txt
printf "Bootcodes:\n"
printf "cmdline.txt:\n"
cat mountpoint1/cmdline.txt
printf "cmdline3.txt:\n"
cat mountpoint1/cmdline3.txt
# Download overlay
wget https://github.com/goodtft/LCD-show/raw/master/usr/tft35a-overlay.dtb
mv tft35a-overlay.dtb mountpoint1/overlays/
cp mountpoint1/overlays/tft35a-overlay.dtb mountpoint1/overlays/tft35a.dtbo
# Change config.txt
echo "" >> mountpoint1/config.txt # ensure new line
echo "# For enabling camera to work" >> mountpoint1/config.txt
echo "start_x=1" >> mountpoint1/config.txt
echo "# For enabling touchscreen" >> mountpoint1/config.txt
echo "hdmi_force_hotplug=1" >> mountpoint1/config.txt
echo "dtparam=i2c_arm=on" >> mountpoint1/config.txt
echo "dtoverlay=tft35a:rotate=90" >> mountpoint1/config.txt
linebreak
pause "Press any key to continue.."
# Unmount first partition
umount mountpoint1
# Mount second partition
linebreak
printf "Mounting 2nd partition\n"
mount -o loop,offset=$((512*blockstart2)) piCore-11.0.img mountpoint2
test $? -eq 0 || ( echo "Error mounting 2nd partition!!" && exit 1 )
pause "Press any key to continue.."
# Create copy2fs.flg file under tce directory
touch mountpoint2/tce/copy2fs.flg
# Remove mydata.tgz since we won't be restoring any persistent data
rm mountpoint2/tce/mydata.tgz
# Copy Extensions fetching script(s) under tce/optional for fetching packages
# If its missing, throw error message and halt script
cd ..
[ -f fetch.sh ] && cp fetch.sh picore/mountpoint2/tce/optional || ( echo "fetch.sh is missing" && exit 1 )
cd picore
#######################
# Download extensions #
#######################
printf "\nReady to fetch extensions. "
pause "Press any key to continue.."
linebreak
cd mountpoint2/tce/optional
rm *tcz* # remove all existing extensions, we will explicitly specify what we are going to need
chmod +x fetch.sh
./fetch.sh flwm_topside
./fetch.sh Xorg
./fetch.sh wbar
./fetch.sh v4l2-utils
./fetch.sh aterm
#./fetch.sh firefox
# For chromium - start of dependencies
./fetch.sh gtk3
./fetch.sh gnutls
./fetch.sh libavahi
# For chromium - end of dependencies
pause "Extensions downloaded. Review Log.txt if you wish. Afterwards press any key to continue.."
linebreak
# Clean fetch.sh files
rm -f Log.txt Extension.list fetch.sh
cd ../../../../
#########################
# Add custom extensions #
#########################
# Add vaultapp extension
wget -O picore/mountpoint2/tce/optional/vaultapp.tcz https://woodpckr.com/vaultapp.tcz
chown 1001:50 picore/mountpoint2/tce/optional/vaultapp.tcz
# Add hacky chromium extension
wget -O picore/mountpoint2/tce/optional/chromium.tcz https://woodpckr.com/chromium.tcz
echo "gtk3.tcz" > picore/mountpoint2/tce/optional/chromium.tcz.dep
echo "gnutls.tcz" >> picore/mountpoint2/tce/optional/chromium.tcz.dep
echo "libavahi.tcz" >> picore/mountpoint2/tce/optional/chromium.tcz.dep
chown 1001:50 picore/mountpoint2/tce/optional/chromium.tcz*
# Add OS customizations extension
mksquashfs includes airgap.tcz
chown 1001:50 airgap.tcz
cp airgap.tcz picore/mountpoint2/tce/optional/
# Add extensions to onboot.lst for auto-loading
cd picore
# But first clear existing entries in it
echo "airgap.tcz" > mountpoint2/tce/onboot.lst # overwrite, not append, effectively clearing the file before writing to it
echo "Xorg.tcz" >> mountpoint2/tce/onboot.lst
echo "flwm_topside.tcz" >> mountpoint2/tce/onboot.lst
echo "wbar.tcz" >> mountpoint2/tce/onboot.lst
echo "vaultapp.tcz" >> mountpoint2/tce/onboot.lst
echo "v4l2-utils.tcz" >> mountpoint2/tce/onboot.lst
echo "aterm.tcz" >> mountpoint2/tce/onboot.lst
echo "chromium.tcz" >> mountpoint2/tce/onboot.lst
#echo "firefox.tcz" >> mountpoint2/tce/onboot.lst
# Unmount second partition
umount mountpoint2
# Copy out the modified IMG file
mv piCore-11.0.img ../airgap.img
cd ..
# Cleanup before exit
cleanup
linebreak
printf "All done!!\n"
# Clean exit
exit 0