configs/daily-use-pcs/setup-git.bash

55 lines
1.7 KiB
Bash
Raw Normal View History

#!/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-09-13 07:58:18 -05:00
GIT_NAME="askiiart"
GIT_EMAIL="dev@askiiart.net"
2023-10-10 13:27:57 -05:00
KEY_ID="02EFA1CE3C3E4AAD7A863AB8ED24985CA884CD61"
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
command_exists() { type "$1" &>/dev/null; }
if command_exists "apt-get"; then
2024-03-17 18:56:48 -05:00
sudo apt-get install git -y
elif command_exists "yum"; then
2024-03-17 18:56:48 -05:00
sudo yum install git -y
elif command_exists "pacman"; then
2023-09-07 09:13:31 -05:00
sudo pacman -S git --noconfirm --needed
elif command_exists "zypp"; then
2024-03-17 18:56:48 -05:00
sudo zypper install git -y
elif command_exists "emerge"; then
2023-09-06 15:18:40 -05:00
sudo echo Not yet supported, exiting...
elif command_exists "apk"; then
2023-09-06 15:18:40 -05:00
sudo apk add git
else
echo "Unsupported: unknown package manager and distro"
fi
2023-08-19 17:04:13 -05:00
############################################
# Do GPG key stuff for commit verification #
############################################
2023-09-13 08:23:45 -05:00
git config --global user.name "${GIT_NAME}"
git config --global user.email "${GIT_EMAIL}"
2023-10-10 13:27:57 -05:00
git config --global commit.gpgsign true
git config --global user.signingkey ${KEY_ID}
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/*
2024-03-17 18:56:48 -05:00
# Fixes dirmngr stuff (for Arch)
2023-09-07 16:34:26 -05:00
sudo chmod 700 $(ls -d $HOME/.gnupg/*/)