Last active
June 25, 2024 04:26
-
-
Save thauber/69c77770520a770942560a2cb09e5526 to your computer and use it in GitHub Desktop.
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/bash | |
################################## FUNCTIONS | |
# Function: sanitize_inputs | |
# Description: Sanitizes the user input, ensuring the existence of the launchsite name | |
function sanitize_inputs() { | |
LAUNCHSITE=$1 | |
function usage { | |
echo "Genesis <launchsite>" | |
echo " This is the setup script for launching a game via launchpad onto a cabinet" | |
echo " This Requires an argument that is the name of the launchsite (eg Brewcade)" | |
} | |
if [[ -z $LAUNCHSITE ]]; then | |
echo "Missing Launchsite" | |
usage | |
exit 1 | |
fi | |
if [[ -n $2 ]] && [[ $2 != "-r" ]]; then | |
echo "Non-standard argument" | |
usage | |
exit 1 | |
fi | |
GH_AUTH_TOKEN=$(sudo cat /media/deathball/GENISIS-KEY/genisis.key) | |
if [[ -z GH_AUTH_TOKEN ]]; then | |
echo "You need an authorized genisis key: missing GH_AUTH_TOKEN" | |
fi | |
} | |
# Function: install_launchpad | |
# Description: Installs the LaunchPad user and keys | |
function install_launchpad { | |
# Create a no-passphrase launch key | |
sudo hostnamectl set-hostname $LAUNCHSITEt stat | |
sudo -u launchpad ssh-keygen -f /home/.launchpad/.ssh/launch-key_rsa -N "" | |
GH_AUTH_TOKEN=$(sudo cat /media/deathball/GENISIS-KEY/genisis.key) | |
# Upload launch key to github with Auth Token from the environment | |
KEYINFO=$(sudo curl -L \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GH_AUTH_TOKEN"\ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/user/keys \ | |
-d "{\"title\":\"LaunchSite [`echo $LAUNCHSITE`]\", \"key\":\"$(cat /home/.launchpad/.ssh/launch-key_rsa.pub)\"}" | |
) | |
echo "$KEYINFO" | |
# Create the ssh config | |
sudo echo "Host * | |
IdentityFile ~/.ssh/launch-key_rsa" > /home/.launchpad/.ssh/config | |
# Initialize Git repository | |
cd /home/.launchpad | |
sudo -u launchpad git checkout stable | |
sudo -u launchpad git fetch | |
sudo -u launchpad git pull --rebase | |
echo "Prompt=never" | sudo tee /etc/update-manager/release-upgrades | |
sudo systemctl disable --now unattended-upgrades | |
} | |
sanitize_inputs $1 $2 | |
install_launchpad | |
# Reboot (only executes with -r argument) | |
if [[ $2 = "-r" ]]; then | |
reboot | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment