From a342a985feb51715c9ad11a5631be3b2ffe5fd88 Mon Sep 17 00:00:00 2001 From: Shunsuke KITADA Date: Thu, 24 Oct 2024 11:37:08 +0900 Subject: [PATCH] Use `git credential manager` in Ubuntu Server (#237) * use `git-credential-manager` in Ubuntu Server * add test --- ...run_once_12-git-credential-manager.sh.tmpl | 7 +++++ home/dot_config/git/config.tmpl | 11 +++---- .../ubuntu/server/git_credential_manager.sh | 29 +++++++++++++++++++ .../ubuntu/server/git_credential_manager.bats | 17 +++++++++++ 4 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 home/.chezmoiscripts/ubuntu/run_once_12-git-credential-manager.sh.tmpl create mode 100644 install/ubuntu/server/git_credential_manager.sh create mode 100644 tests/install/ubuntu/server/git_credential_manager.bats diff --git a/home/.chezmoiscripts/ubuntu/run_once_12-git-credential-manager.sh.tmpl b/home/.chezmoiscripts/ubuntu/run_once_12-git-credential-manager.sh.tmpl new file mode 100644 index 00000000..fe3fbaff --- /dev/null +++ b/home/.chezmoiscripts/ubuntu/run_once_12-git-credential-manager.sh.tmpl @@ -0,0 +1,7 @@ +{{ if eq .chezmoi.os "linux" -}} +{{ if eq .chezmoi.osRelease.idLike "debian" -}} +{{ if eq .system "server" -}} +{{ include "../install/ubuntu/server/git_credential_manager.sh" }} +{{ end -}} +{{ end -}} +{{ end -}} diff --git a/home/dot_config/git/config.tmpl b/home/dot_config/git/config.tmpl index 36abea4f..4b5001ab 100644 --- a/home/dot_config/git/config.tmpl +++ b/home/dot_config/git/config.tmpl @@ -2,26 +2,23 @@ name = Shunsuke KITADA email = {{ .email | quote }} signingkey = D55D775A7951407C - [color] ui = auto - [url "git@github.com:"] pushinsteadof = https://github.com/ - [pager] branch = cat config = cat - [ghq] root = ~/.local/share root = ~/ghq - [commit] gpgsign = true - [pull] rebase = false - [core] quotepath = false +{{ if eq .chezmoi.os "linux" -}} +[credential] + credentialStore = cache +{{ end -}} diff --git a/install/ubuntu/server/git_credential_manager.sh b/install/ubuntu/server/git_credential_manager.sh new file mode 100644 index 00000000..a10d1730 --- /dev/null +++ b/install/ubuntu/server/git_credential_manager.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +if [ "${DOTFILES_DEBUG:-}" ]; then + set -x +fi + +function install_git_credential_manager() { + local gcm_version="2.6.0" + local gcm_deb="gcm-linux_amd64.${gcm_version}.deb" + wget "https://github.com/git-ecosystem/git-credential-manager/releases/download/v${gcm_version}/${gcm_deb}" + sudo dpkg -i ${gcm_deb} + rm -v ${gcm_deb} + git-credential-manager configure +} + +function uninstall_git_credential_manager() { + git-credential-manager unconfigure + sudo dpkg -r gcm +} + +function main() { + install_git_credential_manager +} + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + main +fi diff --git a/tests/install/ubuntu/server/git_credential_manager.bats b/tests/install/ubuntu/server/git_credential_manager.bats new file mode 100644 index 00000000..adb27f30 --- /dev/null +++ b/tests/install/ubuntu/server/git_credential_manager.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +readonly SCRIPT_PATH="./install/ubuntu/server/git_credential_manager.sh" + +function setup() { + source "${SCRIPT_PATH}" +} + +function teardown() { + run uninstall_git_credential_manager +} + +@test "[ubuntu-server] starship" { + DOTFILES_DEBUG=1 bash "${SCRIPT_PATH}" + + [ -x "$(command -v git-credential-manager)" ] +}