Page MenuHomeDevCentral

D1023.id2611.diff
No OneTemporary

D1023.id2611.diff

Index: Makefile
===================================================================
--- /dev/null
+++ Makefile
@@ -0,0 +1,11 @@
+INSTALL=/usr/bin/install
+RM=/bin/rm -f
+PREFIX?=/usr/local
+
+install:
+ ${INSTALL} salt-get-config-dir.py ${PREFIX}/bin/salt-get-config-dir
+ ${INSTALL} salt-wrapper.sh ${PREFIX}/bin/salt-wrapper
+
+deinstall:
+ ${RM} ${PREFIX}/bin/salt-get-config-dir
+ ${RM} ${PREFIX}/bin/salt-wrapper
Index: salt-get-config-dir.py
===================================================================
--- /dev/null
+++ salt-get-config-dir.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+import json
+import os
+import sys
+
+with open('/usr/local/etc/salt-wrapper.conf') as config_file:
+ config = json.load(config_file)
+
+cwd = os.getcwd()
+
+for root in config['roots']:
+ if cwd.startswith(root['states']):
+ print(root['config'])
+ sys.exit(0)
+
+sys.exit(1)
Index: salt-wrapper.sh
===================================================================
--- /dev/null
+++ salt-wrapper.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# -------------------------------------------------------------
+# Salt wrapper
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Created: 2016-04-10
+# License: BSD-2-Clause
+# Usage: salt-wrapper salt-call --local state.highstate
+# -------------------------------------------------------------
+
+# -------------------------------------------------------------
+# Helper functions
+#
+# :: contains
+# -------------------------------------------------------------
+
+# contains(string, substring)
+#
+# Returns 0 if the specified string contains the specified substring,
+# otherwise returns 1.
+# See: https://stackoverflow.com/a/8811800/1930997
+contains() {
+ string="$1"
+ substring="$2"
+ if test "${string#*$substring}" != "$string"
+ then
+ return 0 # $substring is in $string
+ else
+ return 1 # $substring is not in $string
+ fi
+}
+
+# -------------------------------------------------------------
+# Wrapper code
+# -------------------------------------------------------------
+
+CONFIG_DIR=$(salt-get-config-dir)
+CODE=$?
+if [ $CODE -ne 0 ]; then
+ exit $CODE
+fi
+
+EXECUTABLE=$1
+shift
+
+# The default user is salt, but if we need to target the Salt
+# master without a minion running, we need to run as root.
+SALT_USER=salt
+if [ "$EXECUTABLE" = "salt-call" ]; then
+ contains "$*" "--local" && SALT_USER=root
+fi
+
+sudo -u $SALT_USER "$EXECUTABLE" --config-dir="$CONFIG_DIR" "$@"

File Metadata

Mime Type
text/plain
Expires
Thu, Jun 19, 01:28 (7 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2746136
Default Alt Text
D1023.id2611.diff (2 KB)

Event Timeline