-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdate-logsh
executable file
·63 lines (49 loc) · 1.56 KB
/
update-logsh
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/sh
usage() {
cat << EOF
Add or update Trallnags 'logging' shell library.
This script will ensure that 'log.sh' can be found in the same
directory as this script itself.
Usage:
$0 [reference]
Options:
reference: Git reference to checkout. For example a tag. If this
is not set, the latest commit on the default branch
will be checked out and used.
-h, --help: Print this help message.
Examples:
$0 v1.2.3
EOF
}
case $1 in -h | --help) usage && exit ;; esac
# Get source dir of script. <https://stackoverflow.com/a/29835459/7391331>.
# shellcheck disable=SC1007 # Incorrect warning.
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
# ==============================================================================
if [ -z "$1" ]; then
reference=master
else
reference="$1"
fi
set -eu
dir=/tmp/git-trallnag-logsh
if ! [ -d "$dir/.git" ]; then
echo "'$dir/.git' does not exist yet. Time to clone."
echo "Clone 'https://github.com/trallnag/logsh.git' to '$dir'..."
git clone https://github.com/trallnag/logsh.git "$dir"
else
echo "'$dir/.git' already exists. No need to clone."
echo "Pull 'https://github.com/trallnag/logsh.git' at '$dir'..."
cd "$dir"
git checkout master
if ! git pull --all --tags; then
cd ..
rm -rf "$dir"
git clone https://github.com/trallnag/logsh.git "$dir"
cd "$dir"
fi
fi
git config advice.detachedHead false
git checkout "$reference"
echo "Force copy '$dir/log.sh' to '$script_dir/'..."
cp --force log.sh "$script_dir/log.sh"