forked from fleetdm/fleet-gitops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitops.sh
executable file
·36 lines (30 loc) · 1.19 KB
/
gitops.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
#!/usr/bin/env bash
# -e: Immediately exit if any command has a non-zero exit status.
# -x: Print all executed commands to the terminal.
# -u: Exit if an undefined variable is used.
# -o pipefail: Exit if any command in a pipeline fails.
set -exuo pipefail
FLEET_GITOPS_DIR="${FLEET_GITOPS_DIR:-./}"
FLEET_GLOBAL_FILE="${FLEET_GLOBAL_FILE:-$FLEET_GITOPS_DIR/default.yml}"
FLEETCTL="${FLEETCTL:-fleetctl}"
# Validate that global file contains org_settings
grep -Exq "^org_settings:.*" "$FLEET_GLOBAL_FILE"
if compgen -G "$FLEET_GITOPS_DIR"/teams/*.yml > /dev/null; then
# Validate that every team has a unique name.
# This is a limited check that assumes all team files contain the phrase: `name: <team_name>`
! perl -nle 'print $1 if /^name:\s*(.+)$/' "$FLEET_GITOPS_DIR"/teams/*.yml | sort | uniq -d | grep . -cq
fi
# Dry run
$FLEETCTL gitops -f "$FLEET_GLOBAL_FILE" --dry-run
for team_file in "$FLEET_GITOPS_DIR"/teams/*.yml; do
if [ -f "$team_file" ]; then
$FLEETCTL gitops -f "$team_file" --dry-run
fi
done
# Real run
$FLEETCTL gitops -f "$FLEET_GLOBAL_FILE"
for team_file in "$FLEET_GITOPS_DIR"/teams/*.yml; do
if [ -f "$team_file" ]; then
$FLEETCTL gitops -f "$team_file"
fi
done