-
Notifications
You must be signed in to change notification settings - Fork 0
/
puavo-image-repository
executable file
·223 lines (174 loc) · 4 KB
/
puavo-image-repository
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
#!/bin/bash
#default values
REPOSITORY="https://cdn.amxa.ch"
PUAVO_OS="/puavo-os"
NO_FILES=false
help(){
echo "Usage: $(basename "$0") IMAGE_DIR [MIRROR_DIR]"
echo
echo " Maintains an image repository of all images from IMAGE_DIR"
echo " in MIRROR_DIR (def: IMAGE_DIR/mirror)"
echo
echo "Options:"
echo " -r, --repository HOSTNAME set repository's hostname (def: $REPOSITORY)"
echo " -p, --puavo-os DIR set puavo-os to DIR (def: $PUAVO_OS)"
echo " -n, --no-config does not generate config, just make rdiffs"
echo " -h, --help show this message"
echo
}
lister(){
DIST="$1"
echo "{"
FIRST_S="0"
for S in ${SERIES};do
if test -z "$DIST" || echo "$S"|grep -q "$DIST"; then
if test $FIRST_S = 0 ;then
FIRST_S=1
else
echo ","
fi
echo " \"${S}-amd64\": ["
FIRST_I="0"
SEARCH="${S}-20*-amd64\\.img"
for I in $(find "$IMAGE_DIR" -maxdepth 1 -name "$SEARCH");do
if test $FIRST_I = 0 ;then
FIRST_I=1
else
echo ","
fi
echo -n " \"$(basename ${I})\""
done
echo
echo -n " ]"
fi
done
echo
echo "}"
}
list_images(){
SERIES=""
DISTRIBS=""
for I in $(find "$IMAGE_DIR" -maxdepth 1 -name '*-os-*-20*-amd64\.img'); do
OSNAME=$(basename "${I}"|cut -d- -f1)
CLASS=$(basename "${I}"|cut -d- -f3)
DIST=$(basename "${I}"|cut -d- -f4)
D="$DIST"
if ! echo "$DISTRIBS"|grep -q "${D}";then
DISTRIBS="${DISTRIBS} ${D}"
fi
S="$OSNAME-os-$CLASS-$DIST"
if ! echo "$SERIES"|grep -q "${S}";then
SERIES="${SERIES} ${S}"
fi
done
#echo $DISTRIBS -- $SERIES
if $NEW; then
rm -r $PUAVO_OS/config/images
mkdir -p $PUAVO_OS/config/images/
for D in $DISTRIBS; do
echo "$D"
lister "$D" > "$PUAVO_OS/config/images/$D.json"
done
else
mkdir -p $PUAVO_OS
lister "" > $PUAVO_OS/images.json
fi
}
make_rdiffs_alt(){
IMAGE_DIR=$1
REPOSITORY=$2
MIRROR_DIR=$3
# call make
mkdir -p "$MIRROR_DIR/.checksums"
mkdir -p "$MIRROR_DIR/.signatures"
mkdir -p "$MIRROR_DIR/meta"
mkdir -p "$MIRROR_DIR/rdiffs"
cd "${IMAGE_DIR}/.puavo-os" || exit
#needs absolute paths!!!!!!!!!!!!
sudo $PUAVO_OS/.aux/make-rdiffs \
image_dir="${IMAGE_DIR}" \
images_urlbase="${REPOSITORY}" \
mirror_dir="${MIRROR_DIR}" \
mode="production"
}
make_rdiffs(){
cat <<EOF > $PUAVO_OS/defaults.mk
image_dir := $1
images_urlbase := $2
mirror_dir := $3
debootstrap_suite := $4
EOF
ort=$(pwd)
cd $PUAVO_OS || exit
sudo make rdiffs
cd "$ort" || exit
}
main(){
NO_FILES=false
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
shift
help
exit 0
;;
-r|--repository)
shift
REPOSITORY=$1
shift
;;
-p|--puavo-os)
shift
PUAVO_OS=$1
shift
;;
-n|--no-files)
shift
NO_FILES=true
;;
--)
shift
break
;;
-*)
usage_error "invalid argument '$1'"
;;
*)
break
;;
esac
done
if ! test -d "$PUAVO_OS";then
echo "error: puavo-os installation not found"
exit 1
fi
IMAGE_DIR="$1"
if ! test -d "$IMAGE_DIR";then
echo "error: IMAGEDIR \"$IMAGE_DIR\" not found"
exit 1
fi
IMAGE_DIR=$(realpath "$IMAGE_DIR")
if test -z "$2";then
mkdir -p "$IMAGE_DIR/mirror"
MIRROR_DIR="$IMAGE_DIR/mirror"
else
MIRROR_DIR=$(realpath "$2")
fi
NEW=false
test -d $PUAVO_OS/config/images && NEW=true
# ok, here we go
if ! $NO_FILES; then list_images; fi
if $NEW; then
for DIST in $PUAVO_OS/config/images/*; do
D=$(basename -s .json $DIST)
echo make_rdiffs "$IMAGE_DIR" "$REPOSITORY" "$MIRROR_DIR" "$D"
make_rdiffs "$IMAGE_DIR" "$REPOSITORY" "$MIRROR_DIR" "$D"
done
else
make_rdiffs "$IMAGE_DIR" "$REPOSITORY" "$MIRROR_DIR" ""
fi
# fix permissions
sudo chown --recursive --reference "${IMAGE_DIR}" "${MIRROR_DIR}"
}
main "$@"
exit