Skip to content

Commit

Permalink
Adding some fixies and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardolm committed Dec 19, 2023
1 parent f09f956 commit a86ff9b
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 66 deletions.
1 change: 0 additions & 1 deletion aliases
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ alias gfp='git fetch --prune'
alias go-fix='goimports -w ./..'
alias go-test='go-fix ; go clean -testcache ; go test ./...'
alias go-upgrade='bash -c "sudo $WORKSPACE_USER/update-golang/update-golang.sh"'
alias gofix='goimports-here ; gofmt-here ; go mod tidy'
alias gsl='git stash list'
alias gst="git status --branch --show-stash --untracked-files=all --ignore-submodules=untracked --column=always --renames --find-renames=70%"
alias gt='go test ./...'
Expand Down
66 changes: 36 additions & 30 deletions apt/functions/apt_keys_recovery
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,73 @@ function apt_keys_recovery() {
local file

## 1password
function 1password() {
file=/etc/apt/trusted.gpg.d/1password.gpg
if [ ! -f $file ]; then
log info "1password"

curl -sS https://downloads.1password.com/linux/keys/1password.asc | \
sudo gpg --yes --dearmor --output /usr/share/keyrings/1password-archive-keyring.gpg
curl -fsSL https://downloads.1password.com/linux/keys/1password.asc | \
sudo gpg --yes --dearmor --output $file

[ -f /etc/apt/sources.list.d/1password.list ] && sudo rm -f /etc/apt/sources.list.d/1password.list
/bin/rm -f /etc/apt/sources.list.d/1password.list

echo -n 'deb [arch=amd64 signed-by=/usr/share/keyrings/1password-archive-keyring.gpg]' \
echo -n 'deb [arch=amd64 ' \
"signed-by=${file}] " \
'https://downloads.1password.com/linux/debian/amd64 stable main' | \
sudo tee /etc/apt/sources.list.d/1password.list &>/dev/null
tee /etc/apt/sources.list.d/1password.list &>/dev/null

sudo mkdir -p /etc/debsig/policies/AC2D62742012EA22/
[ -d /etc/debsig/policies/AC2D62742012EA22/ ] || \
sudo mkdir -p /etc/debsig/policies/AC2D62742012EA22/

curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | \
curl -fsSL https://downloads.1password.com/linux/debian/debsig/1password.pol | \
sudo tee /etc/debsig/policies/AC2D62742012EA22/1password.pol &>/dev/null

sudo mkdir -p /usr/share/debsig/keyrings/AC2D62742012EA22

curl -sS https://downloads.1password.com/linux/keys/1password.asc | \
sudo gpg --yes --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg
}
fi

## docker
file=/etc/apt/trusted.gpg.d/docker.gpg
if [ ! -f $file ]; then
log info "docker"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo \
gpg --yes --dearmor --output $file
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --yes --dearmor --output $file
fi

## google cloud platform
file=/etc/apt/trusted.gpg.d/cloud.google.gpg
if [ ! -f $file ]; then
log info "google cloud"
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo \
gpg --yes --dearmor --output $file
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | \
sudo gpg --yes --dearmor --output $file
fi

# order is important
declare -a servers=(
"keyserver.ubuntu.com"
"keys.openpgp.org"
"keys.gnupg.net"
"pgp.mit.edu"
)

[ -f /etc/apt/trusted.gpg ] && sudo /bin/rm /etc/apt/trusted.gpg
[ -f /etc/apt/trusted.gpg ] && sudo /bin/rm -f /etc/apt/trusted.gpg

log info "others sources"

sudo apt-get update 2>/dev/null | \
sed -nr 's/^.*NO_PUBKEY\s(\w{16}).*$/\1/p' | sort | uniq | \
while read -r key; do

sudo apt-get update 2>/dev/null | sed -nr 's/^.*NO_PUBKEY\s(\w{16}).*$/\1/p' | sort | uniq | while read -r key; do
log info "${key}: no pubkey found"
log debug "${key}: no pubkey found"

if [ "$key" == "AC2D62742012EA22" ]; then
1password
else
for server in "${servers[@]}"; do
log info "${key}: trying recover key from ${server}"
sudo apt-key adv --keyserver ${server} --recv-keys ${key} &>/dev/null && log info "${key}: OK" && break || log error "${key}: failed"
done
for server in "${servers[@]}"; do
log debug "${key}: trying recover key from ${server}"
sudo apt-key adv --keyserver ${server} \
--recv-keys "${key}" &>/dev/null \
&& log debug "${key}: OK" && \
break || \
log error "${key}: failed"
done

sudo apt-key export ${key} 2>/dev/null | sudo gpg --batch --yes --dearmour -o /etc/apt/trusted.gpg.d/${key}.gpg
fi
sudo apt-key export "${key}" 2>/dev/null | \
sudo gpg --batch --yes --dearmour \
-o "/etc/apt/trusted.gpg.d/${key}.gpg"

log info "${key}: done"
done
Expand Down
1 change: 1 addition & 0 deletions asdf/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<https://asdf-vm.com/>
50 changes: 50 additions & 0 deletions go/functions/go_upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env zsh

function go_upgrade() {
# shell_debug_relay=$SHELL_DEBUG
# SHELL_DEBUG=true

local latest_version
latest_version=$(curl -sL "https://go.dev/dl/?mode=json" | \
jq --raw-output 'map(select(.stable==true)) | first | .version')

local current_version

if $(command -v go &> /dev/null); then
current_version=$(go version | cut -d' ' -f 3)
fi

if [ "${current_version}" == "" ]; then
log info "go(lang) was not installed yet"

elif [ "${current_version}" == "${latest_version}" ]; then
log info "you are already using the latest version $latest_version"
return

else
log info "the current version is $current_version \nand the latest version is $latest_version"

fi

local filename
filename="${latest_version}.linux-amd64.tar.gz"

local source_path
source_path="$USER_TMP/${filename}"

log debug "downloading 'https://go.dev/dl/${filename}'..."

test -f "${source_path}" && /bin/rm -rf "${source_path}"

curl -sL "https://go.dev/dl/${filename}" -o "${source_path}"

sudo /bin/rm -rf /usr/local/go

log debug "extracting ${filename} to /usr/local/go..."

sudo tar -C /usr/local -xzf "${source_path}"

go version

# SHELL_DEBUG=$shell_debug_relay
}
4 changes: 2 additions & 2 deletions ohmyzsh/start
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

log start "ohmyzsh setup"

. "${DOTFILES}/ohmyzsh/install"
[ -d ${ZSH} ] || . "${DOTFILES}/ohmyzsh/install"

zstyle ':omz:lib:directories' aliases no
zstyle ':omz:lib:docker-compose' aliases no
Expand All @@ -15,7 +15,7 @@ zstyle ':omz:update' mode disabled
plugins=($(ohmyzsh_plugins_list))
log debug "oh-my-zsh plugins loaded: '$plugins'"

. "${ZSH}/oh-my-zsh.sh"
. "${ZSH}/oh-my-zsh.sh" &>/dev/null

unalias sudo

Expand Down
22 changes: 6 additions & 16 deletions ssh/start
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,23 @@ log start "ssh setup"

killall -9 ssh-agent 2>/dev/null

# local ssh_agent_instances=$(ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]')

# log debug "ssh_agent_instances=${ssh_agent_instances}"

function ssh_agent_start() {
log info "starting ssh-agent..."
log debug "starting ssh-agent..."

/bin/rm -f ~/.ssh/ssh-agent.ppid || true
ssh-agent -a ~/.ssh/ssh-agent.ppid -s -t 99999 | tee ~/.ssh/ssh-agent &>/dev/null
source ~/.ssh/ssh-agent &>/dev/null
}

# if [ $ssh_agent_instances -eq 0 ]; then
# ssh_agent_start
# elif [ $ssh_agent_instances -gt 1 ]; then
# killall -9 ssh-agent
ssh_agent_start
# fi
ssh_agent_start

if [ "${SSH_AGENT_PID}" -eq "" ]; then
SSH_AGENT_PID=$(ps axf | grep ssh-agent | grep -v grep | awk '{print $1}')
fi

log debug "SSH_AGENT_PID=${SSH_AGENT_PID}"
log debug "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}"
log debug "SSH_CONNECTION=${SSH_CONNECTION}"
log debug "SSH_AGENT_PID=${SSH_AGENT_PID}" \
"SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" \
"SSH_CONNECTION=${SSH_CONNECTION}"

if [[ "$SSH_AGENT_PID" == "" ]] || [[ "$SSH_AUTH_SOCK" == "" ]]; then
log error "ssh-agent was killed unexpectedly, can't continue to add the keys"
Expand All @@ -42,8 +33,7 @@ fi
log debug "adding my keys to agent..."
ssh-add "${HOME}/.ssh/id_ed25519" &>/dev/null

log info "listing agent´s keys:"
log info "$(ssh-add -L)"
log debug "ssh keys loaded: $(ssh-add -L | cut -d' ' -f1)"

log finish "ssh setup"

Expand Down
1 change: 1 addition & 0 deletions zinit/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<https://github.com/zdharma-continuum/zinit>
4 changes: 2 additions & 2 deletions zplug/start
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ zplug clear
local plugins_list=($(zsh_plugins_list))

for p in $plugins_list; do
log debug "calling zplug to $p"
log debug "zplug adding $p"
zplug "$p"
done

Expand All @@ -28,7 +28,7 @@ if ! zplug check; then
$SHELL_DEBUG && zplug install --verbose || zplug install
fi

log info "loading zplug plugins"
log debug "zplug plugins loading"
# $SHELL_DEBUG && zplug load --verbose || zplug load
zplug load

Expand Down
4 changes: 3 additions & 1 deletion zsh/config/setopt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$SHELL_DEBUG || setopt prompt_subst # if is set, the prompt string is first subjected to parameter expansion, command substitution and arithmetic expansion.

setopt append_history # add cmd to history, don't replace. to share history across sessions.
setopt auto_cd # exec cd if cmd is a folder.
setopt autocd auto_cd # exec cd if cmd is a folder.
setopt beep # beep on error in zle.
setopt complete_aliases # prevents aliases on the command line from being internally substituted before completion is attempted. the effect is to make the alias a distinct command for completion purposes.
setopt complete_in_word # do not go to the end of the word in the completing
Expand All @@ -25,3 +25,5 @@ setopt hist_expire_dups_first # Expire A duplicate event first when trimming his
setopt hist_find_no_dups # Do not display a previously found event.
setopt hist_ignore_space # Do not record an Event Starting With A Space.
setopt hist_save_no_dups # Do not write a duplicate event to the history file.

setopt nomatch notify
2 changes: 1 addition & 1 deletion zsh/functions/auto-ls-custom_function
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

function auto-ls-custom_function() {
echo -e "\nauto-ls-custom_function:\n"
exa -GxFa --icons --group-directories-first --no-filesize --no-user
exa -lGxFa --icons --group-directories-first --no-filesize --no-user
}
14 changes: 7 additions & 7 deletions zsh/functions/iterate_and_load
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

function iterate_and_load() {
local msg="$1"
log start "$msg"

local find_path="$2"
local find_term="$3"
local filter_fn="$4"

log start "$msg"

local cmd="find $find_path -name '$find_term' -print 2>/dev/null | $filter_fn"

log debug "$cmd"
log debug "find_path=${find_path} • find_term=${find_term} • filter_fn=${filter_fn}"

eval "$cmd" | while read -r script_file; do
log debug "$script_file"
eval find "${find_path}" -name "${find_term}" -print 2>/dev/null | \
"${filter_fn}" | \
while read -r script_file; do
log debug "loading $script_file"
# shellcheck source=/dev/null
. "$script_file"
done
Expand Down
4 changes: 2 additions & 2 deletions zsh/functions/log
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env zsh

function log() {
level=$1
local level=$1

silenced_levels=("debug" "start" "finish")
local silenced_levels=("debug" "start" "finish")

if ! $SHELL_DEBUG; then
if [[ ${silenced_levels[@]} =~ $level ]]; then
Expand Down
13 changes: 9 additions & 4 deletions zsh/start
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ $SHELL_DEBUG && set -x

log start "zsh setup"

local autoload_this
local autoload_this &>/dev/null

function autoload_this() {
local functions_path
functions_path=$1
functions_path=( $(eval echo "$functions_path") )

for d in $functions_path; do
log debug "zsh autoload ${d}"
fpath+=("$d")
autoload -Uz ${d}/*(:t)
done
}

autoload_this "/home/bernardo/workspaces/bernardolm/dotfiles/**/functions"
autoload_this "/home/bernardo/sync/**/functions"
autoload_this "${HOME}/workspaces/bernardolm/dotfiles/**/functions"
autoload_this "${HOME}/sync/**/functions"

# autoload -Uz +X compaudit zrecompile # needs description
# autoload -Uz +X bashcompinit; bashcompinit # need to be the first
Expand All @@ -37,7 +38,11 @@ autoload -Uz +X promptinit; promptinit # zsh prompt themes extension completion
iterate_and_load "dotfiles zsh init" "${DOTFILES}/zsh/init" "*.zsh" "sort"
iterate_and_load "sync zsh init" "${SYNC_DOTFILES}/zsh/init" "*.zsh" "sort"

zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
setopt automenu nolistambiguous
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'

zstyle :compinstall filename "${HOME}/.zshrc"

log finish "zsh setup"

Expand Down

0 comments on commit a86ff9b

Please sign in to comment.