Created
April 6, 2020 16:41
-
-
Save quantum77/854a36a60c26e16d405080409a99156b to your computer and use it in GitHub Desktop.
An extension to Lunar's Tesla scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Adds your password and SSH pub key to 3 users. root, tesla, yourUsername | |
if [ "$accountUserToSaveToCar" = "yourUsername" ] || [ -z "$accountUserToSaveToCar" ]; then | |
echo "Please set config parameter accountUserToSaveToCar" | |
exit 1 | |
fi | |
if [ "$accountPassToSaveToCar" = "myCarIsRooted" ] || [ -z "$accountPassToSaveToCar" ]; then | |
echo "Please set config parameter accountPassToSaveToCar" | |
exit 1 | |
fi | |
if [ "$keyToSaveToCar" = "ssh-rsa first example" ] || [ -z "$keyToSaveToCar" ]; then | |
echo "If you want to use an SSH cert, set config parameter keyToSaveToCar" | |
fi | |
# Make SSH dirs | |
mkdir --mode=700 /root/.ssh 2>&1 | |
mkdir --mode=700 /home/tesla/.ssh 2>&1 | |
mkdir --mode=700 -p /home/"$accountUserToSaveToCar"/.ssh 2>&1 | |
# Add user account and set your password for root, tesla, and $accountUserToSaveToCar | |
if getent passwd "$accountUserToSaveToCar" >/dev/null 2>&1; then | |
echo "$accountUserToSaveToCar already exists" | |
else | |
echo root:"$accountPassToSaveToCar" | chpasswd | |
echo tesla:"$accountPassToSaveToCar" | chpasswd | |
usermod -s /bin/bash tesla | |
useradd -s /bin/bash -G admin,root,sudo,tesla -c "Car OWNER account DO NOT REMOVE" "$accountUserToSaveToCar" | |
echo "$accountUserToSaveToCar":"$accountPassToSaveToCar" | chpasswd | |
fi | |
# Add the $keyToSaveToCar to root, tesla, and $accountUserToSaveToCar | |
grep --quiet "$keyToSaveToCar" /root/.ssh/authorized_keys && echo "Already added key to /root" || echo "$keyToSaveToCar" >>/root/.ssh/authorized_keys | |
grep --quiet "$keyToSaveToCar" /home/tesla/.ssh/authorized_keys && echo "Already added key to /home/tesla" || echo "$keyToSaveToCar" >>/home/tesla/.ssh/authorized_keys | |
grep --quiet "$keyToSaveToCar" /home/"$accountUserToSaveToCar"/.ssh/authorized_keys && echo "Already added key to /home/$accountUserToSaveToCar" || echo "$keyToSaveToCar" >>/home/"$accountUserToSaveToCar"/.ssh/authorized_keys | |
# Housekeeping | |
echo "" >> /etc/sudoers && echo "$accountUserToSaveToCar ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers | |
chown -R tesla:tesla /home/tesla/.ssh | |
chown -R "$accountUserToSaveToCar":"$accountUserToSaveToCar" /home/"$accountUserToSaveToCar" | |
chmod 600 /root/.ssh/authorized_keys && chmod 600 /home/tesla/.ssh/authorized_keys && chmod 600 /home/"$accountUserToSaveToCar"/.ssh/authorized_keys | |
chmod -R 700 "$homeOfLunars" >/dev/null 2>&1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment