forked from Edusantara/pabrik-cc
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild-image
executable file
·85 lines (77 loc) · 1.89 KB
/
build-image
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
#!/bin/bash
if [ -n "$DEBUG" ];then
set -x
fi
export INTERNALCALL=1
if [ -d /usr/share/pabrik-cc ]; then
export CC_DIR=/usr/share/pabrik-cc
elif [ -d `pwd`/pabrik-cc ];then
export CC_DIR=./pabrik-cc
fi
if [ -z $CC_DIR ];then
echo "Broken setup, CC_DIR is not found"
exit 1
fi
while getopts ":i:f:t:" opt; do
case $opt in
i)
echo "Using ID $OPTARG" >&2
export DISK_ID=$OPTARG
;;
f)
echo "Using profile from file $OPTARG" >&2
export CONFIG=$OPTARG
;;
t)
echo "Using temporary directory $OPTARG" >&2
export TMP=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
if [ -z $DISK_ID ];then
BASE=`date "+%Y%m%d"`
if [ -d $TMP/$BASE-publish ];then
for i in `seq -f "%03.0f" 1 100`;do
CHECK=$BASE-$i
if [ ! -d $TMP/$CHECK-publish ];then
export DISK_ID=$CHECK
break
fi
done
if [ -z $DISK_ID ];then
echo "There are already 100 attempts to build today, come again tomorrow"
exit 1
fi
else
export DISK_ID=$BASE
fi
echo "Using id $DISK_ID"
fi
if [ -z "$CONFIG" -o -z "$DISK_ID" -o -z "$TMP" ];then
echo "Usage: $0 -f PROFILE_FILE -i ID -t TMP_DIRECTORY"
exit 1
fi
LOG_FILE=$TMP/$DISK_ID-publish/log.txt
mkdir -p $TMP/$DISK_ID-publish
set +e
cat $CONFIG | grep -v RECIPIENT | grep -v PUBLISH > $TMP/$DISK_ID-publish/build.conf
export TIME="Time spent: %E."
echo "Configuration used:" > $LOG_FILE
cat $CONFIG >> $LOG_FILE
echo "---------------------" >> $LOG_FILE
echo "Build log:" >> $LOG_FILE
/usr/bin/time $CC_DIR/build-iso >> $LOG_FILE 2>&1
if [ $? -eq 0 ];then
echo "Success."
else
echo "Failed."
fi
set -e