File: auto_update.cron

package info (click to toggle)
astk 1.13.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 4,908 kB
  • sloc: tcl: 24,251; python: 19,546; sh: 279; makefile: 51
file content (119 lines) | stat: -rwxr-xr-x 2,799 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

# cron script to update (and build) Code_Aster versions

# versions to update (space separated)
VERSIONS_TO_UPDATE="NEW11"

# versions to build (without needing to update them, space separated)
VERSIONS_TO_BUILD=

# recipients emails of the update report
MAIL_DEST=

# Example of /etc/cron.d/aster :
## MIN HOUR DAY MONTH DAYOFWEEK USER  COMMAND
#00 05  *  *  4 aster ?ASTER_ROOT?/bin/auto_update.cron

# Example of /etc/logrotate.d/aster :
#?ASTER_ROOT?/log/auto_update.log {
#    compress
#    delaycompress
#    notifempty
#    rotate 3
#    size 300k
#    create 644 aster aster
#}


# Code_Aster root directory

if [ -z "$ASTER_ETC" ]; then
    ASTER_ETC=/etc
    export ASTER_ETC
fi

# set environment
if [ -f $ASTER_ETC/codeaster/profile.sh ]; then
    . $ASTER_ETC/codeaster/profile.sh
fi

set_prefix() {
   local here=`readlink -n -f $1`
   local bin=`dirname $here`
   ASTER_ROOT=`dirname $bin`
}
set_prefix $0

# log file, error file, pid file (could be put in /var/log, /var/run)
LOG_FILE=${ASTER_ROOT}/log/auto_update.log
ERR_FILE=${ASTER_ROOT}/log/auto_update.err
PID_FILE=${ASTER_ROOT}/log/auto_update.pid

loc="--nolocal"
if [ $# -gt 0 ]; then
   if [ "$1" = "--local" ]; then
      loc=$1
   fi
fi

if [ ! -d ${ASTER_ROOT}/log ]; then
    mkdir -p ${ASTER_ROOT}/log
fi

touch ${LOG_FILE}
rm -f ${ERR_FILE}
touch ${ERR_FILE}
cat <<EOF >> ${LOG_FILE}
================================================================================
  DATE : `date`
================================================================================


EOF

# check if another instance is already running.
if [ ! -f ${PID_FILE} ]; then
    echo $$ > ${PID_FILE}
else
    jn=`cat ${PID_FILE}`
    echo "$0 is already running with process #$jn." >> ${LOG_FILE}
    exit 1
fi

# auto_update
for vers in `echo ${VERSIONS_TO_UPDATE}`
do
   cat <<EOF >> ${LOG_FILE}

================================================================================
  UPDATE VERSION : ${vers}
================================================================================

EOF
   /usr/bin/as_run --auto_update ${loc} \
                            --report_to=${MAIL_DEST} \
                            --vers=${vers} \
                                                >> ${LOG_FILE} 2>> ${ERR_FILE}
done


# make
for vers in `echo ${VERSIONS_TO_BUILD}`
do
   cat <<EOF >> ${LOG_FILE}

================================================================================
  MAKE VERSION : ${vers}
================================================================================

EOF
   /usr/bin/as_run --make \
                            --report_to=${MAIL_DEST} \
                            --vers=${vers} \
                                                >> ${LOG_FILE} 2>> ${ERR_FILE}
done

rm -f ${PID_FILE}

exit 0