forked from joshua-ess/ArtsyOnboardScripts2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_creator.sh
executable file
·130 lines (113 loc) · 4.27 KB
/
account_creator.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
#!/bin/bash
# vars
bold=$(tput bold) # ${bold}
# red=$(tput setaf 1) # ${red}
std=$(tput sgr0) # ${std}
adminpkg=admin.pkg
directory=$HOME/.artsy
icon_image="https://github.com/jasonarias/2021onboarding/blob/main/user.tif?raw=true"
url="https://github.com/jasonarias/2021onboarding/blob/main/setup.zip?raw=true"
# 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");')
# sudo check
# if [[ $EUID -ne 0 ]]; then
# echo "This script must be run with sudo privelages from the user account"
# exit 1
# fi
#
# funcs
printer () {
string=''$message''
for ((i=0; i<=${#string}; i++)); do
printf '%s' "${string:$i:1}"
sleep 0.$(( (RANDOM % 1) + 1 ))
done
printf -- '\n';
}
clear
message='account creator is alive lets go'
printer
echo
if [ -z "$password" ]
then
echo
echo -n "Enter Admin Password for $bold SUDO $std: "
read -r -s password
else
echo "seems we have a password already"
fi
if [ -z "$setup_password" ]
then
echo -n "Enter Setup Password from IT Vault: "
read -s -r setup_password # added a -r from shellcheck, remove if issues
echo
else
echo "setup_password seems set"
fi
if [ -d "$directory" ]
then
cd "$directory" || return
else
mkdir "$directory" && cd "$directory"
fi
echo "we should be in the $(pwd)"
message='...lets get the zip file'
printer
echo
curl -o setup.zip -L "$url"
unzip -o -P "$setup_password" setup.zip
while [[ ! -f "$adminpkg" ]] # this checks for the adminpkg, if not there, prompt for pass
do
echo -n "Enter Setup Password from IT Vault: "
read -s -r setup_password # added a -r from shellcheck, remove if issues
unzip -o -P "$setup_password" setup.zip
done
for f in *.pkg ;
do echo "$password"| sudo -S installer -verbose -pkg "$f" -target /
done
for f in *.pkg ;
do rm "$f"
done
# begin icon setter block
system_user=artsytech
curl -o user.tif -L "$icon_image"
printf -- 'changing the user icon \n';
echo "$password"| sudo -S dscl . delete /Users/"$system_user" jpegphoto
echo "$password"| sudo -S dscl . delete /Users/"$system_user" Picture
echo "$password"| sudo -S dscl . create /Users/"$system_user" Picture "$directory/user.tif"
set -e
declare -x USERNAME="$system_user"
declare -x USERPIC="$directory/user.tif"
declare -r DSIMPORT_CMD="/usr/bin/dsimport"
declare -r ID_CMD="/usr/bin/id"
declare -r MAPPINGS='0x0A 0x5C 0x3A 0x2C'
declare -r ATTRS='dsRecTypeStandard:Users 2 dsAttrTypeStandard:RecordName externalbinary:dsAttrTypeStandard:JPEGPhoto'
if [ ! -f "${USERPIC}" ]; then
echo "User image required"
fi
# Check that the username exists - exit on error
${ID_CMD} "${USERNAME}" &>/dev/null || ( echo "User does not exist" && exit 1 )
declare -r PICIMPORT="$(mktemp /tmp/${USERNAME}_dsimport.XXXXXX)" || exit 1
printf "%s %s \n%s:%s" "${MAPPINGS}" "${ATTRS}" "${USERNAME}" "${USERPIC}" >"${PICIMPORT}"
${DSIMPORT_CMD} "${PICIMPORT}" /Local/Default M &&
echo "Successfully imported ${USERPIC} for ${USERNAME}."
rm "${PICIMPORT}"
# second account
system_user=artsyloaner
printf -- 'changing the user icon \n';
echo "$password"| sudo -S dscl . delete /Users/"$system_user" jpegphoto
echo "$password"| sudo -S dscl . delete /Users/"$system_user" Picture
echo "$password"| sudo -S dscl . create /Users/"$system_user" Picture "$directory/user.tif"
set -e
declare -x USERNAME="$system_user"
# declare -r MAPPINGS='0x0A 0x5C 0x3A 0x2C'
# declare -r ATTRS='dsRecTypeStandard:Users 2 dsAttrTypeStandard:RecordName externalbinary:dsAttrTypeStandard:JPEGPhoto'
if [ ! -f "${USERPIC}" ]; then
echo "User image required"
fi
# Check that the username exists - exit on error
${ID_CMD} "${USERNAME}" &>/dev/null || ( echo "User does not exist" && exit 1 )
# declare -r PICIMPORT="$(mktemp /tmp/${USERNAME}_dsimport.XXXXXX)" || exit 1
printf "%s %s \n%s:%s" "${MAPPINGS}" "${ATTRS}" "${USERNAME}" "${USERPIC}" >"${PICIMPORT}"
${DSIMPORT_CMD} "${PICIMPORT}" /Local/Default M &&
echo "Successfully imported ${USERPIC} for ${USERNAME}."
rm "${PICIMPORT}"