-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_image.sh
executable file
·119 lines (93 loc) · 2.54 KB
/
gen_image.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
#!/bin/sh
#Retreive current folder (folder of current script, not working folder)
DIR="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
#manage command line arguements
LANG=EN
DEPLOY_TO_CUSTOM_DIR=NO
for i in "$@"
do
case $i in
-lfr|--lang_french)
LANG=FR
shift
;;
-len|--lang_english)
LANG=EN
shift
;;
-d=*|--deploy=*)
DEPLOY_TO_CUSTOM_DIR=YES
DEPLOY_DIR="${i#*=}"
shift
;;
*)
# unknown option
;;
esac
done
#retreive version from currently built file
export yadomsVersion=`ls Yadoms*.tar.gz | head -1 | grep -oP '(?<=-).*(?=-)'`
if [ $? -ne 0 ]; then echo "ERROR : Fail to find Yadoms binaries. Exit "; exit 1; fi
echo "Found Yadoms : $yadomsVersion"
cd pi-gen
if [ $LANG = "FR" ]; then
# Generate FR image
sudo cp $DIR/config_fr ./config
else
# Generate EN image
sudo cp $DIR/config_en ./config
fi
# disable stage 3, 4 and 5 from pi-gen
sudo rm -Rf stage3
sudo rm -Rf stage4
sudo rm -Rf stage5
#sudo touch ./stage3/SKIP ./stage4/SKIP ./stage5/SKIP
#sudo touch ./stage4/SKIP_IMAGES ./stage5/SKIP_IMAGES
#disable generation of raspbian-lite image (our custom stage will generate raspbian-lite-yadoms)
sudo touch ./stage2/SKIP_IMAGES
# copy stage99
if [ -d "stage99" ]; then
sudo rm -Rf stage99
fi
sudo cp -rp $DIR/stage99 .
sudo cp ../Yadoms-$yadomsVersion-RaspberryPI.tar.gz ./stage99/02-yadoms/yadoms.tar.gz
sudo chmod 777 ./stage99/02-yadoms/yadoms.tar.gz
sudo mv stage99 stage3
if [ -f stage3/EXPORT_NOOBS ]; then
sudo rm -f stage3/EXPORT_NOOBS
fi
#patch pi-gen (make it work within docker inside docker)
#sudo cp $DIR/patch/img_prerun.sh ./export-image/prerun.sh
#sudo cp $DIR/patch/noob_prerun.sh ./export-noobs/prerun.sh
#sudo chmod +x ./export-image/prerun.sh
#sudo chmod +x ./export-noobs/prerun.sh
if [ -d "work" ]; then
sudo rm -Rf work
fi
#detach any loop
sudo losetup --detach-all
# generate image
sudo ./build.sh
if [ $? -ne 0 ]; then echo "ERROR : Fail to make Yadoms Raspian images. Exit "; exit 1; fi
echo "current dir = $(pwd)"
echo "Listing dir"
ls -al
echo "Listing dir deploy"
ls -al deploy
#copy images to output folder
if [ $DEPLOY_TO_CUSTOM_DIR = "YES" ]; then
if [ ! -d "${DEPLOY_DIR}" ]; then
echo "Creating folder ${DEPLOY_DIR}"
mkdir -p ${DEPLOY_DIR}
fi
echo "Move resultig image to ${DEPLOY_DIR}"
sudo mv deploy/* ${DEPLOY_DIR}
sudo chmod -R 777 ${DEPLOY_DIR}
echo "Listing DEPLOY_DIR : ${DEPLOY_DIR}"
ls -al
else
echo "No output folder provided"
echo "Deploy folder is $(pwd)/deploy"
fi
#delete container
#sudo docker rm -v pigen_work || true