source: trunk/base/portmgr/IndexRegen.sh @ 15631

Last change on this file since 15631 was 15631, checked in by jmpp, 15 years ago

Bug: 6258
Submitted by: dluke@
Reviewed by: jmpp@

The script now uses a lock file to check for an already running indexing.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.3 KB
Line 
1#!/bin/bash
2
3####
4# PortIndex regen automation script.
5# Created by Juan Manuel Palacios,
6# e-mail: jmpp@opendarwin.org
7# Updated by Paul Guyot, <pguyot@kallisys.net>
8# $Id: IndexRegen.sh,v 1.2 2005/12/29 16:43:03 jmpp Exp $
9####
10
11# Configuration
12LOCKFILE=/tmp/.dp_index_regen.lock
13# ROOT directory, where everything is. This must exist.
14ROOT=/Users/pguyot/dp-portindex
15# SSH key. This must exist.
16SSH_KEY=${ROOT}/id_dsa
17# DP user.
18DP_USER=pguyot
19# DP group.
20DP_GROUP=darwinports
21# CVS user.
22CVS_USER=pguyot
23# e-mail address to spam in case of failure.
24SPAM_LOVERS=portmgr@opendarwin.org
25
26# Other settings (probably don't need to be changed).
27# CVS root.
28CVS_ROOT=:ext:${CVS_USER}@cvs.opendarwin.org:/Volumes/src/cvs/od
29#CVS_ROOT=/Volumes/src/cvs/od # <-- direct access on the same box.
30# CVS module.
31CVS_MODULE=darwinports
32# Wrapper. This gets created.
33SSH_WRAPPER=${ROOT}/ssh_wrapper
34# Where to checkout the source code. This gets created.
35TREE=${ROOT}/source
36# Where DP will install its world. This gets created.
37PREFIX=${ROOT}/opt/local
38# Where DP installs darwinports1.0. This gets created.
39TCLPKG=${PREFIX}/lib/tcl
40# Path.
41PATH=${PREFIX}/bin:/bin:/usr/bin
42# Log for the e-mail in case of failure.
43FAILURE_LOG=${ROOT}/failure.log
44# Something went wrong.
45FAILED=0
46# Commit message.
47COMMIT_MSG=${ROOT}/commit.msg
48# The date.
49DATE=$(date +'%A %Y-%m-%d at %H:%M:%S')
50
51if [ ! -e $LOCKFILE ]; then
52        touch $LOCKFILE
53else
54        echo "Index Regen lockfile found, is another index regen running?"
55        exit 1
56fi
57
58# Create the SSH wrapper if it doesn't exist (comment this for -d /Volumes...)
59if [ ! -e $SSH_KEY ]; then
60        echo "Key doesn't exist. The script is configured to find the SSH key at:"
61        echo "${SSH_KEY}"
62        exit 1
63fi
64
65# Create the SSH wrapper if it doesn't exist  (comment this for -d /Volumes...)
66if [ ! -x $SSH_WRAPPER ]; then
67        echo "#!/bin/bash" > $SSH_WRAPPER && \
68        echo "/usr/bin/ssh -i ${SSH_KEY} \$*" >> $SSH_WRAPPER 1 && \
69        chmod +x $SSH_WRAPPER \
70                || { echo "Creation of wrapper failed" ; exit 1 ; }
71fi
72
73# checkout if required, update otherwise.
74if [ ! -d ${TREE} ]; then
75        mkdir -p ${TREE} && \
76        cd ${TREE} && \
77        CVS_RSH=${SSH_WRAPPER} cvs -q -d $CVS_ROOT co darwinports > $FAILURE_LOG 2>&1 \
78                || { echo "CVS checkout failed" >> $FAILURE_LOG ; FAILED=1 ; }
79else
80        cd ${TREE}/${CVS_MODULE} && \
81        CVS_RSH=${SSH_WRAPPER} cvs -q update -dP > $FAILURE_LOG 2>&1 \
82                || { echo "CVS update failed" >> $FAILURE_LOG ; FAILED=1 ; }
83fi
84
85# (re)configure.
86if [ $FAILED -eq 0 ]; then
87        cd ${TREE}/${CVS_MODULE}/base/ && \
88        mkdir -p ${TCLPKG} && \
89        ./configure \
90                --prefix=${PREFIX} \
91                --with-tclpackage=${TCLPKG} \
92                --with-install-user=${DP_USER} \
93                --with-install-group=${DP_GROUP} > $FAILURE_LOG 2>&1 \
94                || { echo "./configure failed" >> $FAILURE_LOG ; FAILED=1 ; }
95fi
96
97# clean
98# (cleaning is useful because we don't want the indexing to fail because dependencies aren't properly computed).
99if [ $FAILED -eq 0 ]; then
100        { cd ${TREE}/${CVS_MODULE}/base/ && \
101        make clean > $FAILURE_LOG 2>&1 ; } \
102                || { echo "make clean failed" >> $FAILURE_LOG ; FAILED=1 ; }
103fi
104
105# (re)build
106if [ $FAILED -eq 0 ]; then
107        { cd ${TREE}/${CVS_MODULE}/base/ && \
108        make > $FAILURE_LOG 2>&1 ; } \
109                || { echo "make failed" >> $FAILURE_LOG ; FAILED=1 ; }
110fi
111
112# (re)install
113if [ $FAILED -eq 0 ]; then
114        { cd ${TREE}/${CVS_MODULE}/base/ && \
115        make install > $FAILURE_LOG 2>&1 ; } \
116                || { echo "make install failed" >> $FAILURE_LOG ; FAILED=1 ; }
117fi
118
119# (re)index
120if [ $FAILED -eq 0 ]; then
121        { cd ${TREE}/${CVS_MODULE}/dports/ && \
122        ${PREFIX}/bin/portindex > $FAILURE_LOG 2>&1 ; } \
123                || { echo "portindex failed" >> $FAILURE_LOG ; FAILED=1 ; }
124fi
125
126# check all ports were indexed.
127if [ $FAILED -eq 0 ]; then
128        grep Failed $FAILURE_LOG \
129                && { echo "some ports couldn\'t be indexed" >> $FAILURE_LOG ; FAILED=1 ; }
130fi
131
132# commit the file if and only if all ports were successfully indexed.
133if [ $FAILED -eq 0 ]; then
134        # Use the last 5 lines of the log for the commit message.
135        tail -n 5 $FAILURE_LOG > $COMMIT_MSG
136       
137        # Actually commit the file.
138        { cd ${TREE}/${CVS_MODULE}/dports/ && \
139        CVS_RSH=${SSH_WRAPPER} cvs commit -F $COMMIT_MSG PortIndex > $FAILURE_LOG 2>&1 ; } \
140                || { echo "cvs commit failed" >> $FAILURE_LOG ; FAILED=1 ; }
141fi
142
143# spam if something went wrong.
144if [ $FAILED -ne 0 ]; then
145        mail -s "AutoIndex Failure on ${DATE}" $SPAM_LOVERS < $FAILURE_LOG
146else
147        # trash log files
148        rm -f $COMMIT_MSG $FAILURE_LOG
149fi
150
151rm -f $LOCKFILE
Note: See TracBrowser for help on using the repository browser.