forked from lncm/pi-factory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_cache.sh
executable file
·71 lines (52 loc) · 1.52 KB
/
make_cache.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
#!/bin/sh
# make_cache.sh
#
# updates and packages cache as cache.tar.gz
# to be run as sudo on Alpine armhf
WORLD=/etc/apk/world
#LOCATION=/media/mmcblk0p1/cache # initial cache location
NORMAL_LOCATION=/var/cache/apk # default of installed boxes
WORKDIR=/home/lncm/pi-factory/lncm-workdir
OUTPUT=cache.tar.gz
cmd_exists() {
$(command -v ${1} 2>&1 1>/dev/null;)
echo $?
}
if [ ! "$(cmd_exists apk)" -eq "0" ]; then
echo "Not an Alpine-based system, aborting"
exit 1
fi
mkdir -p ${WORKDIR}
cd ${WORKDIR} || exit
echo "Cleaning up..."
echo "Remove cache dir"
rm -rfv ${WORKDIR}/cache
echo "Remove cache tarball"
rm -v ${WORKDIR}/cache.tar.gz
echo "Making backup of ${WORLD}"
cp -v ${WORLD} ${WORLD}.backup
echo "Creating new minimal ${WORLD}"
echo -e "alpine-base" > ${WORLD}
echo -e "avahi" >> ${WORLD}
echo -e "dbus" >> ${WORLD}
echo -e "docker" >> ${WORLD}
echo -e "openssh" >> ${WORLD}
echo -e "wireless-tools" >> ${WORLD}
echo -e "wpa_supplicant" >> ${WORLD}
mkdir -p ${WORKDIR}/cache
echo "Setting apk cache to ${WORKDIR}/cache"
setup-apkcache ${WORKDIR}/cache
echo "Syncing cache"
apk update && \
apk cache sync -v --no-cache
# Disables adding resource-forks on MacOS
export COPYFILE_DISABLE=true
# echo "Copy cache files"
# cp -rv ${LOCATION} cache
echo "Bundling cache"
# Folder to be compressed must be called cache
tar cvzf ${WORKDIR}/${OUTPUT} --exclude '.DS_Store' cache
echo "Restoring previous ${WORLD}"
cp ${WORLD}.backup ${WORLD}
echo "Restoring previous apk cache location"
setup-apkcache ${NORMAL_LOCATION}