Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Author: MichalM.Mac
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Config
- PAYLOAD_SAVE_LOCATION='/Users/Shared'
- PAYLOAD_ORGANIZATION='cz.osxadmin'
- PAYLOAD_VERSION=1
- PAYLOAD_REMOVAL_DISALLOWED='true'
- PROFILE_PASSWORD='password'
- # CSV:: SSID;password;room_number;room_name
- CSV_DELIMITER=','
- # Programs
- BUDDY='/usr/libexec/PlistBuddy -c'
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- error_printer() {
- echo "$@" 1>&2;
- }
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- add_payload_removal_password(){ # $1: ProfileIdentifier, $2: Path to .mobileconfig file
- PROFILE="$2"
- PASSWORD_PAYLOAD_UUID=$(uuidgen)
- # New Dict
- $BUDDY "Add :PayloadContent:1 dict" "$PROFILE"
- # Profile Specific
- $BUDDY "Add :PayloadContent:1:RemovalPassword string \"${PROFILE_PASSWORD}\"" "$PROFILE"
- # Generated
- $BUDDY "Add :PayloadContent:1:PayloadIdentifier string \"${1}.com.apple.profileRemovalPassword.${PASSWORD_PAYLOAD_UUID}\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:1:PayloadUUID string \"${PASSWORD_PAYLOAD_UUID}\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:1:PayloadVersion integer \"${PAYLOAD_VERSION}\"" "$PROFILE"
- # Static
- $BUDDY "Add :PayloadContent:1:PayloadDisplayName string \"Profile Removal\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:1:PayloadType string \"com.apple.profileRemovalPassword\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:1:PayloadDescription string \"Configures a password for profile removal\"" "$PROFILE"
- }
- add_payload_wifi(){ # $1: Wi-Fi name, $2: Wi-Fi password, $3: ProfileIdentifier $4: Path to .mobileconfig file
- PROFILE="$4"
- WIFI_PAYLOAD_IDENTIFIER=$(uuidgen)
- WIFI_PAYLOAD_UUID=$(uuidgen)
- # New Dict
- $BUDDY "Add :PayloadContent:0 dict" "$PROFILE"
- # Wi-Fi Specific
- $BUDDY "Add :PayloadContent:0:SSID_STR string \"${1}\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:Password string \"${2}\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:AutoJoin bool true" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:HIDDEN_NETWORK bool false" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:IsHotspot bool false" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:_UsingHotspot20 bool false" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:EncryptionType string \"WPA\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:ProxyType string \"None\"" "$PROFILE"
- # Generated
- $BUDDY "Add :PayloadContent:0:PayloadIdentifier string \"${3}.com.apple.wifi.managed.${WIFI_PAYLOAD_IDENTIFIER}\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:PayloadUUID string \"${WIFI_PAYLOAD_UUID}\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:PayloadVersion integer \"${PAYLOAD_VERSION}\"" "$PROFILE"
- # Payload Default
- $BUDDY "Add :PayloadContent:0:PayloadDisplayName string \"WiFi ${1}\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:PayloadType string \"com.apple.wifi.managed\"" "$PROFILE"
- $BUDDY "Add :PayloadContent:0:PayloadDescription string \"Configures Wi-Fi settings\"" "$PROFILE"
- }
- generate_profile() { # $1: Wi-Fi name, $2: Wi-Fi password, $3: Path to .mobileconfig file
- PROFILE="$3"
- PAYLOAD_IDENTIFIER="script.$(uuidgen)"
- PAYLOAD_UUID=$(uuidgen)
- $BUDDY "Add :PayloadDisplayName string \"Wi-Fi ${1}\"" "$PROFILE"
- $BUDDY "Add :PayloadIdentifier string \"$PAYLOAD_IDENTIFIER\"" "$PROFILE"
- $BUDDY "Add :PayloadOrganization string $PAYLOAD_ORGANIZATION" "$PROFILE"
- $BUDDY "Add :PayloadType string \"Configuration\"" "$PROFILE"
- $BUDDY "Add :PayloadUUID string \"$PAYLOAD_UUID\"" "$PROFILE"
- $BUDDY "Add :PayloadVersion integer \"$PAYLOAD_VERSION\"" "$PROFILE"
- #Payload
- $BUDDY "Add :PayloadContent array" "$PROFILE"
- #Payload item 0
- add_payload_wifi "$1" "$2" $PAYLOAD_IDENTIFIER "$PROFILE"
- if [ "$PAYLOAD_REMOVAL_DISALLOWED" = "true" ]; then
- $BUDDY "Add :PayloadRemovalDisallowed bool true" "$PROFILE"
- if [ ! -z "$PROFILE_PASSWORD" ]; then
- $BUDDY "Add :HasRemovalPasscode bool true" "$PROFILE"
- #Payload item 1
- add_payload_removal_password $PAYLOAD_IDENTIFIER "$PROFILE"
- else
- $BUDDY "Add :HasRemovalPasscode bool false" "$PROFILE"
- fi
- else
- $BUDDY "Add :PayloadRemovalDisallowed bool false" "$PROFILE"
- fi
- }
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Main Body
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- if [ $# -eq 0 ]; then
- error_printer "Error: No input file. Please add input file with wi-fi network as an argument"
- exit 1
- fi
- if [ ! -f "$1" ]; then
- echo "Input file not found!"
- fi
- while read LINE; do
- SSID="$(echo $LINE | cut -d${CSV_DELIMITER} -f1)"
- PASSWORD="$(echo $LINE | cut -d${CSV_DELIMITER} -f2)"
- generate_profile "$SSID" "$PASSWORD" "${PAYLOAD_SAVE_LOCATION}/Wi-Fi_${SSID}.mobileconfig"
- done < "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement