sz-doctor some work done, not complete yet

Adding repo testing code, needs to by tied to missing package logic
This commit is contained in:
Gal Szkolnik 2022-06-09 14:23:30 -04:00
parent df97fb2614
commit d0447b4f61
2 changed files with 80 additions and 23 deletions

View File

@ -1,9 +1,9 @@
#! /usr/bin/env bash #! /usr/bin/env bash
# sudo mkdir -p /usr/share/keyrings 2>&1 > /dev/null sudo mkdir -p /usr/share/keyrings 2>&1 > /dev/null
# sudo apt-get install --yes --no-install-recommends \ sudo apt-get install --yes --no-install-recommends \
# curl gnupg software-properties-common apt-transport-https curl gnupg software-properties-common apt-transport-https
function add_repo() { function add_repo() {
REPO_FQDN=$1 #'download.docker.com' REPO_FQDN=$1 #'download.docker.com'

View File

@ -1,24 +1,75 @@
#! /usr/bin/env bash #! /usr/bin/env bash
MISSING_APT_PACKAGES=() unset MISSING_APT_PACKAGES
export MISSING_APT_PACKAGES=()
SUGGESTED=() SUGGESTED=()
APT_OK=$([[ -e $(type -fP apt) ]] && [[ -x $(type -fP apt | head -1) ]] && echo 'true' || echo 'false')
PACKAGE_SOURCES=$( \
grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* \
| sed 's/\[.*\] //; s/^deb //' \
| sort -u\
)
function print-result() { function print-result() {
printf "%-30s: %-8s %s \n" "$1" "$2" "$3" printf "%-30s: %-8s %s \n" "$1" "$2" "$3"
} }
function test-print() {
if [[ -n "$FAIL_EVERYTHING" || $(eval $1) ]]; then
echo $3
else
echo $2
fi
}
function safe-add() {
SAVE_IFS="$IFS"
IFS=':'
eval "$1+=($2)"
eval "$1=($(eval "echo $(printf '$IFS${%s[*]}$IFS' "$1")" | xargs -n1 echo | sort -u))"
IFS="$SAVE_IFS"
unset SAVE_IFS
}
KNOWN_REPOS=()
# REPO_<name>_HOSTNAME=Full.Qualified.Domain.Name.com
# REPO_<name>_PROTOCOL=http|https
# REPO_<name>_PATH=/ or /deeper/but/never/blank
function add-known-repo() {
safe-add 'KNOWN_REPOS' "$1"
eval "REPO_$1_HOSTNAME='$2'"
eval "REPO_$1_PROTOCOL='${3:-http}'"
eval "REPO_$1_PATH='${4:-/}'"
eval "REPO_$1_KEYWORD='${5}'"
}
add-known-repo 'terraform' 'apt.releases.hashicorp.com' 'https'
add-known-repo 'terraform' 'apt.releases.hashicorp.com' 'https'
# add-known-repo 'docker' 'download.docker.com' 'https'
# add-known-repo 'anydesk' 'deb.anydesk.com' 'https'
# add-known-repo 'gcloud' 'packages.cloud.google.com' 'https'
# add-known-repo 'microsoft' 'packages.microsoft.com' 'https'
add-known-repo 'debian_sid' 'http.us.debian.org' 'http' '' 'sid'
# set | grep '^REPO'
# check-exist <Name> [path:default is $(type $1)] [test operator: default is -x] [Found note: default blank] [missing note: default blank] [reponame: default blank]
function check-exist() { function check-exist() {
_RETURN_EVAL='true' _RETURN_EVAL='true'
_TEST_RESULT='Missing' _TEST_RESULT='Missing'
_TEST_NAME=$1 _TEST_NAME=$1
_TEST_PATH=${2:-$(type -fP $_TEST_NAME | head -1 2>/dev/null)} _TEST_PATH=${2:-$(type -fP $_TEST_NAME | head -1 2>/dev/null)}
[[ -n "$_TEST_PATH" ]] && eval "[[ ${3:--x} ${_TEST_PATH// /\\ } ]]" && _TEST_RESULT='Found' || _RETURN_EVAL='false' [[ -n "$_TEST_PATH" ]] && eval "[[ ${3:--x} ${_TEST_PATH// /\\ } ]]" && _TEST_RESULT='Found' || _RETURN_EVAL='false'
[[ -n "$FAIL_EVERYTHING" ]] && _TEST_RESULT="-$_TEST_RESULT" && _RETURN_EVAL='false'
eval $_RETURN_EVAL && _TEST_NOTE="${4}" || _TEST_NOTE="${5}" eval $_RETURN_EVAL && _TEST_NOTE="${4}" || _TEST_NOTE="${5}"
print-result "$_TEST_NAME" "$_TEST_RESULT" "$_TEST_NOTE" print-result "$_TEST_NAME" "$_TEST_RESULT" "$_TEST_NOTE"
eval $_RETURN_EVAL eval $_RETURN_EVAL
} }
echo "Shell: $SHELL" echo "Shell: $SHELL"
echo "" echo ''
#_ALT_EDITOR=$( update-alternatives --get-selections | grep '^editor' | sed 's:^editor\W\+\w\+\W\+/:/:' ) #_ALT_EDITOR=$( update-alternatives --get-selections | grep '^editor' | sed 's:^editor\W\+\w\+\W\+/:/:' )
_ALT_EDITOR=$( update-alternatives --query editor | grep '^Value:' | cut -d: -f2 | sed 's: *\(.*\) *:\1:g' ) _ALT_EDITOR=$( update-alternatives --query editor | grep '^Value:' | cut -d: -f2 | sed 's: *\(.*\) *:\1:g' )
@ -26,27 +77,33 @@ print-result "System prefered editor" "$_ALT_EDITOR"
( echo $_ALT_EDITOR | grep "nano$" >/dev/null ) && echo "Recommended to run: update-alternatives --set editor $(type -fP nvim vim.basic vim.tiny vi | head -1)" ( echo $_ALT_EDITOR | grep "nano$" >/dev/null ) && echo "Recommended to run: update-alternatives --set editor $(type -fP nvim vim.basic vim.tiny vi | head -1)"
echo "editors found:" echo "editors found:"
update-alternatives --query editor | grep Alternative: | cut -d: -f2 update-alternatives --query editor | grep Alternative: | cut -d: -f2
echo "" echo ''
APT_OK=$([[ -e $(type -fP apt) ]] && [[ -x $(type -fP apt | head -1) ]] && echo '1')
APT_OK=""
print-result 'Executable `apt`' $([[ -n "$APT_OK" ]] && echo "Found" || echo "Missing" ) "$([[ -n "$APT_OK" ]] || printf 'repair by running:\n%-41sfix-apt.sh' '' )"
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 "Byobu" "/usr/bin/byobu-launch" || MISSING_APT_PACKAGES+=('byobu')
check-exist "oh-my-posh" check-exist "oh-my-posh"
check-exist "~/.poshtheme.omp.json" "~/.poshtheme.omp.json" "-r" check-exist "~/.poshtheme.omp.json" "~/.poshtheme.omp.json" "-r"
check-exist "tmux" check-exist "tmux" || MISSING_APT_PACKAGES+=('tmux')
check-exist "git" check-exist "git" || MISSING_APT_PACKAGES+=('git')
check-exist "emacs" check-exist "emacs" || MISSING_APT_PACKAGES+=('emacs')
check-exist "terraform" '' '' '' "$([[ -r /usr/share/keyrings/hashicorp.gpg ]] && MISSING_APT_PACKAGES+=('torraform') || echo \ check-exist "monit" || MISSING_APT_PACKAGES+=('monit')
'add apt repo by running: check-exist "terraform" '' '' '' "$( \
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp.gpg [[ -r /usr/share/keyrings/apt.releases.hashicorp.com.gpg ]] \
sudo apt-add-repository \ && MISSING_APT_PACKAGES+=('terraform') \
"deb [arch=amd64 signed-by=/usr/share/keyrings/hashicorp.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main"' \ || echo 'fix missing repos (See SUGGESTED below)' \
)" )" \
check-exist "setxkbmap" || SUGGESTED+=( 'sz-add-my-apt-repos' '# followed by:' 'sudo apt install terraform', '' )
check-exist "chezmoi" check-exist "setxkbmap" || MISSING_APT_PACKAGES+=('setxkbmap')
check-exist "gcloud" 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') \
|| echo 'fix missing repos (See SUGGESTED below)' \
)" \
|| SUGGESTED+=( 'sz-add-my-apt-repos' '# followed by:' 'sudo apt install gcloud', '' )
check-exist 'bash completion' '/usr/share/bash-completion/bash_completion' '-r' check-exist 'bash completion' '/usr/share/bash-completion/bash_completion' '-r'
check-exist 'CodeNewRoman Nerd Font' '~/.local/share/fonts/NF_CodeNewRoman' '-d' check-exist 'CodeNewRoman Nerd Font' '~/.local/share/fonts/NF_CodeNewRoman' '-d'
check-exist 'FiraCode Nerd Font' '~/.local/share/fonts/NF_FiraCode' '-d' check-exist 'FiraCode Nerd Font' '~/.local/share/fonts/NF_FiraCode' '-d'
@ -54,6 +111,6 @@ check-exist '~/bin' "~/bin" '-d' '(Optional)'
check-exist '~/.local/bin' "~/.local/bin" '-d' '(Optional)' check-exist '~/.local/bin' "~/.local/bin" '-d' '(Optional)'
echo "" echo ""
[[ -n $SUGGESTED ]] && echo 'You might want to run the following commands:' && printf "\n%s\n" "${SUGGESTED[*]}" [[ -n $SUGGESTED ]] && echo 'You might want to run the following commands:' && printf " %s\n" "${SUGGESTED[@]}"
[[ -n $MISSING_APT_PACKAGES ]] && printf "There are some missing APT packages, run the following command line to add them:\n\tsudo apt install ${MISSING_APT_PACKAGES[*]}\n\n" [[ -n $MISSING_APT_PACKAGES ]] && printf "There are some missing APT packages, run the following command line to add them:\n\tsudo apt install ${MISSING_APT_PACKAGES[*]}\n\n"