qubes-apply
python script to automate qubes saltstack
git clone https://9o.is/git/qubes-apply.git
qubes-apply
(1117B)
1 #!/usr/bin/bash
2 set -eo pipefail
3
4 configfile=$HOME/.config/qubes-apply/config
5
6 if [ -n $configfile ]; then
7 . $HOME/.config/qubes-apply/config
8 fi
9
10 cache_path="$HOME/.cache/qubes-apply"
11 package="/tmp/user-salt.tar"
12 args=($@)
13 paths=()
14
15 for path in salt pillar formulas; do
16 if [ -d $project_path/$path ]; then
17 paths+=($path)
18 fi
19 done
20
21 if [[ ! "${paths[@]}" ]]; then
22 echo "error: no valid directories found in '$project_path'"
23 exit 1
24 fi
25
26 if [[ " ${args[@]} " =~ ( -u | --upload-only ) ]]; then
27 upload_only=1
28 fi
29
30 if [ "$force_color" ]; then
31 args+=(--force-color)
32 fi
33
34 if [[ " ${args[@]} " =~ ' --force-color ' ]]; then
35 qrexec_flags='--no-filter-escape-chars-stdout --no-filter-escape-chars-stderr'
36 fi
37
38 mkdir -p $cache_path
39 [ -f $cache_path/log ] || touch $cache_path/log
40
41 tar cf $package -C $project_path ${paths[@]} \
42 --transform 's,^\(salt\|pillar\|formulas\),user_\1,'
43 qrexec-client-vm $qrexec_flags dom0 qubes.SaltUserUpload
44
45 if [ "$upload_only" ]; then
46 echo "upload only enabled... skipping apply"
47 else
48 qrexec-client-vm $qrexec_flags dom0 \
49 qubes.SaltQubesApply <<< "${args[@]}" | tee $cache_path/log
50 fi
51