Skip to content

Commit 817c6e8

Browse files
paulopattoPaulo 'Patto' Santos
andauthored
fix(git): ssh program (#95)
Co-authored-by: Paulo 'Patto' Santos <paulopatto@MacBookPro.bbrouter>
1 parent e7bbf6f commit 817c6e8

File tree

9 files changed

+180
-17
lines changed

9 files changed

+180
-17
lines changed

.github/workflows/CI.yaml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ jobs:
3838
- name: Install bats and helpers
3939
run: npm ci
4040

41-
- name: Run install script (make bootstrap)
42-
run: make bootstrap
43-
44-
- name: Run stow to link config files (make link)
45-
run: make link
41+
- name: Run install script (make all)
42+
run: make all
4643

4744
- name: Add bats to PATH
4845
run: echo "$(npm bin)" >> $GITHUB_PATH
@@ -71,11 +68,8 @@ jobs:
7168
- name: Install bats and helpers
7269
run: npm ci
7370

74-
- name: Run install script (make bootstrap)
75-
run: make bootstrap
76-
77-
- name: Run stow to link config files (make link)
78-
run: make link
71+
- name: Run install script (make all)
72+
run: make all
7973

8074
- name: Add bats to PATH
8175
run: echo "$(npm bin)" >> $GITHUB_PATH

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ tmux/.config/tmux/plugins/tpm/
66
.bootstrap
77
node_modules/
88
zsh/.config/zsh/envs/
9+
zshrc
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# vim: ft=gitconfig
2-
# ~/.gitconfig
2+
# ~/.config/git/config
3+
# https://git-scm.com/docs/git-config#_environment
34
[user]
45
name = Paulo Patto
56
email = paulopatto@paulopatto.com

git/.config/git/git-gpg-wrapper.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
case "$(uname -s)" in
4+
Darwin)
5+
exec /Applications/1Password.app/Contents/MacOS/op-ssh-sign "$@"
6+
;;
7+
Linux)
8+
exec /opt/1Password/op-ssh-sign "$@"
9+
;;
10+
*)
11+
echo "Unsupported OS $(uname -s)" >&2
12+
exit 1
13+
;;
14+
esac

installer/1password_formula.bash

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# -----------------------------------------------------------------------------
2+
# Instala o 1Password em sistemas Linux seguindo o passo a passo
3+
# oficial da 1Password.
4+
#
5+
# Referência:
6+
# Documentação oficial: https://1password.com/downloads/linux
7+
# -----------------------------------------------------------------------------
8+
function install_1password() {
9+
10+
if [ -f /opt/1Password/op-ssh-sign ]; then
11+
echo "✔️ 1Password já instalado."
12+
return
13+
fi
14+
15+
echo "🗝️ Instalando 1Password..."
16+
17+
case $PLATFORM_OS in
18+
Fedora)
19+
install_1password_fedora
20+
;;
21+
Ubuntu)
22+
install_1password_debian_or_ubuntu
23+
;;
24+
MacOS)
25+
echo "1Password no MacOS deve ser instalado via Homebrew ou manualmente."
26+
;;
27+
*)
28+
echo "Invalid option $PLATFORM_ARCH"
29+
esac
30+
31+
if [ $? -eq 0 ]; then
32+
echo "✔️ 1Password instalado com sucesso."
33+
else
34+
echo "☠️ Falha ao instalar o 1Password."
35+
exit 1
36+
fi
37+
}
38+
39+
40+
# -----------------------------------------------------------------------------
41+
# install_1password_debian_or_ubuntu
42+
#
43+
# Instala o 1Password em sistemas Debian ou Ubuntu seguindo o passo a passo
44+
# oficial da 1Password.
45+
#
46+
# Passos realizados por esta função:
47+
# 1. Adiciona o repositório oficial da 1Password.
48+
# 2. Importa a chave GPG do repositório.
49+
# 3. Atualiza a lista de pacotes.
50+
# 4. Instala o pacote 1password.
51+
#
52+
# Requisitos:
53+
# - Permissões de superusuário (sudo).
54+
# - Conexão com a internet.
55+
#
56+
# Limitações e melhorias:
57+
# - Atualmente, esta função só da suporte a plataformas x86_64 (amd64).
58+
#
59+
# Referência:
60+
# Documentação oficial: https://support.1password.com/install-linux/#debian-or-ubuntu
61+
# -----------------------------------------------------------------------------
62+
function install_1password_debian_or_ubuntu() {
63+
_add_key_for_the_1Password_apt_repository_and_add_apt_repo
64+
sudo apt-get update -qq
65+
sudo apt-get install -y 1password
66+
}
67+
68+
function _add_key_for_the_1Password_apt_repository_and_add_apt_repo() {
69+
curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo gpg --dearmor --output /usr/share/keyrings/1password-archive-keyring.gpg
70+
echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/1password-archive-keyring.gpg] https://downloads.1password.com/linux/debian/amd64 stable main' | sudo tee /etc/apt/sources.list.d/1password.list
71+
sudo mkdir -p /etc/debsig/policies/AC2D62742012EA22/
72+
curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | sudo tee /etc/debsig/policies/AC2D62742012EA22/1password.pol
73+
sudo mkdir -p /usr/share/debsig/keyrings/AC2D62742012EA22
74+
curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo gpg --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg
75+
}
76+
77+
# -----------------------------------------------------------------------------
78+
# install_1password_fedora
79+
#
80+
# Instala o 1Password em sistemas Fedora seguindo o passo a passo
81+
# oficial da 1Password.
82+
#
83+
# Passos realizados por esta função:
84+
# 1. Adiciona o repositório oficial da 1Password.
85+
# 2. Importa a chave GPG do repositório.
86+
# 3. Atualiza a lista de pacotes.
87+
# 4. Instala o pacote 1password.
88+
#
89+
# Requisitos:
90+
# - Permissões de superusuário (sudo).
91+
# - Conexão com a internet.
92+
#
93+
#
94+
# Referência:
95+
# Documentação oficial: https://support.1password.com/install-linux/#fedora-or-red-hat-enterprise-linux
96+
# -----------------------------------------------------------------------------
97+
function install_1password_fedora() {
98+
_add_key_for_the_1Password_yum_repository
99+
sudo dnf install -y 1password
100+
}
101+
102+
function _add_key_for_the_1Password_yum_repository() {
103+
sudo rpm --import https://downloads.1password.com/linux/keys/1password.asc
104+
sudo sh -c 'echo -e "[1password]\nname=1Password Stable Channel\nbaseurl=https://downloads.1password.com/linux/rpm/stable/\$basearch\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=\"https://downloads.1password.com/linux/keys/1password.asc\"" > /etc/yum.repos.d/1password.repo'
105+
}

installer/bootstrap.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ source ./installer/brew_packages.bash
66
source ./installer/lazy_packages.bash
77
source ./installer/zplug_formula.bash
88
source ./installer/tmux_formula.bash
9+
source ./installer/1password_formula.bash
910

1011
export XDG_CONFIG_HOME=$HOME/.config
1112

@@ -21,14 +22,16 @@ main() {
2122
echo "Bootstrapping system dependencies..."
2223
echo "🔍 Verificando e instalando pacotes base..."
2324
if [[ "$(uname -s)" == "Darwin" ]]; then
24-
PLATFORM_OS="MacOS"
25-
PLATFORM_ARCH="Darwin"
25+
export PLATFORM_OS="MacOS"
26+
export PLATFORM_ARCH="Darwin"
27+
ln -sf $HOME/.config/git/gitconfig-osx $HOME/.gitconfig-ssh
2628
elif [[ "$(uname -s)" == "Linux" ]]; then
27-
PLATFORM_ARCH="Linux"
29+
export PLATFORM_ARCH="Linux"
30+
ln -sf $HOME/.config/git/gitconfig-linux $HOME/.gitconfig-ssh
2831
if command -v dnf >/dev/null; then
29-
PLATFORM_OS="Fedora"
32+
export PLATFORM_OS="Fedora"
3033
elif command -v apt >/dev/null; then
31-
PLATFORM_OS="Ubuntu"
34+
export PLATFORM_OS="Ubuntu"
3235
else
3336
echo "☠️ Distribuição Linux não suportada (nem dnf, nem apt encontrados)."
3437
exit 1
@@ -45,6 +48,7 @@ main() {
4548
change_shell_to_zsh
4649
ensure_zplug_installed
4750
ensure_tmux_tpm_installed
51+
install_1password
4852
echo "🎉 Bootstrap concluído com sucesso!"
4953
}
5054

@@ -67,7 +71,7 @@ function install_os_packages() {
6771
function change_shell_to_zsh() {
6872
if command -v zsh >/dev/null 2>&1; then
6973
echo "✔️ Zsh já instalado."
70-
if [ "$SHELL" != "$(which zsh)" ]; then
74+
if [[ "$SHELL" != *zsh* ]]; then
7175
echo "🔄 Alterando shell padrão para zsh..."
7276
chsh -s "$(which zsh)"
7377
echo "✔️ Shell padrão alterado para zsh. Por favor, reinicie o terminal."

tests/02-stow-structure.test.bash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ load test_helper
1717
assert_file_exists "$HOME/.config/tmux/tmux.conf"
1818
}
1919

20+
@test "it git folder in XDG_CONFIG_HOME exists in the new structure" {
21+
assert_dir_exists "$HOME/.config/git/"
22+
}
23+
24+
@test "it zplug folder in XDG_CONFIG_HOME exists in the new structure" {
25+
assert_dir_exists "$HOME/.config/zsh/plugins/zplug"
26+
}
27+
2028
@test "it MCPHUB folder in XDG_CONFIG_HOME exists in the new structure" {
2129
assert_dir_exists "$HOME/.config/mcphub"
2230
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bats
2+
load test_helper
3+
4+
@test "it git config in XDG_CONFIG_HOME exists in the new structure" {
5+
assert_file_exists "$HOME/.config/git/config"
6+
}
7+
8+
@test "it git zsh envs exists" {
9+
assert_file_exists "$HOME/.config/zsh/envs/git.env.zsh"
10+
}
11+
12+
@test "it environment variable GIT_CONFIG_GPG_SSH_PROGRAM is set in git.env.zsh" {
13+
run grep 'export GIT_CONFIG_GPG_SSH_PROGRAM=' "$HOME/.config/zsh/envs/git.env.zsh"
14+
[ "$status" -eq 0 ]
15+
}
16+
17+
@test "it gitconfig-ssh symlink exists" {
18+
assert_file_exists "$HOME/.gitconfig-ssh"
19+
}

zsh/.config/zsh/envs/git.env.zsh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Read: https://developer.1password.com/docs/ssh/get-started/
2+
# https://git-scm.com/docs/git-config#_environment
3+
case "$(uname -s)" in
4+
Darwin)
5+
export GIT_CONFIG_GPG_SSH_PROGRAM="/Applications/1Password.app/Contents/MacOS/op-ssh-sign"
6+
;;
7+
Linux)
8+
export GIT_CONFIG_GPG_SSH_PROGRAM="/opt/1Password/op-ssh-sign"
9+
;;
10+
*)
11+
echo "Unsupported OS $(uname -s)" >&2
12+
exit 1
13+
;;
14+
esac
15+
export GIT_CONFIG_COUNT=1
16+
export GIT_CONFIG_KEY_0=gpg.program
17+
export GIT_CONFIG_VALUE_0=$GIT_CONFIG_GPG_SSH_PROGRAM

0 commit comments

Comments
 (0)