/
bzr_update
executable file
·64 lines (57 loc) · 2.11 KB
/
bzr_update
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
#!/bin/bash
#
# Quick proof of concept bzr updater scrip
# incorporate into interface/write in python later
#
# will update an install in the users home directory.
# edit WP var to change the location.
#
# 20101218 - first release of basic script
WP="$PWD"
WGET=`which wget`
BZR=`which bzr`
if [ -d ${WP}/.bzr ]; then
if [ -f ${WP}/.bzr/branch/branch-revision ]; then
echo "Removing old branch-revision file"
rm ${WP}/.bzr/branch/branch-revision
fi
echo "Checking for update ... Please Wait"
BRANCH_URL=`grep -m1 "parent_location" ${WP}/.bzr/branch/branch.conf | awk '{ print $3 }' `
if [ `echo ${BRANCH_URL} | grep -o "bzr+ssh"` ]; then
echo "Branch is using bzr+ssh method, fixing url for use with updater."
BRANCH_RSS=`echo ${BRANCH_URL} | sed -e s#bzr\+ssh#http#`
else
BRANCH_RSS=${BRANCH_URL}
fi
wget -q ${BRANCH_RSS}/changes/ -O ${WP}/.bzr/branch/branch-revision
LAST_REV=`cat ${WP}/.bzr/branch/last-revision | awk '{ print $1 }'`
BRANCH_REV=`grep -m1 "<span>" ${WP}/.bzr/branch/branch-revision | sed -e s#\<[^\>]*\>##g`
if [ ! $LAST_REV ]; then
echo "Could not obtain current branch revision number, exiting"
exit 0
fi
if [ ! $BRANCH_REV ]; then
echo "Could not obtain remote branch revision number, exiting"
exit 0
fi
if [ $BRANCH_REV -gt $LAST_REV ]; then
BEHIND=$(($BRANCH_REV-$LAST_REV))
echo -n "Update available, you are ${BEHIND} commits behind, update? (y/N): "
read a
if [[ $a == "Y" || $a == "y" ]]; then
cd ${WP}
echo "Updating branch to revision: ${BRANCH_REV} in ${WP} using ${BZR} from ${BRANCH_URL}"
${BZR} pull ${BRANCH_URL}
exit 1
else
echo "Not updating, local version remains at revision: ${LAST_REV}"
exit 0
fi
else
echo "Revision: ${LAST_REV} is current"
exit 0
fi
else
echo "This is not a branched version of wahcade, script cannot be used"
exit 2
fi