forked from rtrouton/CasperCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_pkg.sh
57 lines (47 loc) · 1.92 KB
/
create_pkg.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
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
###
#
# Name: create_pkg.sh
# Description: This script automatically creates a pkg file that you can
# use to deploy the Casper Check script/LaunchDaemon
# pair to your managed clients.
# Ripped off by: David West
# Author: Elliot Jordan <[email protected]>
# Created: 2015-09-18
# Last Modified: 2016-07-15
# Version: 1.0
#
###
cd "$(dirname "$0")"
if [[ ! -f "./script/caspercheck.sh" ||
! -f "./LaunchDaemon/com.company.caspercheck.plist" ||
! -f "./pkg_scripts/postinstall" ]]; then
echo "[ERROR] At least one required file is missing. Ensure that the following files exist in the correct folders:"
echo " script/caspercheck.sh"
echo " LaunchDaemon/com.company.caspercheck.plist"
echo " pkg_scripts/postinstall"
exit 1
fi
script_md5=$(md5 -q ./script/caspercheck.sh)
if [[ "$script_md5" == "7b1cc4afd0f53484ca772c0ac06ee786" ]]; then
echo "[ERROR] It looks like you haven't customized the caspercheck.sh script yet. Please do that now, then run create_pkg.sh again."
exit 2
fi
echo "Great! Sounds like you're good to go."
TMP_PKGROOT="/private/tmp/caspercheck/pkgroot"
echo "Building package root in /tmp folder..."
mkdir -p "$TMP_PKGROOT/Library/LaunchDaemons" "$TMP_PKGROOT/Library/Scripts"
echo "Copying the files to the package root..."
cp "./LaunchDaemon/com.company.caspercheck.plist" "$TMP_PKGROOT/Library/LaunchDaemons/"
cp "./script/caspercheck.sh" "$TMP_PKGROOT/Library/Scripts/"
echo "Setting mode and permissions..."
chown -R root:wheel "$TMP_PKGROOT"
chmod +x "$TMP_PKGROOT/Library/Scripts/caspercheck.sh"
echo "Building the package..."
pkgbuild --root "/tmp/caspercheck/pkgroot" \
--scripts "./pkg_scripts" \
--identifier "com.company.caspercheck.plist" \
--version "2.0" \
--install-location "/" \
"./caspercheck-$(date "+%Y%m%d").pkg"
exit 0