Rename Computer using Scripting and Google Sheets

With Apple’s Device Enrollment program, when a organization-owned device first turns on, it checks in with Device Enrollment and gets the information to know what MDM is managing it and how to contact it. That MDM system can then install what’s known as a bootstrapping package.

In our old bootstrapping package, which was developed by an employee no longer here, was a giant if statement. If SerialNumber = x then set ComputerName to Bob, elseif SerialNumber = y then set ComputerName to Frank, elseif SerialNumber = z then set ComputerName to Jane. Pretty simple and straight forward, but a long list that is static and cannot be updated, without getting the package, rewriting the script to include new computers, repackage it and redeploy it. UGH!

I can’t find the original package. It’s in AirWatch, but sadly, I can’t find a “Download your package” button anywhere in there.

So I was going to rewrite it. Then I came across a page that talked about doing it from a spreadsheet. So I thought, well I can host a CSV file on a server somewhere and the computer can use the curl command to download it. Then I discovered that you can curl command to download a Google Sheet from the internet. At that point then I never have to change the package again1, I just have to update the Google Sheet.

I got into some trouble, and as usual, the killer community in the #toronto channel of the MacAdmins Slack are amazing and came to the rescue.

Specifically @Gerk, I had this weird awk command that wasn’t working. I also didn’t quite understand the command I had found in my Googling. He told me how he would do it, I quickly changed the line and tested it and it worked. I think googled how to parse $LINE variable to only have the value prior to the ,.

I think this works well. If anyone wants to improve on it, let me know. This is why we share knowledge in the MacAdmins community.

#!/bin/sh

# Get the current device's serial number
SERIAL="$(ioreg -l | grep IOPlatformSerialNumber | sed -e 's/.*\"\(.*\)\"/\1/')"

# Where the file will be saved using today's date. On date of writing would be /tmp/serials20190802.csv
OUTPUT=/tmp/serials$(date +%Y%m%d).csv

# Download the CSV from Google Drive, file must be set to Shared With Anyone with Link (or Shared with Anyone)
curl 'https://docs.google.com/spreadsheets/d/YOURGOOGLESHEETIDHERE/export?exportFormat=csv' -o $OUTPUT

# With much thanks to @Gerk and the rest of the crew on the MacAdmins #toronto channel, this now grabs the entire line from the CSV file 
LINE=$(grep $SERIAL $OUTPUT)

# This will grab all the text before the ,
ASSETTAG="$( cut -d ',' -f 1 <<< "$LINE" )"

# Set the ComputerName, HostName and LocalHostName
scutil --set ComputerName $ASSETTAG
scutil --set HostName $ASSETTAG
scutil --set LocalHostName $ASSETTAG
  1. Well, never say never []

Doctor Who Serial 094 – Image of the Fendahl

Part One

These scientists have obviously never heard of time travel. That skull could have belonged to a time traveller. Oooo-wee-oooo

Well that is why K9 isn’t in this episode. The Doctor broke him.

Leela’s wearing the most boob-a-licious dress I’ve seen in a while. How come the Doctor never wears such a low cut top. I think Tom Baker could’ve pulled it off.

There’s something so lovely about Tom Baker’s voice.

Part Two

How are there so many people in the Whoniverse who can convince other people not to call the cops?

Part Three

The skull is hypnotizing the Doctor, take your hand off of it.

Part Four

I have no idea what is going on. Maybe I shouldn’t have spent all of episode three looking at Boaty Weekender passes that I can’t afford or justify.

Doctor Who Serial 093 – The Invisible Enemy

Part One

That’s the weirdest design for the bridge of a shuttle craft. Also, are they in la-z-boys?

Oh, the Doctor switched back to the main control room. That’s nice. Except he’s calling it the “number two control room.” I disagree.

C’mon! Have a drink before you shoot people. That’s the least you could do.

Damn, Leela, that hat looks good on you.

That knife looked like rubber. I needed a “BOING” sound effect.

Part Two

I forgot that K9 shows up at some point in this story. I can’t wait for that. Also, really digging this soundtrack while the Doctor is in hospital.

That receptionist is so rude. “Computer says no.”

K9! He’s there! “Affirmative, master!” I didn’t know he was a medical doggy before he was a time traveller.

I like that their English has migrated over the past 3000 years and the spelling on all the walls have changed.

The doctor who is attending the Doctor made K9 because he was lonely. That’s so lovely.

This is overexposed.

Hmm, 4th millenium when we first cloned… they forgot about Dolly.

Nice that Gallifreyan technology is compatible with Human technology from this century.

“I’m shrinking, and my clothes are shrinking too, and my voice is getting higher in proportion to my shrinking!” Mahatma Gandhi

Part Three

Oh god, clone Doctor and clone Leela are being flushed down the toilet.

How convenient it is that the wall K9 was going to blast already had cut marks!

“That is why my brain is so much superior to yours.” God damn, you’re an asshole, Doctor.

Hahaha! Leela is being attacked by balloons.

NO! They made contact with K9!

Yay, K9 is better, but his master has been taken over by the virus.

Hahaha! How did he walk around the Nucleus and not see it?

Part Four

Let’s do this! Part four, yeah! I’m enjoying this one.

HAHAHAHA! The nucleus cannot move, so the other actors have to help it.

Poor K9, he’s getting blowed up. Aww, he has a leash.

Leela was barely pinning that guy down. I think she was killing him with underarm smell.

The Doctor got K9 as a gift from his doctor. That’s really nice.

Doctor Who Serial 092 – Horror of Fang Rock

Part One

Yar! There be a fog coming up!

Excellent hat, Doctor.

Once again, The Doctor is accused of murdering a character. It seems pretty cliché, but worse that they did it two stories in a row. They could have prevented that.

Part Two

Doctor Who characters need to learn to believe the eyes of other characters in Doctor Who.

Part Three

The gentleman from the upper chamber is an asshole. I like the man from the Commons. Then again, the Doctor himself is a bit of an asshole.

Leela’s callousness is fantastic!

Part Four

He’s dead, Jim.

Oh, we’re seeing Rutans for the first time. They don’t seem to care about Humans, maybe the Sontarans should destroy them.

That tentacle wrapping around the neck of the Member of the Commons was so hilarious I laughed out loud.

The Rutan sounds too much like a Dalek.

Doctor Who Serial 091 – The Talons of Weng-Chiang

Part One

Let’s start with racism. Holy shit. All the supporting Chinese characters are played by Chinese actors, but the main one is played by John Bennett, the whitest British actor you can imagine. I am tempted to just skip this episode, but it is considered to be one of the best. From now on we will be referring to Weng-Chiang as Racist Depiction of Asian Person.

That woman plays an impeccable witch.

“Carrying a body, a European body,” at least they’re right about cops being racist.

Rat hair, long rat hair, that seems improbable, but apparently Racist Depiction of Asian Person is the “god of abundance” and can “make things grow.”

Part Two

Why are they trusting the Doctor in the mortuary. Isn’t he a suspect?

The theatre owner has the greatest nose I’ve ever seen.

Oh, Racist Depiction of Asian Person is in service of another. Oh, his lord is a time traveler from the future.

Big Nose got hypnotized to remember the hypnotism that made him forget.

Can I just say that this is the shittiest Muppet I have ever seen. Kermit would be crying.

Leela’s culinary skills are fun.

“One thing I can swear is he was a Chinese.” *facepalm*

SHIT! The Muppet is going to kill Leela!

Part Three

Leela’s taken out shitty Muppet without breaking a sweat. That’s my problem with Doctor Who cliffhangers, they are never actually difficult for our heroes to get out of.

The Doctor wants an elephant gun. He’s going hunting.

Leela’s gonna meet the giant rat.

Big Nose is worried about “missing females.” I think he might be a Ferengi, but they’re big ears.

All while I’m watching this Doctor Who, I’m also in the #Toronto channel of the MacAdmins slack, and it’s a bloody rollercoaster in there. Things working, not working, working again, not working. Woo, oh, the episode ended.

Part Four

HAHAHA! That rat is amazing!

The Doctor is very prescient.

There’s a dead man in the box!

Part Five

That’s a pretty evil laugh.

They’ve got the time cabinet.

Ugly Muppet is the worst thing Doctor Who has ever done.

Run Big Nose!

I don’t believe either of those dumb waiters have enough strength to lift themselves in a dumb waiter.

The evil dude is disfigured, oh, that explains why he’s evil. *facepalm*

Part Six

Jelly baby?

Wow, this guy is so desperate. How did he ever get as far as he did?

Wait, he was the Minister of Justice? He’s a whiny baby.

Ugly Muppet is defying his master. I’m not sure why.

Doctor Who Serial 090 – The Robots of Death

Part One

That’s pretty heavy foreshadowing. Robots are going to rip someone’s arm off.

“That’s silly” says Leela as she learned about how the TARDIS works. She’s right. She’s very very right.

Oh my god, these hats are divine.

Shit, that robot has red eyes, that can only mean one thing… ARMS ABOUT TO RIPPED OFF!

Big hat commander is talking into his Apple Watch.

Damn, the dude was strangled, no arms ripped off.

If your buddy gives you an alibi, don’t throw a hole in it.

Part Two

That last episode led to a two hour nap. Not sure what that means for part two, but here we go…. *dum de dum, dum de dum, dum de dum, dum de dum…*

Well, they killed the brown dude. Of course.

Everyone here is jumping to conclusions. They were foreshadowing about robot murders, obviously it’s the robots! Also, the title is “Robots of Death.” Look at the script!

That guy really doesn’t like Jelly Babies.

Big hat leader looks a lot like Tim Curry.

Well, now they’re pointing figures, so that’s good, but no one is pointing to robots, except the Doctor. Maybe he’s right.

Also, I love their makeup.

Looks like the robots are getting their commands from a meat person.

Part Three

Everyone is about to die, I bet they’ll get out of this scrape.

Well, that was easy, but new problem, their car is sinking.

Part Four

Had a nice swim in the lake, time for part four. THEN DINNER!

That was handy, there was a dude there to save the Doctor.

These robots are assholes.

It’s a really ingenious feature to turn the eyes red on any robot that is jailbroken.

“They call it robophobia” might be the greatest line of dialogue ever. This is high quality psychology.

YES! The Doctor is defeating the back guy by using helium to change his voice so the robots don’t obey his commands. They’re changing his voice with post-production, it should’ve been done on set with actual helium, it sounds terrible. How come the Doctor’s voice never changed? Oh, they answered it, he’s a Time Lord.

Doctor Who Serial 089 – The Face of Evil

Part One

There’s a great god named Zynon! I’m down for this. We’re meeting Leela a lot quicker than I expected we would.

I like their Jelly Baby exchange quite a bit.

Leela gained trust in the Doctor quite quickly.

I love the ridiculous priest.

So these dudes are praying to an alien who crashed on their planet. Cool.

Tom Baker’s head a-la Mount Rushmore is great.

Part Two

“I like the hat, very fetching” was pretty much what I was thinking.

Is that the Doctor’s voice on the radio? Okay, so they confirmed it.

Hahaha, flinging the Cybermat at the dude, and making him run away screaming was delightful.

That is some bad blue screen.

Part Three

He’s dead with some spectacular acting. /s

Who are you?

Part Four

If you’re going to fight with the Doctor, use his scarf against him!

It’s another journey of wandering around hallways. Their fighting against a computer, but the computer doesn’t seem too excited to kill the Doctor. I don’t think it’s because the writer wanted complexity, I think it’s because the writer is bad.

“Where the beams… are… coming… from.” This guy went to the Shatner School of Acting.

The hat the Doctor’s wearing reminds me of Doc Brown.

Okay, before I resume Doctor Who, can we talk about that last second of that Back To The Future scene? Christopher Lloyd’s reaction is perfect. That movie has such a great and tight script.

The Doctor giving the group on the planet a button to destroy the supercomputer, but it looks like a Staples easy button.

Okay, I like Leela, forcing herself into the Doctor’s life.

Doctor Who Serial 088 – The Deadly Assassin

Part One

To Gallifrey we go!

What the hell was that Star Warsesque title scroll? That’s terrible.

There’s a lot of exposition here, oddly, it’s good.

Hahaha! Gallifreyan newscasts are as boring as BBC News.

The Doctor shot the President, what the farts?

Part Two

The Doctor should’ve brought Sarah. She would have stopped him murdering.

“Vaporization without representation is against the constitution.”

Oh! The Doctor is throwing his hat in the ring.

The Master is looking rather creepy. At least he doesn’t have a bad goatee.

Part Three

All reality is a computation matrix, Doctor.

That rock-face with superimposed eyes was so bad, I had to interrupt my wife to show her.

I think that might be the first time in Doctor Who history that we saw blood.

I don’t understand why he’s in this matrix.

Part Four

Drown Doctor! Drown! Oh, you’re still alive, and has a stick! He won!

The Master is a jerk.

I like that this guy’s name is Goth.

Deathbed speeches are terrible.

The Master’s makeup looks ridiculous. Kind of like a muppet.

So they completely forgot about the Doctor running for President, and that his only competition is dead?

Doctor Who Serial 087 – The Hand of Fear

Part One

That jacket looks comfy.

I know I’ve seen this one before, but none of this looks familiar.

Now I’m remembering it. The scene in the quarry is quite familiar.

That is some bad special effects. Even for Doctor Who.

I’m really liking Elisabeth Sladen as possessed Sarah. She looks good as she knocks people out with her ring.

She got into a restricted, high radiation zone really easily.

Part Two

Eldrad must live. Fuck. Eldrad is also talking to the doctor from the hospital. Eldrad must live.

That was a quick end from the dude who was a doctor from the hospital.

Sarah’s radioactive, 3.6 roentgen, not great, not terrible.

I liked evil Sarah, but I’m glad she’s back to normal.

This ring man, let’s call him Ringo, is rather obsessed with Eldrad.

Part Three

This story seems to have long “previously on” segments.

An unexplosion? Does he mean an implosion?

She’s sexy for a rock lady!

I think the Doctor is tricking Eldrad.

NO! ELDRAD!

Part Four

This is the final episode with Sarah. Will I cry? We’ll find out. Probably not.

Oh yeah! Eldrad got shot. Poor Eldrad. Also Doctor Who needs to stop showing elevators, they look terrible, just do what Star Trek, a small room with a window hole and a moving light to show movement.

Also, Sarah’s screaming is terrible.

Eldrad’s people are going to try to kill Eldrad, but it’s not Eldrad’s people, it must be the invaders.

Oh no! Eldrad is crushed. Oh! She’s good.

How did Eldrad go from a quiet and subtle person to this annoying dude?

Uh oh, Eldrad is telling the Doctor his evil plans. Don’t do that, the Doctor will stop you.

I like that the rock peeps are all wearing kippot.

Sarah is throwing a tantrum and the Doctor doesn’t care. He should be a better friend.

The Doctor is truly abandoning her. He’s a jerk.

Doctor Who Serial 086 – The Masque of Mandragora

Part One

It’s season 14! This is fun, we get a little tour of the TARDIS. Oh, and a new control room. Sarah found Doctor 2’s recorder! I love Doctor 2. You know you’re in the ’70s when you have a wood panelled TARDIS.

I think we’re now in the olden times… and I think there’s a Time Lord. I checked Wikipedia. It’s 15th century Europe. It didn’t say he was a time lord, and he’s removed his stupid collar, so it might not be.

Evil monks have captured Sarah, but the Doctor knows Venutian Judo, so he’s gonna kick some Monk ass… until he gets hit on the head with a rock.

The red light from earlier is now on Earth… the Doctor brough it to Earth! Stupid Doctor.

The Doctor stole that horse with gusto and it was stolen from him with gusto.

Wow, that soldier got crispy from the red light.

Nice bedsheet, Sarah! You rock it!

Part Two

Hahaha! I like Tom Baker. He’s about to get his head cut off and says, “Hold it, excuse me, I like to look my best on these occasions.” Takes off his scarf and uses it to trip the executioner before running away. This is why Tom Baker is so well loved.

Sarah’s still rocking the bedsheet. Looks like she’s going to be sacrificed by the monks. Not be confused with the Monk, the Time Lord. The monks are kinda doing the hora.

The monks’ masks remind me of Zardoz. Not sure why.

Wow, that beard.

Ooo, the duke has a companion. They look like they’re a couple.

Part Three

“Death to Julianos!”

I don’t know what’s happening, but it seems the Doctor is confused, too.

I didn’t notice before that one of the monks is in purple. He looks rather fetching.

Part Four

This is a really silly episode, but I feel a bit lost. See, it’s Friday evening after the most treacherous work week. I watched episode three at least a week ago.

That lion mask looks like it should be heavy, but doesn’t look like it weighs more than a gram.

Sarah’s hair is fantastic.

FIGHT! FIGHT! FIGHT!

DANCE! DANCE! DANCE!

Everything’s good and the Doctor has a salami. How nice.