2023-08-23 21:25:12 -05:00
|
|
|
#!/usr/bin/env bash
|
2023-08-21 13:13:13 -05:00
|
|
|
# Exit if there's an error
|
|
|
|
set -e
|
2023-08-20 21:35:16 -05:00
|
|
|
# Modify constants as needed
|
2023-08-21 12:02:10 -05:00
|
|
|
GITEA_URL="https://git.askiiart.net"
|
2023-08-31 10:28:37 -05:00
|
|
|
NAME="askiiart"
|
2023-08-21 12:02:10 -05:00
|
|
|
EMAIL="dev@askiiart.net"
|
2023-08-20 21:35:16 -05:00
|
|
|
|
|
|
|
# Note: This waits until enter is pressed
|
2023-08-19 17:04:13 -05:00
|
|
|
# read -p "Press Enter to continue" < /dev/tty
|
|
|
|
|
2023-09-06 15:18:40 -05:00
|
|
|
if [ $(whoami) == "root" ]; then
|
2023-08-30 22:15:13 -05:00
|
|
|
echo "Run as a normal user, not root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-08-28 18:01:19 -05:00
|
|
|
command_exists() { type "$1" &>/dev/null; }
|
2023-08-23 21:25:12 -05:00
|
|
|
|
|
|
|
if command_exists "apt-get"; then
|
2023-09-06 15:18:40 -05:00
|
|
|
sudo apt-get install pass git -y
|
2023-08-23 21:25:12 -05:00
|
|
|
elif command_exists "yum"; then
|
2023-09-06 15:18:40 -05:00
|
|
|
sudo yum install pass git -y
|
2023-08-23 21:25:12 -05:00
|
|
|
elif command_exists "pacman"; then
|
2023-09-06 15:18:40 -05:00
|
|
|
sudo pacman -S git --noconfirm
|
|
|
|
sudo pacman -S pass --noconfirm
|
2023-08-23 21:25:12 -05:00
|
|
|
elif command_exists "zypp"; then
|
2023-09-06 15:18:40 -05:00
|
|
|
sudo zypper install pass git -y
|
2023-08-23 21:25:12 -05:00
|
|
|
elif command_exists "emerge"; then
|
2023-09-06 15:18:40 -05:00
|
|
|
sudo echo Not yet supported, exiting...
|
2023-08-23 21:25:12 -05:00
|
|
|
elif command_exists "apk"; then
|
2023-09-06 15:18:40 -05:00
|
|
|
sudo apk add pass
|
|
|
|
sudo apk add git
|
2023-08-23 21:25:12 -05:00
|
|
|
else
|
2023-09-06 20:54:23 -05:00
|
|
|
echo "Unsupported: unknown package manager and distro"
|
2023-08-23 21:25:12 -05:00
|
|
|
fi
|
|
|
|
|
2023-08-21 22:08:51 -05:00
|
|
|
# Check if GCM is installed
|
2023-08-31 10:28:37 -05:00
|
|
|
if [ -d "${HOME}/git-credential-manager" ]; then
|
2023-08-21 22:08:51 -05:00
|
|
|
echo "Git Credential Manager already installed, skipping..."
|
|
|
|
else
|
|
|
|
# Install git credential manager
|
|
|
|
curl -L https://aka.ms/gcm/linux-install-source.sh | sh
|
|
|
|
git-credential-manager configure
|
2023-08-31 10:28:37 -05:00
|
|
|
rm dotnet-install.sh
|
2023-08-21 22:08:51 -05:00
|
|
|
fi
|
2023-08-19 17:04:13 -05:00
|
|
|
|
|
|
|
############################################
|
|
|
|
# Do GPG key stuff for commit verification #
|
|
|
|
############################################
|
2023-08-31 10:28:37 -05:00
|
|
|
if [ -d "${HOME}/.gnupg/" ]; then
|
|
|
|
echo "GPG key(s) already exist, skipping..."
|
|
|
|
else
|
2023-08-19 17:04:13 -05:00
|
|
|
# Create GPG key
|
2023-08-31 10:28:37 -05:00
|
|
|
echo "> $ gpg --full-generate-key"
|
|
|
|
echo
|
|
|
|
echo Use the defaults, then real name "askiiart", email address \"dev@askiiart.net\", and comment \"git key\"\n
|
|
|
|
echo
|
|
|
|
gpg --full-generate-key
|
|
|
|
read -p "Copy the long ID above, then paste it here: " KEY_ID
|
|
|
|
echo $KEY_ID
|
2023-08-19 17:04:13 -05:00
|
|
|
|
2023-08-31 10:28:37 -05:00
|
|
|
# Export GPG key
|
|
|
|
gpg --armor --export $KEY_ID
|
|
|
|
echo This is the exported key, copy it and put it in GitHub/Gitea/whatever
|
|
|
|
echo Gitea URL: ${GITEA_URL}/user/settings/keys
|
|
|
|
echo GitHub URL: https://github.com/settings/gpg/new
|
|
|
|
read -p "Press enter when you're done" </dev/tty
|
2023-09-07 08:17:15 -05:00
|
|
|
else
|
|
|
|
gpg --list-keys
|
|
|
|
read -p "Enter the long ID of the key to be used for git:" KEY_ID
|
2023-08-31 10:28:37 -05:00
|
|
|
fi
|
2023-08-21 12:02:10 -05:00
|
|
|
|
2023-08-31 10:28:37 -05:00
|
|
|
echo Doing git config stuff...
|
2023-08-21 12:06:09 -05:00
|
|
|
git config --global credential.credentialStore gpg
|
2023-08-31 10:28:37 -05:00
|
|
|
git config --global user.name "${NAME}"
|
|
|
|
git config --global user.email "${EMAIL}"
|
2023-09-07 08:17:15 -05:00
|
|
|
git config --global user.signingkey ${KEY_ID}
|
2023-09-07 09:02:03 -05:00
|
|
|
git config --global commit.gpgsign true
|
|
|
|
pass init ${KEY_ID}
|
2023-08-21 12:06:09 -05:00
|
|
|
|
2023-08-19 17:04:13 -05:00
|
|
|
#############
|
|
|
|
# SSH stuff #
|
|
|
|
#############
|
|
|
|
|
|
|
|
# Get SSH key
|
2023-08-31 10:28:37 -05:00
|
|
|
if [ -d "${HOME}/.ssh" ]; then
|
|
|
|
echo "SSH keys already exist, skipping..."
|
|
|
|
else
|
|
|
|
# Generate SSH keys
|
|
|
|
echo
|
|
|
|
# -f: file, -N: passphrase, -t: type
|
|
|
|
ssh-keygen -f ~/.ssh/id_rsa -N "" -t rsa
|
|
|
|
echo
|
|
|
|
cat ~/.ssh/id_rsa.pub
|
|
|
|
echo This is the SSH public key, copy it and put it in GitHub/Gitea/whatever
|
|
|
|
echo Gitea URL: ${GITEA_URL}/user/settings/keys
|
|
|
|
echo GitHub URL: https://github.com/settings/ssh/new
|
|
|
|
fi
|
2023-09-01 06:58:35 -05:00
|
|
|
|
|
|
|
# From https://superuser.com/a/954639
|
|
|
|
# Archived at https://web.archive.org/web/20230606153856/https://superuser.com/a/954639
|
|
|
|
echo Fixing .gnupg/ permissions
|
|
|
|
# Set ownership to your own user and primary group
|
|
|
|
chown -R "$USER:$(id -gn)" ~/.gnupg
|
|
|
|
# Set permissions to read, write, execute for only yourself, no others
|
|
|
|
chmod 700 ~/.gnupg
|
|
|
|
# Set permissions to read, write for only yourself, no others
|
|
|
|
chmod 600 ~/.gnupg/*
|
2023-08-19 17:06:40 -05:00
|
|
|
|
2023-08-28 18:01:19 -05:00
|
|
|
read -p "Done. Now verify your SSH and GPG keys in Git*" </dev/tty
|