forked from radicallyopensecurity/pentext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull_upstream_changes.sh
69 lines (56 loc) · 1.89 KB
/
pull_upstream_changes.sh
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
#!/usr/bin/env bash
# pull_upstream_changes - Updates repo and applies upstream changes
#
# Copyright (C) 2016-2017 Peter Mosmans [Radically Open Security]
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# File which has to exist in the target directory to qualify as target
FINGERPRINT="dtd"
# List of files and directories that need to be updated
SOURCEFILES="dtd xslt source/snippets"
# Root directory within source repo
SOURCEROOT="xml"
## Don't change anything below this line
VERSION=0.7
source=$(dirname $(readlink -f $0))
if [ "$1" == "--force" ]; then
force=true
shift
fi
target=$1
if [ -z "$target" ]; then
target=$(readlink -f .)
if [ "${target}" == "${source}" ]; then
echo "Usage: pull_upstream_changes [--force] [TARGET]"
echo " or run from within target directory"
exit
fi
fi
# Check if the target actually contains the repository
if [ ! -z ${FINGERPRINT} ] && [ ! -d $target/dtd ]; then
echo "[-] ${target} does not contain the correct repository"
if [ -z $force ]; then
exit
else
echo "[*] --force option: continuing anyway..."
fi
fi
# Update repository
echo "[*] Updating source repository (${source})..."
pushd "$source" >/dev/null && git pull && popd >/dev/null
# Only update newer files
echo "[*] Applying changes (if any)..."
for sourcefile in ${SOURCEFILES}; do
if [ -d "${source}/${SOURCEROOT}/${sourcefile}" ]; then
if [ ! -z $force ]; then
mkdir -p ${target}/${sourcefile} 1>/dev/null
fi
cp -prv ${source}/${SOURCEROOT}/${sourcefile}/* $target/${sourcefile}/
else
cp -pv ${source}/${SOURCEROOT}/${sourcefile} $target/${sourcefile}
fi
done
echo "[+] Done"