-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply.sh
executable file
·44 lines (36 loc) · 1.28 KB
/
apply.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
#!/bin/sh
# Determine correct directory and change into it
DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR"
# Determine manifest to apply
if [ -n "$1" ]; then
MANIFEST="$1"
else
MANIFEST="workstation"
fi
# Some tasks are better left if we aren't the correct user
if [ $(id -u) -ne 0 ]; then
# Initialise git submodules
./submodules.sh
# Copy updated ssh/known_hosts back into repository and commit (if no other changes are staged)
if [ "$MANIFEST" = "workstation" ]; then
KNOWN_HOSTS_REAL="$HOME/.ssh/known_hosts"
KNOWN_HOSTS_REPO="$DIR/modules/users/files/$USER/dotfiles/ssh/known_hosts"
if [ -f "$KNOWN_HOSTS_REAL" ] && [ "$KNOWN_HOSTS_REAL" -nt "$KNOWN_HOSTS_REPO" ]; then
SUM_REAL=$(md5sum "$KNOWN_HOSTS_REAL" | awk '{print $1;}')
SUM_REPO=$(md5sum "$KNOWN_HOSTS_REPO" | awk '{print $1;}')
if [ "$SUM_REPO" != "$SUM_REAL" ]; then
cp -v "$KNOWN_HOSTS_REAL" "$KNOWN_HOSTS_REPO"
if ! git status | grep -qc '^# Changes to be committed:$'; then
git add "$KNOWN_HOSTS_REPO"
git commit -m 'Update ssh/known_hosts'
fi
fi
fi
fi
fi
# Perform puppet run
[ $(id -u) -ne 0 ] && SUDO="sudo -H"
$SUDO puppet apply --color ansi --modulepath "$DIR/modules" "$DIR/manifests/$MANIFEST.pp"
# Exit with status code
exit $?