diff --git a/README.md b/README.md index 04fa22a..d15d916 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ sw_vers ``` ProductName: macOS -ProductVersion: 13.2 -BuildVersion: 22D49 +ProductVersion: 13.4.1 +BuildVersion: 22F82 ``` ```zsh @@ -19,7 +19,7 @@ zsh --version ``` ``` -zsh 5.8.1 (x86_64-apple-darwin22.0) +zsh 5.9 (x86_64-apple-darwin22.0) ``` ## Installation diff --git a/scripts/git.zsh b/scripts/git.zsh index 20b6f93..a507731 100644 --- a/scripts/git.zsh +++ b/scripts/git.zsh @@ -37,40 +37,68 @@ else echo "Completed installing pinentry-mac ✅ " fi -if gpg --list-secret-keys | grep -q "Tatsuya Okayama " &>/dev/null; then - echo 'Key already exists ✅ ' - exit 0 -fi - mkdir -p "$HOME/.gnupg" && chmod 700 "$HOME/.gnupg" echo "pinentry-program $(which pinentry-mac)" >"$HOME/.gnupg/gpg-agent.conf" gpgconf --kill gpg-agent -if [[ "$GITHUB_ACTIONS" == 'true' ]]; then - gpg --no-tty --pinentry-mode loopback --passphrase passwd --quick-gen-key "Tatsuya Okayama " default default 0 -else - gpg --quick-gen-key "Tatsuya Okayama " default default 0 -fi +function generate_key() { + local CONFIG_NAME=$1 + local USER_NAME=$2 + local EMAIL=$3 + local AUTHOR="$USER_NAME <$EMAIL>" -GPG_KEY_ID=$(gpg --list-secret-keys --with-colons | awk -F: '$1 == "sec" {print $5}' | tail -n 1) -GPG_PUBLIC_KEY=$(gpg --armor --export "$GPG_KEY_ID") - -if [[ "$GITHUB_ACTIONS" != 'true' ]]; then - yes | gh auth login -h github.com -s admin:gpg_key -p https -w - gh api \ - --method POST \ - -H "Accept: application/vnd.github+json" \ - /user/gpg_keys \ - -f name="blendthink's GPG Key" \ - -f armored_public_key="$GPG_PUBLIC_KEY" -fi + if gpg --list-secret-keys | grep -q "$AUTHOR" &>/dev/null; then + echo "Key already exists ✅ : $AUTHOR" + return + fi + + if [[ "$GITHUB_ACTIONS" == 'true' ]]; then + gpg --no-tty --pinentry-mode loopback --passphrase passwd --quick-gen-key "$AUTHOR" default default 0 + else + gpg --quick-gen-key "$AUTHOR" default default 0 + fi + + GPG_KEY_ID=$(gpg --list-secret-keys --with-colons | awk -F: '$1 == "sec" {print $5}' | tail -n 1) + GPG_PUBLIC_KEY=$(gpg --armor --export "$GPG_KEY_ID") + + if [[ "$GITHUB_ACTIONS" != 'true' ]]; then + yes | gh auth login -h github.com -s admin:gpg_key -p https -w + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + /user/gpg_keys \ + -f name="$AUTHOR's GPG Key" \ + -f armored_public_key="$GPG_PUBLIC_KEY" + fi + + cat <>.gitconfig-"$CONFIG_NAME" +[user] + name = "$USER_NAME" + EMAIL = "$EMAIL" + signingkey = "$GPG_KEY_ID" + +EOT +} + +CONFIG_NAME_PRIVATE="private" +CONFIG_NAME_YUMEMI="yumemi" + +USER_NAME="Tatsuya Okayama (blendthink)" + +EMAIL_PRIVATE="admin@blendthink.dev" +EMAIL_YUMEMI="t_okayama@yumemi.co.jp" + +generate_key "$CONFIG_NAME_PRIVATE" "$USER_NAME" "$EMAIL_PRIVATE" git config --global init.defaultBranch main -git config --global user.name blendthink -git config --global user.email admin@blendthink.dev -git config --global user.signingkey "$GPG_KEY_ID" +git config --global user.name "$USER_NAME" +git config --global user.EMAIL "$EMAIL_PRIVATE" git config --global commit.gpgsign true git config --global gpg.program "$(which gpg)" +git config --global includeIf."gitdir:~/Repos/$CONFIG_NAME_PRIVATE/".path ".gitconfig-$CONFIG_NAME_PRIVATE" +git config --global includeIf."gitdir:~/Repos/$CONFIG_NAME_YUMEMI/".path ".gitconfig-$CONFIG_NAME_YUMEMI" + +generate_key "$CONFIG_NAME_YUMEMI" "$USER_NAME" "$EMAIL_YUMEMI" GIT_CONFIG_DIR="$HOME/.config/git" mkdir -p "$GIT_CONFIG_DIR"