Push improvements form the PQB work

This commit is contained in:
Gal Szkolnik 2022-09-29 18:29:13 -04:00
parent f3323b159b
commit 1e3c60630e
68 changed files with 409 additions and 219 deletions

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 710 B

After

Width:  |  Height:  |  Size: 710 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1012 B

After

Width:  |  Height:  |  Size: 1012 B

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 189 KiB

View File

Before

Width:  |  Height:  |  Size: 743 B

After

Width:  |  Height:  |  Size: 743 B

View File

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 612 B

After

Width:  |  Height:  |  Size: 612 B

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,8 +1,8 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
[ -z ${DBG_SZSHRC} ] || echo "Entered .bashrc"
[ -z ${DBG_SHRC} ] || echo "Entered .bashrc"
[[ -r ~/.sz.shrc ]] && source ~/.sz.shrc
[ -z ${DBG_SZSHRC} ] || echo "Exiting .bashrc"
[ -z ${DBG_SHRC} ] || echo "Exiting .bashrc"

View File

@ -74,14 +74,14 @@
],
"background": "red",
"background_templates": [
"{{ if contains \"true\" .Output }}#DD7700{{ end }}"
"{{ if contains \"true\" .Output }}#4063D8{{ end }}"
],
"powerline_symbol": "",
"invert_powerline": true,
"style": "powerline",
"properties": {
"shell": "bash",
"command": "type -t direnv 2>/dev/null && { direnv status 2>&1 || true; } | grep \"Found RC allowed\"; true"
"command": "type -t direnv 2>&1 > /dev/null && direnv status 2>&1 | grep 'Found RC allowed'"
},
"template": "{{ if .Output }}.{{ end }}"
},
@ -93,14 +93,14 @@
],
"background": "red",
"background_templates": [
"{{ if contains \"true\" .Output }}#DD7700{{ end }}"
"{{ if contains \"true\" .Output }}#4063D8{{ end }}"
],
"invert_powerline": true,
"style": "diamond",
"trailing_diamond": "▓",
"properties": {
"shell": "bash",
"command": "type -t direnv 2>/dev/null && { direnv status 2>&1 || true; } | grep \"Found RC allowed\"; true"
"command": "type -t direnv 2>&1 > /dev/null && direnv status 2>&1 | grep 'Found RC allowed'"
},
"template": "{{ if .Output }}envrc{{ end }}"
}

View File

@ -1,24 +1,25 @@
# If not running interactively, don't do anything
[ -z ${DBG_SZSHRC} ] || echo "Entered .sz.shrc"
SFP='.sz' # Script Family Prefix
[ -z ${DBG_SHRC} ] || echo "Entered ${SFP}.shrc"
case $- in
*i*) echo "Welcome $USER to $(hostname)";;
*) [ -z "${INCLUDE_SZSHRC}" ] && return;;
*) return;;
esac
if [ -d ~/.sz.shrc.d ]; then
[ -z ${DBG_SZSHRC} ] || ps -p$$ -ho comm
script_source=("$(find ~/.sz.shrc.d -maxdepth 1 -type d -name "$(ps -p$$ -ho comm).pre")")
script_source+=("$(find ~/.sz.shrc.d -maxdepth 0 -type d)")
script_source+=("$(find ~/.sz.shrc.d -maxdepth 1 -type d -name "$(ps -p$$ -ho comm).post")")
[ -z ${DBG_SZSHRC} ] || echo "Working with (${script_source[@]})..."
export SHRC_D=~/${SFP}.shrc.d
if [ -d ${SHRC_D} ]; then
script_source=("$(find ${SHRC_D} -maxdepth 1 -type d -name "$(ps -p$$ -ho comm).pre")")
script_source+=("$(find ${SHRC_D} -maxdepth 0 -type d)")
script_source+=("$(find ${SHRC_D} -maxdepth 1 -type d -name "$(ps -p$$ -ho comm).post")")
[ -z ${DBG_SHRC} ] || echo "Working with (${script_source[@]})..."
for script_src in ${script_source[@]}; do
scripts=($(find $script_src -maxdepth 1 -type f -not -name "*~" -not -name "*.off" -not -name "*.swp" | sort))
#[ -z ${DBG_SZSHRC} ] || echo "Within $script_src, will review (${scripts[@]})..."
#[ -z ${DBG_SHRC} ] || echo "Within $script_src, will review (${scripts[@]})..."
for script_name in ${scripts[@]}; do
[ -z ${DBG_SZSHRC} ] || echo "Checking $script_name..."
[ -z ${DBG_SHRC} ] || echo "Checking $script_name..."
if [ -r $script_name ]; then
[ -z ${DBG_SZSHRC} ] || echo "Sourcing $script_name..."
[ -z ${DBG_SHRC} ] || echo "Sourcing $script_name..."
. $script_name
fi
done
@ -28,4 +29,5 @@ if [ -d ~/.sz.shrc.d ]; then
unset script_source
fi
[ -z ${DBG_SZSHRC} ] || echo "Exiting .sz.shrc"
[ -z ${DBG_SHRC} ] || echo "Exiting ${SFP}.shrc"

View File

@ -1,3 +1,7 @@
warn() {
(>&2 printf '\E[34mWARNING:\E[0m %s\n' "$@" )
}
error() {
(>&2 printf '\E[31mERROR:\E[0m %s\n' "$@" )
}
@ -9,6 +13,13 @@ require_root() {
fi
}
recommend_root() {
if [[ $EUID -ne 0 ]]; then
warn "This script works better using sudo or as the root user"
return 3
fi
}
function setacl() {
if [[ $# -lt 4 ]]; then
error "setacl missing arguments, called with '$1' ${@:2}"

View File

@ -1,5 +1,3 @@
alias sudo="/usr/bin/sudo "
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
@ -7,12 +5,10 @@ alias l='ls -CF'
alias lessr="less --raw-control-chars "
alias sz-edshrc="ed ~/.sz.shrc.d ; exec $SHELL"
alias edshrc="ed ~/${SFP}.shrc.d && exec $SHELL"
[[ -z "$(env inkscape 2> /dev/null)" && -n "$(flatpak info org.inkscape.Inkscape 2> /dev/null)" ]] && alias inkscape="flatpak run org.inkscape.Inkscape "
alias cdgit='cd $(git rev-parse --show-toplevel) '
function clip() {
xclip -i -sel clipboard
}

View File

@ -1,17 +1,6 @@
PREFERED_VI=$(which-command nvim vim | head -1)
if [[ -z "$PREFERED_VI" ]]; then
PREFERED_VI=$(which-command vi | head -1)
MY_VI="$(type -fP my_vi)"
if [[ -z "$PREFERED_VI" ]]; then
alias my_vi='eval $EDITOR '
else
alias my_vi="$PREFERED_VI"
fi
else
alias my_vi="$PREFERED_VI -p"
fi
export DOOMROOT="$HOME/.config/_my.emacs/doom"
port DOOMROOT="$HOME/.config/_my.emacs/doom"
[[ -x $DOOMROOT/emacs.d/bin/doom ]] && function doom() {
export EMACSDIR="$DOOMROOT/emacs.d"
export DOOMDIR="$DOOMROOT/config"
@ -29,11 +18,12 @@ if [[ -r "$HOME/.config/_my.emacs/spacemacs/emacs.d/init.el" \
]]; then
alias my_editor='edit-with-spacemacs'
else
alias my_editor='my_vi'
alias my_editor="${MY_VI} "
fi
alias nvim="my_vi"
alias vim="my_vi"
alias vi="my_vi"
alias nvim="${MY_VI} "
alias vim="${MY_VI} "
alias vi="${MY_VI} "
alias ed="my_editor"
alias edit="my_editor"

View File

@ -0,0 +1,8 @@
#alias sudo="/usr/bin/sudo "
function sudo() {
local cli="$(command -v "${1}")"
[[ -x "$cli" ]] || cli="${1}"
/usr/bin/sudo --preserve-env=PATH -- "$cli" "${@:2}"
}

View File

@ -0,0 +1,7 @@
if [[ -n "$(which-command git)" ]]; then
alias gitcd='cd $(git rev-parse --show-toplevel) '
if [[ -n $(git credential-manager-core --version 2>/dev/null) ]]; then
export GCM_CREDENTIAL_STORE=plaintext
fi
fi

View File

@ -6,17 +6,24 @@ if [[ -n "$(which-command chezmoi)" ]]; then
alias czcd="cd $CZ"
alias czxcd="cd $CZ_X"
alias cz="chezmoi "
alias czx="chezmoi --source $CZ_X --config $HOME/.config/chezmoi/chezmoi.externals.toml "
function cz() { chezmoi "${@}"; }
function czx() {
chezmoi --source $CZ_X --config $HOME/.config/chezmoi.externals/config.toml "${@}"
}
alias czs="cz status "
function czg() {
cz git -- "${@}"
}
#alias czg="cz git -- "
alias czgs="cz git -- status "
alias cza="cz apply && exec $SHELL"
alias czu="cz upgrade && cz update && exec $SHELL "
alias czxu="cz upgrade && cz update && czx apply && exec $SHELL "
alias cz-refresh="czs | cut -d\ -f2 | grep '^\.sz\.shrc\.d' | xargs cz forget --force; cz add ~/.sz.shrc.d --recursive; cz status; cz git status"
alias cz-commit="cz git -- commit -a "
function cz() {
chezmoi "${@}"
}
function cz-remove-missing() {
pushd ~ > /dev/null
changes=$(cz status | sed -n 's/^DA[ \t]\+//p')
@ -37,12 +44,18 @@ if [[ -n "$(which-command chezmoi)" ]]; then
}
function cz-set-ssh-github() {
cz git -- remote set-url origin "$(cz git -- remote get-url origin | sed 's|https://github.com/|git@github.com:|')"
cz git -- remote set-url origin "$( \
cz git -- remote get-url origin \
| sed 's|https://github.com/|git@github.com:|' \
)"
cz git -- remote get-url origin
}
function cz-set-https-github() {
cz git -- remote set-url origin "$(cz git -- remote get-url origin | sed 's|git@github.com:|https://github.com/|')"
cz git -- remote set-url origin "$( \
cz git -- remote get-url origin \
| sed 's|git@github.com:|https://github.com/|' \
)"
cz git -- remote get-url origin
}
fi

View File

@ -1,5 +0,0 @@
if [[ -n "$(type -fP chezmoi)" ]]; then
CHEZMOI_OUT="$(chezmoi status || true)x"
[[ "x" != "$CHEZMOI_OUT" ]] && printf "\nChezmoi changes:\n" && echo "${CHEZMOI_OUT%?}"
unset CHEZMOI_OUT
fi

View File

@ -4,4 +4,11 @@ export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
function _history_hook() {
history -a; history -c; history -r
}
export PROMPT_COMMAND="$( \
echo "$PROMPT_COMMAND" \
| sed 's/;\ *$//; s/; _history_hook//g' \
); _history_hook"

View File

@ -0,0 +1,2 @@
# BC_PATH=$(which-command bash-complete-alias)
# [[ -n "$BC_PATH" && -r "$BC_PATH" ]] && source "$BC_PATH"

View File

@ -1 +0,0 @@
[[ -n "$BASH_COMPLETION_EXIST" && -n $(which-command chezmoi) ]] && source <(chezmoi completion bash | add-alias-to-bash-completion-code chezmoi cz )

View File

@ -0,0 +1,13 @@
[[ -n "$BASH_COMPLETION_EXIST" && -n $(which-command chezmoi) ]] \
&& source <( \
chezmoi completion bash \
| add-alias-to-bash-completion-code chezmoi cz czx \
| add-alias-to-bash-completion-code chezmoi czx \
) \
echo done.
# && if [[ $(type -t compopt) = "builtin" ]]; then
# complete -o default -F __git_complete czg
# else
# complete -o default -o nospace -F __git_complete czg
# fi

View File

@ -1 +0,0 @@
[[ -n "$(which-command oh-my-posh)" ]] && source <(oh-my-posh completion bash)

View File

@ -0,0 +1,2 @@
[[ -n "$(which-command oh-my-posh)" ]] \
&& source <( oh-my-posh completion bash )

View File

@ -1,21 +0,0 @@
if ( uname --kernel-release | grep -q truenas ); then
# Completion code is only avialable with `sudo`, the aliases below
# are desined for 'lazy-loading' the completion code, when it's time
# to enter the sudo password.
if [[ -n "$(which-command 'k3s')" ]]; then
alias kubectl=' \
### Lazy load `kubectl` bash-completion \
alias kubectl="sudo k3s kubectl "; \
source <( kubectl completion bash ); \
sudo k3s kubectl '
fi
if [[ -n "$(which-command 'helm')" ]]; then
alias helm=' \
### Lazy load `helm` bash-completion \
alias helm="sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm "; \
source <( helm completion bash ); \
sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm '
fi
fi

View File

@ -1,5 +1,5 @@
[ -z ${DBG_SZSHRC} ] || echo "Entered .zshrc"
[ -z ${DBG_SHRC} ] || echo "Entered .zshrc"
[[ -r ~/.sz.shrc ]] && source ~/.sz.shrc
[ -z ${DBG_SZSHRC} ] || echo "Exiting .zshrc"
[ -z ${DBG_SHRC} ] || echo "Exiting .zshrc"

View File

@ -0,0 +1,228 @@
#! /usr/bin/env bash
######### Repo list
# this is a reference template
# function _repo_template_function() {
# REPO_FQDN='' # host FQDN, this will also be the name of the apt list/source file
# GPG_KEY_URL='' # [optional] URL to the GPG Key, if not supplied it will be https://$REPO_FQDN/gpg
# GPG_KEY_PATH='' # [optional] Location on disk for the public GPG key
# REPO_ARCH='' # [optional] System architecture specific package, '-' is shorthand for current architecture
# REPO_URL='' # [optional] REPO Url if not https://$REPO_FQDN, which is the default.
# REPO_SUITE='' # [optional] Suite / Release codename
# REPO_CMP='' # [optional] Package Channel - default is 'main', this is vendor specific.
# }
function _repo_docker() {
# for: docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Also don't forget:
# remove: docker docker-engine docker.io containerd runc
# possibly remove docker-compose and install: https://github.com/docker/compose-switch
REPO_FQDN='download.docker.com'
REPO_URL="https://download.docker.com/linux/$_OS"
GPG_KEY_URL="$REPO_URL/gpg"
REPO_CMP='stable'
}
function _repo_anydesk() {
# for: anydesk
REPO_FQDN='deb.anydesk.com'
REPO_URL="http://$REPO_FQDN/" # NOTE, this is http, not https
GPG_KEY_URL='https://keys.anydesk.com/repos/DEB-GPG-KEY'
REPO_ARCH='-'
REPO_CMP='main'
REPO_SUITE='all'
}
function _repo_gcloud() {
# for: google-cloud-cli
REPO_FQDN='packages.cloud.google.com'
REPO_URL="https://$REPO_FQDN/apt"
GPG_KEY_URL="$REPO_URL/doc/apt-key.gpg"
REPO_ARCH='-'
REPO_SUITE='cloud-sdk'
}
function _repo_mspackages() {
# for: code (optionally: powershell dotnet-*)
REPO_FQDN='packages.microsoft.com'
GPG_KEY_URL="https://$REPO_FQDN/keys/microsoft.asc"
REPO_URL="https://$REPO_FQDN/$_OS/$_REL/prod"
}
function _repo_msedge() {
# for: microsoft-edge-stable
REPO_FQDN='edge.microsoft.com'
GPG_KEY_URL="https://packages.microsoft.com/keys/microsoft.asc"
REPO_URL="http://packages.microsoft.com/repos/edge"
REPO_SUITE='stable'
}
function _repo_hashicorp() {
# for: terraform
REPO_FQDN='apt.releases.hashicorp.com'
# GPG_KEY_URL='' # default value is enough here
# REPO_URL='' # default value is enough here
}
function _repo_custom_xscreensavers() {
# I really LOVE xscreensavers, but it's been stuck in limbo on the
# `stable` repos, so I install it from the `unstable`, aka `sid`, suite.
# To do that safely, I make sure the repo is pinned to a lower priority.
# I do this BEFORE I add the repo.
# # Debian sid (unstable) as low-priority option
(echo 'Package: *'; echo 'Pin: release a=unstable'; echo 'Pin-Priority: 200') | sudo tee /etc/apt/preferences.d/unstable > /dev/null
# # pin xscreensaver to unstable
(echo 'Package: xscreenaver*'; echo 'Pin: release a=unstable'; echo 'Pin-Priority: 2000') | sudo tee /etc/apt/preferences.d/xscreensaver > /dev/null
# for: xscreensaver xscreensaver-data xscreensaver-data-extra
# xscreensaver-screensaver-bsod xscreensaver-screensaver-webcollage
# Add the unstable/sid repo - THIS IS DANGEROUS without the pinning via
# /etc/apt/preferences.d files created by the code above.
sudo apt-add-repository $_YES --no-update "deb [arch=amd64] http://deb.debian.org/debian sid main non-free contrib"
}
############ Script Logic starts here
set -e
ANSI_Print() { printf "\E[${ANSI_Code}m%s\E[0m" "$@"; }
ANSI_Red() { ANSI_Code=31 ANSI_Print "$@"; }
ANSI_Green() { ANSI_Code=32 ANSI_Print "$@"; }
ANSI_Yellow() { ANSI_Code=33 ANSI_Print "$@"; }
ANSI_Blue() { ANSI_Code=34 ANSI_Print "$@"; }
ANSI_Indiego() { ANSI_Code=35 ANSI_Print "$@"; }
ANSI_Cyan() { ANSI_Code=36 ANSI_Print "$@"; }
error() {
(>&2 ANSI_Red 'ERROR: ' && printf '%s\n' "$@" )
}
require_root() {
if [[ $EUID -ne 0 ]]; then
error "This script should only be run using sudo or as the root user"
exit 1
fi
}
# The function that does the _Heavy Lifting_.
# see the code that follows for the parameter signature
function add_repo() {
unset REPO_FQDN GPG_KEY_URL GPG_KEY_PATH REPO_ARCH REPO_URL REPO_SUITE REPO_CMP
# In case custom handling is required, call it and return.
if [[ "$(type -t _repo_custom_$1)" == 'function' ]]; then
eval "_repo_custom_$1" && return 0
return $?
# If no repo defintion exist, exit with an error
elif [[ "$(type -t _repo_$1)" != 'function' ]]; then
error "Can't configure $1, could not find _repo_$1 definition!"
return 1
fi
# Grab the repo's defintion
eval "_repo_$1"
# Prepare all necessary vraiables
[[ -z "$REPO_FQDN" ]] && error "REPO_FQDN not defined for '$1'" && return 1
GPG_KEY_URL=${GPG_KEY_URL:-https:\/\/$REPO_FQDN\/gpg}
GPG_KEY_PATH=${GPG_KEY_PATH:-/usr/share/keyrings/$REPO_FQDN.gpg}
REPO_ARCH=${REPO_ARCH:-${_ARC}}
[[ $REPO_ARCH == '-' ]] && REPO_ARCH='' || REPO_ARCH="arch=$REPO_ARCH"
REPO_URL=${REPO_URL:-https:\/\/$REPO_FQDN}
REPO_SUITE=${REPO_SUITE:-$_CNM}
REPO_CMP=${REPO_CMP:-main}
# Grab the GPG key and save it.
curl -fsSL $GPG_KEY_URL | sudo gpg --dearmor -o $GPG_KEY_PATH $_YES
echo "Key created: $GPG_KEY_PATH"
# Define the package source
echo "deb [$(echo "$REPO_ARCH signed-by=$GPG_KEY_PATH" | xargs )] $REPO_URL $REPO_SUITE $REPO_CMP" | \
sudo tee /etc/apt/sources.list.d/$REPO_FQDN.list > /dev/null
echo "APT source list added: /etc/apt/sources.list.d/$REPO_FQDN.list"
}
function usage() {
printf " %s\n" \
"Usage:" \
" $0 [-v[v]] " \
" [--no-init] [--no-overwrite] " \
" all|<repo name>[ <repo name 2>...] " \
"" \
"Repos: $( \
printf "\n %s" $( \
typeset -f \
| grep '^_repo_' \
| sed 's/_repo\(_custom\)\?_\(.*\) ()/\2/' \
| sort \
))" \
"" \
"Options:" \
" --no-init - skip package initialization." \
" --no-overwrite - don't overwrite gpg keys automatially, ask." \
" new keys will still be written without asking." \
" -v[v] - script verbosity, equivalent to set -x and set -xv" \
""
}
function main() {
[[ ${#REPO_LIST[@]} -eq 0 ]] && usage && return 1
require_root
_OS=$(lsb_release -is | awk '{ print tolower($0) }')
[[ $_OS == 'pop' ]] && _OS='ubuntu'
_REL=$(lsb_release -rs) # Release
_CNM=$(lsb_release -cs) # CodeName
_ARC=$(dpkg --print-architecture) # Architecture
ANSI_Cyan "Initializing: Installing basic packages..."; echo
if [[ -n "$SHOULD_INIT" ]]; then
# Make sure the /usr/share/keyrings dir exists
mkdir -p /usr/share/keyrings 2>&1 > /dev/null
# Make sure all of the basic required tools are installed for the code
# below to work
apt-get install --yes --no-install-recommends \
curl gnupg software-properties-common apt-transport-https
fi
ANSI_Green "Done."; echo
while read r; do
ANSI_Cyan "Installing $r repository..."; echo
add_repo $r && UPDATE_REQUIRED=1 || return 2
ANSI_Green "Installation of $r repository completed."; echo
done < <(printf "%s\n" "${REPO_LIST[@]}")
# Finally, run `apt update` to check that everything completed successfully
if [[ $UPDATE_REQUIRED == 1 ]]; then
ANSI_Cyan "Finalizing: running 'apt update'..."; echo
MISSING_SIGNATURES=($( \
sudo apt update 2>&1 1>/dev/null \
| sed -ne 's/.*NO_PUBKEY //p' \
))
$MISSING_SIGNATURES| while read key; do if ! [[ ${keys[*]} =~ "$key" ]]; then sudo apt-key adv --keyserver hkp://pool.sks-keyservers.net:80 --recv-keys "$key"; keys+=("$key"); fi; done
sudo apt update
ANSI_Green "'apt update' completed."; echo
fi
}
# Iterate through stdin or parameters
if [[ $# == 0 ]]; then
usage
else
REPO_LIST=()
_YES='--yes'
_SHOULD_INIT=1
UPDATE_REQUIRED=0
READCMD='printf "%s\n" "${@}"'
[[ $# == 1 && $1 == '-' ]] && READCMD='cat - '
while read a; do
# Switch on _YES
[[ "$a" == "-v" ]] && set -x && continue
[[ "$a" == "-vv" ]] && set -xv && continue
[[ "$a" == "--no-overwrite" ]] && unset _YES && continue
[[ "$a" == "--no-init" ]] && unset _SHOULD_INIT && continue
# Add repo
[[ -n "$a" ]] && REPO_LIST+=("$a")
done < <( eval $READCMD )
main
fi

View File

@ -1,75 +0,0 @@
#! /usr/bin/env bash
# Make sure the /usr/share/keyrings dir exists
sudo mkdir -p /usr/share/keyrings 2>&1 > /dev/null
# Make sure all of the basic required tools are installed for the code
# below to work
sudo apt-get install --yes --no-install-recommends \
curl gnupg software-properties-common apt-transport-https
# some utility variables, _YES is optionally '--yes'
[[ ! -z "$1" && "$1" == '--yes' ]] && _YES='--yes'
_OS=$(lsb_release -is | awk '{ print tolower($0) }')
[[ $_OS == 'pop' ]] && _OS='ubuntu'
_REL=$(lsb_release -rs) # Release
_CNM=$(lsb_release -cs) # CodeName
_ARC=$(dpkg --print-architecture) # Architecture
# The function that does the _Heavy Lifting_.
# see the code that follows for the parameter signature
function add_repo() {
REPO_FQDN=$1 #'download.docker.com'
GPG_KEY_URL=${2:-https:\/\/$REPO_FQDN\/gpg}
GPG_KEY_PATH=/usr/share/keyrings/$REPO_FQDN.gpg
REPO_ARCH=${3:-${_ARC}}
[[ $REPO_ARCH == '-' ]] && REPO_ARCH='' || REPO_ARCH="arch=$REPO_ARCH"
REPO_URL=${4:-https:\/\/$REPO_FQDN}
REPO_SUITE=${5:-$_CNM}
REPO_CMP=${6:-main}
curl -fsSL $GPG_KEY_URL | sudo gpg --dearmor -o $GPG_KEY_PATH $_YES
echo "Key created: $GPG_KEY_PATH"
echo "deb [$(echo "$REPO_ARCH signed-by=$GPG_KEY_PATH" | xargs )] $REPO_URL $REPO_SUITE $REPO_CMP" | \
sudo tee /etc/apt/sources.list.d/$REPO_FQDN.list > /dev/null
echo "APT source list added: /etc/apt/sources.list.d/$REPO_FQDN.list"
}
#Long line - 197 characters long
#add_repo REPO_FQDN/Name GPG_KEY_URL REPO_ARCH REPO_URL REPO_SUITE REPO_CMP # TBD: PIN_PRIORITY
#defaults: <required> 'https://$REPO_FQDN/gpg' $_ARC 'https://$REPO_FQDN' $_CNM 'main' # <optional>
# ---------------------------- ------------------------------------------------------- ---------- ------------------------------------------------ ----------- ---------
# for: docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Also don't forget:
# remove: docker docker-engine docker.io containerd runc
# possibly remove docker-compose and install: https://github.com/docker/compose-switch
add_repo 'download.docker.com' "https://download.docker.com/linux/$_OS/gpg" '' "https://download.docker.com/linux/$_OS" '' 'stable'
# for: anydesk
add_repo 'deb.anydesk.com' 'https://keys.anydesk.com/repos/DEB-GPG-KEY' '-' 'http://deb.anydesk.com/' 'all' ''
# for: google-cloud-cli
add_repo 'packages.cloud.google.com' 'https://packages.cloud.google.com/apt/doc/apt-key.gpg' '-' 'https://packages.cloud.google.com/apt' 'cloud-sdk' ''
# for: code (optionally: powershell dotnet-*)
add_repo 'packages.microsoft.com' 'https://packages.microsoft.com/keys/microsoft.asc' '' "https://packages.microsoft.com/$_OS/$_REL/prod" '' ''
# for: microsoft-edge-stable
add_repo 'packages.microsoft.com-edge' 'https://packages.microsoft.com/keys/microsoft.asc' '' 'http://packages.microsoft.com/repos/edge' 'stable' ''
# for: terraform
add_repo 'apt.releases.hashicorp.com' 'https://apt.releases.hashicorp.com/gpg' '' 'https://apt.releases.hashicorp.com' '' ''
# I really LOVE xscreensavers, but it's been stuck in limbo on the
# `stable` repos, so I install it from the `unstable`, aka `sid`, suite.
# To do that safely, I make sure the repo is pinned to a lower priority.
# I do this BEFORE I add the repo.
# # Debian sid (unstable) as low-priority option
(echo 'Package: *'; echo 'Pin: release a=unstable'; echo 'Pin-Priority: 200') | sudo tee /etc/apt/preferences.d/unstable > /dev/null
# # pin xscreensaver to unstable
(echo 'Package: xscreenaver*'; echo 'Pin: release a=unstable'; echo 'Pin-Priority: 2000') | sudo tee /etc/apt/preferences.d/xscreensaver > /dev/null
# for: xscreensaver xscreensaver-data xscreensaver-data-extra
# xscreensaver-screensaver-bsod xscreensaver-screensaver-webcollage
# Add the unstable/sid repo - THIS IS DANGEROUS without the pinning via
# /etc/apt/preferences.d files created by the code above.
sudo apt-add-repository $_YES --no-update "deb [arch=amd64] http://http.us.debian.org/debian sid main non-free contrib"
# Finally, run `apt update` to check that everything completed successfully
sudo apt update

View File

@ -1,4 +1,7 @@
#! /usr/bin/env bash
USER_HOME=$HOME
[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")"
. ${SHRC_D:-$USER_HOME/.pqb.shrc.d}/01_util.functions
unset MISSING_APT_PACKAGES
export MISSING_APT_PACKAGES=()
@ -8,7 +11,7 @@ APT_OK=$([[ -e $(type -fP apt) ]] && [[ -x $(type -fP apt | head -1) ]] && echo
# TODO: Implement a test for specific Package Sources per package check
PACKAGE_SOURCES=$( \
grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* \
grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* 2>/dev/null \
| sed 's/\[.*\] //; s/^deb //' \
| sort -u\
)
@ -70,22 +73,31 @@ function check-exist() {
}
#### Output starts here
PROD_NAME=$( sudo dmidecode --type 200 2> /dev/null | tail +5 | tail -2 | head -1 | awk '{print $1}')
#### These all run better with sudo
if ( check-exist 'dmidecode' > /dev/null ); then
if recommend_root; then
PROD_NAME=$( dmidecode --type 200 2> /dev/null | tail +5 | tail -2 | head -1 | awk '{print $1}')
MACHINE_INFO_FORMAT='%-14s %-19s %-13s %-11s %s\n'
MACHINE_INFO_FIELDS=("Manufacturer" "Model family" "Model/MTM" "S/N" "BIOS Firmware")
printf "$MACHINE_INFO_FORMAT" "${MACHINE_INFO_FIELDS[@]}"
printf "$MACHINE_INFO_FORMAT" "$(
sudo dmidecode -s system-manufacturer
)" "$(sudo dmidecode -s system-family
dmidecode -s system-manufacturer
)" "$(dmidecode -s system-family
)" "${PROD_NAME:-$(
sudo dmidecode -s system-product-name
)}" "$(sudo dmidecode -s system-serial-number
)" "$(sudo dmidecode -s bios-version)"
dmidecode -s system-product-name
)}" "$(dmidecode -s system-serial-number
)" "$(dmidecode -s bios-version)"
printf " CPU: %s\n" "$(
sudo dmidecode -s processor-version
dmidecode -s processor-version
)"
echo ''
else
echo "Running dmidecode requires root access, skipping machine info collection..."
fi
else
echo "dmidecode is required to collect System and BIOS information"
fi
echo "Shell: $SHELL (availabe: $(echo $(cat /etc/shells | grep -v 'shells:' | sed "s/^\(.*\/\)*//" | sort -u)))"
echo ''
@ -99,13 +111,17 @@ echo ''
print-result 'Executable `apt`' $(test-print $APT_OK "Found" "Missing") "$(test-print $APT_OK '' "$(printf 'repair by running:\n%-41sfix-apt.sh')" )"
echo ''
check-exist 'Byobu' '/usr/bin/byobu-launch' || MISSING_APT_PACKAGES+=('byobu')
check-exist "setxkbmap" '' '' '(Optional)' \
|| MISSING_APT_PACKAGES+=('setxkbmap')
check-exist 'oh-my-posh'
check-exist '~/.poshtheme.omp.json' "~/.poshtheme.omp.json" "-r"
check-exist '~/.poshtheme.omp.json' "${USER_HOME}/.poshtheme.omp.json" "-r"
check-exist 'tmux' || MISSING_APT_PACKAGES+=('tmux')
check-exist 'git' || MISSING_APT_PACKAGES+=('git')
check-exist 'emacs' || MISSING_APT_PACKAGES+=('emacs')
check-exist 'monit' || MISSING_APT_PACKAGES+=('monit')
check-exist 'direnv' || MISSING_APT_PACKAGES+=('direnv')
check-exist "chezmoi" '' '' '' 'wget -O- chezmoi.io/get | bash # or'
# wget -O- lksz.me/dotfiles | bash'
check-exist 'terraform' '' '' '' "$( \
[[ -r /usr/share/keyrings/apt.releases.hashicorp.com.gpg ]] \
&& MISSING_APT_PACKAGES+=('terraform') \
@ -114,10 +130,6 @@ check-exist 'terraform' '' '' '' "$( \
|| SUGGESTED+=(
'sz-add-my-apt-repos' '# followed by:' 'sudo apt install terraform', ''
)
check-exist "setxkbmap" '' '' '(Optional)' \
|| MISSING_APT_PACKAGES+=('setxkbmap')
check-exist "chezmoi" '' '' '' 'wget -O- chezmoi.io/get | bash # or
# wget -O- lksz.me/dotfiles | bash'
check-exist "gcloud" '' '' '' "$( \
[[ -r /usr/share/keyrings/apt.releases.hashicorp.com.gpg ]] \
&& MISSING_APT_PACKAGES+=('terraform') \
@ -125,11 +137,13 @@ check-exist "gcloud" '' '' '' "$( \
)" \
|| SUGGESTED+=( 'sz-add-my-apt-repos' '# followed by:' 'sudo apt install gcloud', '' )
check-exist 'dmidecode'
check-exist 'bash completion' '/usr/share/bash-completion/bash_completion' '-r'
check-exist 'CodeNewRoman Nerd Font' '~/.local/share/fonts/NF_CodeNewRoman' '-d'
check-exist 'FiraCode Nerd Font' '~/.local/share/fonts/NF_FiraCode' '-d'
check-exist '~/bin' "~/bin" '-d' '(Optional)'
check-exist '~/.local/bin' "~/.local/bin" '-d' '(Optional)'
check-exist 'CodeNewRoman Nerd Font' '${USER_HOME}/.local/share/fonts/NF_CodeNewRoman' '-d'
check-exist 'FiraCode Nerd Font' '${USER_HOME}/.local/share/fonts/NF_FiraCode' '-d'
check-exist '~/bin' "${USER_HOME}/bin" '-d' '(Optional)'
check-exist '~/.local/bin' "${USER_HOME}/.local/bin" '-d' '(Optional)'
echo ""
[[ -n $SUGGESTED ]] && echo 'You might want to run the following commands:' && printf " %s\n" "${SUGGESTED[@]}"