forked from rderewianko/caspersuite
/
DEP-newcomputer.sh
130 lines (100 loc) · 4.25 KB
/
DEP-newcomputer.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#
########################################################################
# Created By: Adam Codega, Swipely Inc.
# with help from Ross Derewianko Ping Identity Corporation
# Creation Date: June 2015
# Last updated: Dec 2015
# Brief Description: Changes machine hostname based on first initial and
# last name of local user. Then, ask IT tech which department to
# set computer to in JSS. Follows up with installing updates,
# running a recon, and telling tech it's ready to restart.
########################################################################
########################################################################
# Lets locate some Applications
########################################################################
#Find out where JAMF is because of the JSS 9.8 binary move
jamfbinary='/usr/bin/which jamf'
#check for cocoaDialog and if not install it
if [ -d "/Applications/Utilities/cocoaDialog.app" ]; then
echo "CocoaDialog.app installed, continuing on"
else
echo "CocoaDialog.app not found, pausing to install"
$jamfbinary policy -event cocoa
fi
coDi="/Applications/Utilities/cocoaDialog.app/Contents/MacOS/CocoaDialog"
#check for Dockutil and if not install it
if [ -f "/usr/local/bin/dockutil" ]; then
echo "Dockutil.app installed, continuing on"
else
echo "Dockutil not found, pausing to install"
$jamfbinary policy -event dockutil
fi
dockutil="/usr/local/bin/dockutil"
#######################################################################
# Figure out the hostname
#######################################################################
#Set the hostname
# figure out the user
user=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
#figure out the user's full name
name=$(finger "$user" | awk -F: '{ print $3 }' | head -n1 | sed 's/^ //' )
# get first initial
finitial="$(echo "$name" | head -c 1)"
# get last name
ln="$(echo "$name" | cut -d \ -f 2)"
# add first and last together
un=($finitial$ln)
# clean up un to have all lower case
hostname=$(echo "$un" | awk '{print tolower($0)}')
#######################################################################
# Clean up the dock
#######################################################################
$dockutil --remove all
$dockutil --add '/Applications/Launchpad.app' --no-restart
$dockutil --add '/Applications/System Preferences.app' --no-restart
$dockutil --add "/$HOME/Downloads"
#######################################################################
# Functions
#######################################################################
sethostname() {
$jamfbinary setComputerName -name "$hostname"
}
cdprompt() {
jssdept=$("$coDi" standard-dropdown --string-output --title "Choose a Department" --height 150 --text "Department" --items "Business Administration" Technology Finance Marketing Product Sales Success Talent)
if [ "$jssdept" == "2" ]; then
echo "user cancelled"
exit 1
fi
cleanjssdept
}
#cleans the first two characters out (cocoaDialog adds a 1 \n to the string value which we don't need.)
cleanjssdept() {
dept=$(echo "$jssdept" | sed -n 2p)
}
#sets department using JAMF Framework Recon command
setdepartment() {
$jamfbinary recon -department "$dept"
}
########################################################################
# Script
########################################################################
# sometimes we image (don't tell anyone) so we need to makes sure Site is Upserve and Department is None
$jamfbinary recon -building "Upserve"
$jamfbinary recon -department "None"
sethostname
cdprompt
setdepartment
# now that the dept is set let's apply profiles and policies
$jamfbinary manage
$jamfbinary policy
# manage and policy probably changed stuff, so let's submit an updated inventory
$jamfbinary recon
# set softwareupdate schedule On
softwareupdate --schedule on
# install all updates with verbose output
softwareupdate -via
# recon again
$jamfbinary recon
#notify the tech that computer is ready for restart
$coDi bubble --no-timeout --title "Upserve Enrollment Complete" --text "Restart to enable FileVault 2 Encryption" --icon "computer"