forked from lunar-linux/lunar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.lunar
115 lines (103 loc) · 3.51 KB
/
logging.lunar
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
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/logging.lunar #
# #
############################################################
start_logging () {
debug_msg "start_logging ($@)"
export C_LOG=$(temp_create "${MODULE}.compile-log")
export C_FIFO=$(temp_create "${MODULE}.compile-fifo")
# just remaking this as FIFO
rm -f $C_FIFO
mknod $C_FIFO p
echo "++ Mark Compile start : \"$MODULE\" \"$VERSION\" \"$(date -Ru)\"" > $C_LOG
activate_voyeur
}
stop_logging() {
debug_msg "stop_logging ($@)"
# Make sure the FIFO gets closed
echo > $C_FIFO
echo "++ Mark Compile stop : \"$MODULE\" \"$VERSION\" \"$(date -Ru)\"" >> $C_LOG
message "${MESSAGE_COLOR}Creating" \
"${FILE_COLOR}$COMPILE_LOGS/$MODULE-$VERSION.${COMPRESS_METHOD}" \
"${DEFAULT_COLOR}"
${COMPRESS_METHOD/bz2/bzip2} -9f $COMPRESS_METHOD_ARGS < $C_LOG > $COMPILE_LOGS/$MODULE-$VERSION.${COMPRESS_METHOD}
temp_destroy $C_LOG
temp_destroy $C_FIFO
}
progress() {
local OLDLOG OLDSZ S PC
OLDLOG=$(ls -1d $COMPILE_LOGS/$MODULE-*.{xz,bz2} 2>&- | head -n 1)
STIME=$(date +%s)
if [[ -f $OLDLOG ]]; then
X="############################################################"
Y=" "
OLDSZ=$(xzbz -dc $OLDLOG | wc -c)
OLDTIMES=($(xzbz -dc $OLDLOG | grep 'Mark Compile ' | cut -d \" -f6 | while read TIME ; do date +%s -d "$TIME" ; done))
CTIME=$((${OLDTIMES[1]} - ${OLDTIMES[0]}))
echo "Last compile time: $((CTIME / 60))m$((CTIME % 60))s"
while true ; do
read -t 2 LINE
STATUS=$?
if [ $STATUS -gt 128 ]; then
sleep 2
continue
elif [ $STATUS -eq 1 ]; then
echo -ne "\r [${X:0:60}] (100%)\n"
exit
fi
(( S += ${#LINE} ))
if [[ $S -gt OLDSZ ]]; then
# never print 100% - subtract 1 :)
S=$((OLDSZ - 1))
fi
PC=$((S * 100 / OLDSZ))
L=$((S * 60 / OLDSZ))
CTIME=$(($(date +%s) - $STIME))
echo -ne "\r [${X:0:$L}${Y:0:$((60 - L))}] ($PC%) $((CTIME / 60))m$((CTIME % 60))s \r"
done
else
SPINNER="/-\|"
# spinerrrrrr!!!!
while true ; do
read -t 2 LINE
STATUS=$?
if [ $STATUS -gt 128 ]; then
sleep 2
continue
elif [ $STATUS -eq 1 ]; then
echo -ne "\r [#]\n"
exit
fi
((C++))
if [[ $C -gt $((${#SPINNER} - 1)) ]]; then
C=0
fi
CTIME=$(($(date +%s) - $STIME))
echo -en "\r [${SPINNER:$C:1}] $((CTIME / 60))m$((CTIME % 60))s \r"
done
fi
}
activate_voyeur() {
debug_msg "activate_voyeur ($@)"
if [ -z "$SILENT" ] ; then
case $VOYEUR in
on) ( tee -a $C_LOG < $C_FIFO ; rm -f "$C_FIFO" ) & ;;
p*) ( tee -a $C_LOG < $C_FIFO | progress ; rm -f "$C_FIFO" ) & ;;
*) ( tee -a $C_LOG < $C_FIFO >/dev/null ; rm -f "$C_FIFO" ) & ;;
esac
else
( tee -a $C_LOG < $C_FIFO >/dev/null ; rm -f "$C_FIFO" ) &
fi
}
activity_log() {
debug_msg "activity_log ($@)"
lock_file $ACTIVITY_LOG &&
echo -e "$(date -u +%Y%m%d-%T)\t$1\t$2\t$3\t$4\t$5" >> $ACTIVITY_LOG
unlock_file $ACTIVITY_LOG
}