-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate
executable file
·55 lines (45 loc) · 1.33 KB
/
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
TEMP_DIR=/tmp/temp/blogit
CONFIG_FILE=.blogit
CURRENT_DIR=`pwd`
echo "==> Cleaning directory with another releases"
rm -rf ${TEMP_DIR}
echo "==> Cloning repository into ${TEMP_DIR}"
git clone [email protected]:xepozz/blogit ${TEMP_DIR}
LAST_RELEASE=`cat ${TEMP_DIR}/.git/refs/heads/master`
echo "[Info] Last release hash: ${LAST_RELEASE}"
if [ -f ${CONFIG_FILE} ]
then
. ${CONFIG_FILE}
fi
echo "[Info] Current release hash: ${CURRENT_RELEASE}"
if [[ "${LAST_RELEASE}" = "${CURRENT_RELEASE}" ]]
then
echo "[Info] System is up to date"
else
echo "==> Caught updates, trying to apply..."
cd ${TEMP_DIR}
git diff --unified=0 ${CURRENT_RELEASE} ${LAST_RELEASE} > ${TEMP_DIR}/.patch
cd ${CURRENT_DIR}
patch -p1 < ${TEMP_DIR}/.patch
if [[ $? -eq 0 ]]
then
echo ""
echo "[Info] System was updated successfully"
echo "[Info] Please review updates and commit them"
echo ""
else
echo ""
echo "[Warning] Updates conflicts with your system"
echo "[Warning] Files with conflicts: `git status --short | grep "^UU "`"
echo ""
fi
echo ""
echo "==> Saving last release hash ${LAST_RELEASE}"
if [ -f ${CONFIG_FILE} ]
then
sed -i "s/CURRENT_RELEASE=.*/CURRENT_RELEASE=${LAST_RELEASE}/g" ${CONFIG_FILE}
else
echo "CURRENT_RELEASE=${LAST_RELEASE}" > ${CONFIG_FILE}
fi
echo "[Info] Update completed"
fi