Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Validate plist during make nbi
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed May 13, 2015
1 parent daa73af commit 55be9d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ARGS= -e -p
BUILD=Release
AUTONBIURL=https://bitbucket.org/bruienne/autonbi/raw/master/AutoNBI.py
FOUNDATIONPLISTURL=https://raw.githubusercontent.com/munki/munki/master/code/client/munkilib/FoundationPlist.py
VALIDATE=True

-include config.mk

Expand Down Expand Up @@ -42,6 +43,9 @@ run: build

config:
rm -f com.grahamgilbert.Imagr.plist
ifeq ($(VALIDATE),True)
./validateplist $(URL)
endif
/usr/libexec/PlistBuddy -c 'Add :serverurl string "$(URL)"' com.grahamgilbert.Imagr.plist

deps: autonbi foundation
Expand All @@ -52,6 +56,7 @@ dmg: build
mkdir -p /tmp/imagr-build
cp ./Readme.md /tmp/imagr-build
cp -R ./build/Release/Imagr.app /tmp/imagr-build
cp ./validateplist /tmp/imagr-build
hdiutil create -srcfolder /tmp/imagr-build -volname "Imagr" -format UDZO -o Imagr.dmg
mv Imagr.dmg \
"Imagr-$(shell /usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "./build/Release/Imagr.app/Contents/Info.plist").dmg"
Expand Down
17 changes: 15 additions & 2 deletions validateplist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import os
import sys
import argparse
import subprocess
import tempfile
import shutil
if os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Imagr')):
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Imagr'))
elif os.path.exists('/usr/local/munki/munkilib'):
Expand Down Expand Up @@ -69,8 +71,9 @@ def validateComponent(component, workflow):
fail("'content' is a required key in a 'script' component. Not found in %s" % workflow['name'])

def main():
temp_plist = None
parser = argparse.ArgumentParser()
parser.add_argument('plist', help='Path to your Imagr config plist')
parser.add_argument('plist', help='Path or URL to your Imagr config plist')
args = parser.parse_args()

if 'plist' not in args:
Expand All @@ -79,7 +82,15 @@ def main():
plist = args.plist

if plist.startswith('http://') or plist.startswith('https://'):

temp_dir = tempfile.mkdtemp()
cmd = ['/usr/bin/curl', '-fsSL', plist, '-o', os.path.join(temp_dir, 'config.plist')]
task = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = task.communicate()[0]

if task.returncode != 0:
fail(proc)
temp_plist = os.path.join(temp_dir, 'config.plist')
plist = temp_plist
if not os.path.exists(plist):
fail("Couldn't find configuration plist at %s" % plist)

Expand All @@ -96,6 +107,8 @@ def main():
except:
fail("Couldn't read plist. Make sure it's a valid ")

if temp_plist:
shutil.rmtree(temp_dir)
# Rule 1
if 'password' not in config:
fail('There must be a password set.')
Expand Down

0 comments on commit 55be9d4

Please sign in to comment.