Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ jobs:
- name: Install bats and helpers
run: npm ci

- name: Run install script (make bootstrap)
run: make bootstrap

- name: Run stow to link config files (make link)
run: make link
- name: Run install script (make all)
run: make all

- name: Add bats to PATH
run: echo "$(npm bin)" >> $GITHUB_PATH
Expand Down Expand Up @@ -71,11 +68,8 @@ jobs:
- name: Install bats and helpers
run: npm ci

- name: Run install script (make bootstrap)
run: make bootstrap

- name: Run stow to link config files (make link)
run: make link
- name: Run install script (make all)
run: make all

- name: Add bats to PATH
run: echo "$(npm bin)" >> $GITHUB_PATH
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tmux/.config/tmux/plugins/tpm/
.bootstrap
node_modules/
zsh/.config/zsh/envs/
zshrc
3 changes: 2 additions & 1 deletion git/.config/git/.gitconfig → git/.config/git/config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# vim: ft=gitconfig
# ~/.gitconfig
# ~/.config/git/config
# https://git-scm.com/docs/git-config#_environment
[user]
name = Paulo Patto
email = paulopatto@paulopatto.com
Expand Down
14 changes: 14 additions & 0 deletions git/.config/git/git-gpg-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

case "$(uname -s)" in
Darwin)
exec /Applications/1Password.app/Contents/MacOS/op-ssh-sign "$@"
;;
Linux)
exec /opt/1Password/op-ssh-sign "$@"
;;
*)
echo "Unsupported OS $(uname -s)" >&2
exit 1
;;
esac
105 changes: 105 additions & 0 deletions installer/1password_formula.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# -----------------------------------------------------------------------------
# Instala o 1Password em sistemas Linux seguindo o passo a passo
# oficial da 1Password.
#
# Referência:
# Documentação oficial: https://1password.com/downloads/linux
# -----------------------------------------------------------------------------
function install_1password() {

if [ -f /opt/1Password/op-ssh-sign ]; then
echo "✔️ 1Password já instalado."
return
fi

echo "🗝️ Instalando 1Password..."

case $PLATFORM_OS in
Fedora)
install_1password_fedora
;;
Ubuntu)
install_1password_debian_or_ubuntu
;;
MacOS)
echo "1Password no MacOS deve ser instalado via Homebrew ou manualmente."
;;
*)
echo "Invalid option $PLATFORM_ARCH"
esac

if [ $? -eq 0 ]; then
echo "✔️ 1Password instalado com sucesso."
else
echo "☠️ Falha ao instalar o 1Password."
exit 1
fi
}


# -----------------------------------------------------------------------------
# install_1password_debian_or_ubuntu
#
# Instala o 1Password em sistemas Debian ou Ubuntu seguindo o passo a passo
# oficial da 1Password.
#
# Passos realizados por esta função:
# 1. Adiciona o repositório oficial da 1Password.
# 2. Importa a chave GPG do repositório.
# 3. Atualiza a lista de pacotes.
# 4. Instala o pacote 1password.
#
# Requisitos:
# - Permissões de superusuário (sudo).
# - Conexão com a internet.
#
# Limitações e melhorias:
# - Atualmente, esta função só da suporte a plataformas x86_64 (amd64).
#
# Referência:
# Documentação oficial: https://support.1password.com/install-linux/#debian-or-ubuntu
# -----------------------------------------------------------------------------
function install_1password_debian_or_ubuntu() {
_add_key_for_the_1Password_apt_repository_and_add_apt_repo
sudo apt-get update -qq
sudo apt-get install -y 1password
}

function _add_key_for_the_1Password_apt_repository_and_add_apt_repo() {
curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo gpg --dearmor --output /usr/share/keyrings/1password-archive-keyring.gpg
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
sudo mkdir -p /etc/debsig/policies/AC2D62742012EA22/
curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | sudo tee /etc/debsig/policies/AC2D62742012EA22/1password.pol
sudo mkdir -p /usr/share/debsig/keyrings/AC2D62742012EA22
curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo gpg --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg
}

# -----------------------------------------------------------------------------
# install_1password_fedora
#
# Instala o 1Password em sistemas Fedora seguindo o passo a passo
# oficial da 1Password.
#
# Passos realizados por esta função:
# 1. Adiciona o repositório oficial da 1Password.
# 2. Importa a chave GPG do repositório.
# 3. Atualiza a lista de pacotes.
# 4. Instala o pacote 1password.
#
# Requisitos:
# - Permissões de superusuário (sudo).
# - Conexão com a internet.
#
#
# Referência:
# Documentação oficial: https://support.1password.com/install-linux/#fedora-or-red-hat-enterprise-linux
# -----------------------------------------------------------------------------
function install_1password_fedora() {
_add_key_for_the_1Password_yum_repository
sudo dnf install -y 1password
}

function _add_key_for_the_1Password_yum_repository() {
sudo rpm --import https://downloads.1password.com/linux/keys/1password.asc
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'
}
16 changes: 10 additions & 6 deletions installer/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source ./installer/brew_packages.bash
source ./installer/lazy_packages.bash
source ./installer/zplug_formula.bash
source ./installer/tmux_formula.bash
source ./installer/1password_formula.bash

export XDG_CONFIG_HOME=$HOME/.config

Expand All @@ -21,14 +22,16 @@ main() {
echo "Bootstrapping system dependencies..."
echo "🔍 Verificando e instalando pacotes base..."
if [[ "$(uname -s)" == "Darwin" ]]; then
PLATFORM_OS="MacOS"
PLATFORM_ARCH="Darwin"
export PLATFORM_OS="MacOS"
export PLATFORM_ARCH="Darwin"
ln -sf $HOME/.config/git/gitconfig-osx $HOME/.gitconfig-ssh
elif [[ "$(uname -s)" == "Linux" ]]; then
PLATFORM_ARCH="Linux"
export PLATFORM_ARCH="Linux"
ln -sf $HOME/.config/git/gitconfig-linux $HOME/.gitconfig-ssh
if command -v dnf >/dev/null; then
PLATFORM_OS="Fedora"
export PLATFORM_OS="Fedora"
elif command -v apt >/dev/null; then
PLATFORM_OS="Ubuntu"
export PLATFORM_OS="Ubuntu"
else
echo "☠️ Distribuição Linux não suportada (nem dnf, nem apt encontrados)."
exit 1
Expand All @@ -45,6 +48,7 @@ main() {
change_shell_to_zsh
ensure_zplug_installed
ensure_tmux_tpm_installed
install_1password
echo "🎉 Bootstrap concluído com sucesso!"
}

Expand All @@ -67,7 +71,7 @@ function install_os_packages() {
function change_shell_to_zsh() {
if command -v zsh >/dev/null 2>&1; then
echo "✔️ Zsh já instalado."
if [ "$SHELL" != "$(which zsh)" ]; then
if [[ "$SHELL" != *zsh* ]]; then
echo "🔄 Alterando shell padrão para zsh..."
chsh -s "$(which zsh)"
echo "✔️ Shell padrão alterado para zsh. Por favor, reinicie o terminal."
Expand Down
8 changes: 8 additions & 0 deletions tests/02-stow-structure.test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ load test_helper
assert_file_exists "$HOME/.config/tmux/tmux.conf"
}

@test "it git folder in XDG_CONFIG_HOME exists in the new structure" {
assert_dir_exists "$HOME/.config/git/"
}

@test "it zplug folder in XDG_CONFIG_HOME exists in the new structure" {
assert_dir_exists "$HOME/.config/zsh/plugins/zplug"
}

@test "it MCPHUB folder in XDG_CONFIG_HOME exists in the new structure" {
assert_dir_exists "$HOME/.config/mcphub"
}
19 changes: 19 additions & 0 deletions tests/04-validates-git-config.test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bats
load test_helper

@test "it git config in XDG_CONFIG_HOME exists in the new structure" {
assert_file_exists "$HOME/.config/git/config"
}

@test "it git zsh envs exists" {
assert_file_exists "$HOME/.config/zsh/envs/git.env.zsh"
}

@test "it environment variable GIT_CONFIG_GPG_SSH_PROGRAM is set in git.env.zsh" {
run grep 'export GIT_CONFIG_GPG_SSH_PROGRAM=' "$HOME/.config/zsh/envs/git.env.zsh"
[ "$status" -eq 0 ]
}

@test "it gitconfig-ssh symlink exists" {
assert_file_exists "$HOME/.gitconfig-ssh"
}
17 changes: 17 additions & 0 deletions zsh/.config/zsh/envs/git.env.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Read: https://developer.1password.com/docs/ssh/get-started/
# https://git-scm.com/docs/git-config#_environment
case "$(uname -s)" in
Darwin)
export GIT_CONFIG_GPG_SSH_PROGRAM="/Applications/1Password.app/Contents/MacOS/op-ssh-sign"
;;
Linux)
export GIT_CONFIG_GPG_SSH_PROGRAM="/opt/1Password/op-ssh-sign"
;;
*)
echo "Unsupported OS $(uname -s)" >&2
exit 1
;;
esac
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0=gpg.program
export GIT_CONFIG_VALUE_0=$GIT_CONFIG_GPG_SSH_PROGRAM
Loading