Update 'kfg'

This commit is contained in:
2023-05-25 12:50:06 +02:00
parent acbfd74983
commit a9ed1b1dc6

145
kfg
View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
NAME="kfg" NAME="kfg"
VERSION="0.4" VERSION="0.5"
HOME_PATH="$HOME" HOME_PATH="$HOME"
TMP_PATH="$HOME_PATH/.tmp/kfg_install" TMP_PATH="$HOME_PATH/.tmp/kfg_install"
@@ -25,6 +25,8 @@ TOOLS[bat]="cat replacement with syntax highlighting and git integration - https
TOOLS[lsd]="ls replacement with colors, icons, tree-view and more - https://github.com/lsd-rs/lsd" TOOLS[lsd]="ls replacement with colors, icons, tree-view and more - https://github.com/lsd-rs/lsd"
TOOLS[omp]="Customisable shell prompt renderer - https://github.com/jandedobbeleer/oh-my-pos" TOOLS[omp]="Customisable shell prompt renderer - https://github.com/jandedobbeleer/oh-my-pos"
TOOLS[zoxide]="A smarter cd command. - https://github.com/ajeetdsouza/zoxide" TOOLS[zoxide]="A smarter cd command. - https://github.com/ajeetdsouza/zoxide"
TOOLS[fzf]="A command-line fuzzy finder - https://github.com/junegunn/fzf"
TOOLS[fzf-tab]="Replace zsh's default completion selection menu with fzf - https://github.com/Aloxaf/fzf-tab"
function show_help_name { function show_help_name {
echo "$NAME v$VERSION" echo "$NAME v$VERSION"
@@ -130,43 +132,31 @@ function download_config {
fi fi
} }
function install_rc { function install_rc_file {
local _file=$1
install_rc "[ -f "${_file}" ] && source "${_file}""
}
function install_rc_download {
if [ -z "$P_RC" ]; then return 0; fi if [ -z "$P_RC" ]; then return 0; fi
# Make sure the directory exists # Make sure the directory exists
mkdir -p "$CONFIG_PATH/$1/" mkdir -p "$CONFIG_PATH/$1/"
# This is the config file # This is the config file
FILE="$CONFIG_PATH/$1/.$1.rc" local _file="$CONFIG_PATH/$1/.$1.rc"
# Does the file already exist? or does the user want to overwrite it? # Does the file already exist? or does the user want to overwrite it?
if [ ! -e "$FILE" ] || user_confirm_overwrite "$FILE"; then if [ ! -e "$_file" ] || user_confirm_overwrite "$_file"; then
# Download the file and save it # Download the file and save it
download "$2" "$FILE" download "$2" "$_file"
#wget -O "$FILE" "$2" > /dev/null 2>&1 #wget -O "$FILE" "$2" > /dev/null 2>&1
log_add "Added $FILE" log_add "Added $_file"
fi fi
# Add the file to the rc file as source $file install_rc_file "$_file"
SOURCE_CMD=$( echo "source $FILE" )
RC="$HOME_PATH/$RC_FILE"
if ! cat "$RC" | grep "$SOURCE_CMD" > /dev/null; then
echo "$SOURCE_CMD" >> "$RC"
log_add "Added \"$SOURCE_CMD\" to $RC"
else
log_info "\"$SOURCE_CMD\" already in $RC"
fi
# Add the file to the rc file as source $file in root
RC_ROOT="/root/$RC_FILE"
if ! sudo cat "$RC_ROOT" | grep "$SOURCE_CMD" > /dev/null; then
echo "$SOURCE_CMD" | sudo tee -a "$RC_ROOT"
log_add "Added \"$SOURCE_CMD\" to $RC_ROOT"
else
log_info "\"$SOURCE_CMD\" already in $RC_ROOT"
fi
} }
function init_install_rc { function install_rc {
if [ -z "$P_RC" ]; then return 0; fi if [ -z "$P_RC" ]; then return 0; fi
# Add the file to the rc file as source $file # Add the file to the rc file as source $file
SOURCE_CMD="$1" SOURCE_CMD="$1"
@@ -221,8 +211,8 @@ function download {
fi fi
case "${_dld}" in case "${_dld}" in
curl) _result="$(curl $_args "${_url}")" || _result="$(sudo curl $_args "${_url}")" || err "curl: failed to download ${_url}" ;; curl) _result="$(curl $_args "${_url}")" || err "curl: failed to download ${_url}" ;;
wget) _result="$(wget $_args "${_url}")" || _result="$(sudo wget $_args "${_url}")" || err "wget: failed to download ${_url}" ;; wget) _result="$(wget $_args "${_url}")" || err "wget: failed to download ${_url}" ;;
*) err "unsupported downloader: ${_dld}" ;; *) err "unsupported downloader: ${_dld}" ;;
esac esac
@@ -412,36 +402,29 @@ function apt_install {
fi fi
} }
#function github_latest { function github_latest {
# VERSION=$(curl -I "https://github.com/$1/releases/latest/" 2> /dev/null | grep -iE "^Location:" | tr -s ' ' | cut -d '/' -f 8 2> /dev/null) VERSION=$(curl -I "https://github.com/$1/releases/latest/" 2> /dev/null | grep -iE "^Location:" | tr -s ' ' | cut -d '/' -f 8 2> /dev/null)
# echo -n ${VERSION//[$'\t\r\n']} echo -n ${VERSION//[$'\t\r\n']} 2> /dev/null
#} }
#function install_deb_github {
# if [ -z "$P_DEB" ]; then return 0; fi
# local PATTERN=${3/ARCH/$ARCH};
# log_debug "Loading most recent version for $1"
# local VERSION=$(github_latest $2 2> /dev/null )
# VERSION=${VERSION/v/}
# log_debug "Found version $VERSION"
# local FILE=${PATTERN/VERSION/$VERSION}
# local LINK="https://github.com/$2/releases/latest/download/$FILE"
# log_debug "Download link: $LINK"
# install_deb "$1" ${LINK//[$'\t\r\n']}
#}
function git_clone { function git_clone {
CLONE=$(git clone "$1" "$2" 2>&1) CLONE=$(git clone "$1" "$2" 2>&1)
if [[ $CLONE =~ "already exists" ]]; then log_debug "${CLONE}"
if [[ $CLONE =~ "already exists" ]] || [[ $CLONE =~ "existiert bereits" ]]; then
log_debug "$1 already exists. Running 'git pull'." log_debug "$1 already exists. Running 'git pull'."
PULL=$(git -C "$2" pull) PULL=$(git -C "$2" pull)
log_info "$PULL" log_info "Updated $1 in $2"
else
log_add "Cloned $1 into $2"
fi fi
} }
function install_binary { function install_binary {
local _app=$1 local _app=$1
local _path=$2 local _path=$2
if [ -z "$P_BINARY" ]; then return 0; fi
#log_info "Downloading $2 to $BINARY_PATH ..."
#sudo wget -O $BINARY_PATH/$1 $2 > /dev/null 2>&1
log_debug $_path log_debug $_path
log_debug $BINARY_PATH/$_app log_debug $BINARY_PATH/$_app
sudo cp $_path $BINARY_PATH/$_app sudo cp $_path $BINARY_PATH/$_app
@@ -449,19 +432,6 @@ function install_binary {
log_add "Installed $_app into $BINARY_PATH/$_app" log_add "Installed $_app into $BINARY_PATH/$_app"
} }
#function install_binary_github {
# if [ -z "$P_BINARY" ]; then return 0; fi
# local PATTERN=${3/ARCH/$ARCH};
# log_debug "Loading most recent version for $1"
# VERSION=$(github_latest $2 2> /dev/null)
# VERSION=${VERSION/v/}
# log_debug "Found version $VERSION"
# local FILE=${PATTERN/VERSION/$VERSION}
# local LINK="https://github.com/$2/releases/latest/download/$FILE"
# log_debug "Download link: $LINK"
# install_binary "$1" ${LINK//[$'\t\r\n']}
#}
function set_shell { function set_shell {
if [ -z "$P_ZSH" ]; then return 0; fi if [ -z "$P_ZSH" ]; then return 0; fi
CURR_U=$(grep "^$USER" /etc/passwd | cut -d ':' -f 7 | cut -d '/' -f 4) CURR_U=$(grep "^$USER" /etc/passwd | cut -d ':' -f 7 | cut -d '/' -f 4)
@@ -507,6 +477,7 @@ function show_help_install {
} }
function p_all { function p_all {
ALL=1
p_zsh p_zsh
p_tmux p_tmux
p_unp p_unp
@@ -514,6 +485,7 @@ function p_all {
p_lsd p_lsd
p_omp p_omp
p_zoxide p_zoxide
p_fzf
} }
function p_zsh { function p_zsh {
@@ -539,7 +511,7 @@ function p_tmux {
download_config tmux tmux.theme https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.tmux.theme download_config tmux tmux.theme https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.tmux.theme
download_config tmux myip.sh https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/myip.sh download_config tmux myip.sh https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/myip.sh
sudo chmod +x ${CONFIG_PATH}/tmux/myip.sh sudo chmod +x ${CONFIG_PATH}/tmux/myip.sh
install_rc tmux https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.tmux.rc install_rc_download tmux https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.tmux.rc
git_clone "https://github.com/tmux-plugins/tpm" "${CONFIG_PATH}/tmux/plugins/tpm" git_clone "https://github.com/tmux-plugins/tpm" "${CONFIG_PATH}/tmux/plugins/tpm"
} }
@@ -557,7 +529,7 @@ function p_bat {
# ----------------- # -----------------
github_install bat "sharkdp/bat" github_install bat "sharkdp/bat"
#install_deb_github bat "sharkdp/bat" "bat_VERSION_ARCH.deb" #install_deb_github bat "sharkdp/bat" "bat_VERSION_ARCH.deb"
install_rc bat https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.bat.rc install_rc_download bat https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.bat.rc
} }
function p_lsd { function p_lsd {
@@ -573,7 +545,7 @@ function p_lsd {
function p_zoxide { function p_zoxide {
github_install "zoxide" "ajeetdsouza/zoxide" github_install "zoxide" "ajeetdsouza/zoxide"
install_rc "zoxide" "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.zoxide.rc" install_rc_download zoxide https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.zoxide.rc
} }
function p_omp { function p_omp {
@@ -582,10 +554,43 @@ function p_omp {
# ----------------- # -----------------
github_install "oh-my-posh" "JanDeDobbeleer/oh-my-posh" github_install "oh-my-posh" "JanDeDobbeleer/oh-my-posh"
download_config "omp" "omp.json" "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.omp.json" download_config "omp" "omp.json" "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.omp.json"
install_rc "omp" "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.omp.rc" install_rc_download "omp" "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.omp.rc"
#install_binary_github "oh-my-posh" "JanDeDobbeleer/oh-my-posh" "posh-linux-ARCH" #install_binary_github "oh-my-posh" "JanDeDobbeleer/oh-my-posh" "posh-linux-ARCH"
} }
function p_fzf {
# -----------------
# Install fzf
# -----------------
local _repo="junegunn/fzf"
github_install "fzf" "${_repo}"
# Install latest release version of fzf-tmux
local _latest_version="$( github_latest ${_repo})"
local _path_fzf_tmux="$TMP_PATH/fzf-tmux"
download "https://raw.githubusercontent.com/${_repo}/${_latest_version}/bin/fzf-tmux" "${_path_fzf_tmux}"
install_binary "fzf-tmux" "${_path_fzf_tmux}"
# download autocomplete
if [ ! -z $ALL ] || user_confirm "Do you want to install fzf-tab as well?"; then
p_fzf_tab
fi
install_rc_download fzf "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/fzf.rc"
#download_config "fzf" "omp.json" "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.omp.json"
#install_rc "fzf" "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.omp.rc"
#install_binary_github "oh-my-posh" "JanDeDobbeleer/oh-my-posh" "posh-linux-ARCH"
}
function p_fzf_tab {
# -----------------
# Install fzf-tab
# -----------------
git_clone "https://github.com/Aloxaf/fzf-tab" "${CONFIG_PATH}/fzf/tools/fzf-tab"
install_rc_file "${CONFIG_PATH}/fzf/tools/fzf-tab/fzf-tab.plugin.zsh"
}
function install { function install {
if [ -z $1 ]; then if [ -z $1 ]; then
show_help_install show_help_install
@@ -599,9 +604,9 @@ function install {
# ----------------- # -----------------
# General Config # General Config
# ----------------- # -----------------
init_install_rc "export KHOME=$HOME_PATH" install_rc "export KHOME=$HOME_PATH"
init_install_rc "export XDG_CONFIG_HOME=$CONFIG_PATH" install_rc "export XDG_CONFIG_HOME=$CONFIG_PATH"
install_rc "shell" "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.general.rc" install_rc_download "shell" "https://git.cbeck.tech/kamu/dotfiles/raw/branch/main/.general.rc"
while : while :
do do
@@ -616,6 +621,7 @@ function install {
lsd) p_lsd; shift ;; lsd) p_lsd; shift ;;
omp) p_omp; shift ;; omp) p_omp; shift ;;
zoxide) p_zoxide; shift ;; zoxide) p_zoxide; shift ;;
fzf) p_fzf; shift ;;
# If invalid options were passed, then getopt should have reported an error, # If invalid options were passed, then getopt should have reported an error,
# which we checked as VALID_ARGUMENTS when getopt was called... # which we checked as VALID_ARGUMENTS when getopt was called...
*) log_error "Unrecognised program: $1"; shift ;; *) log_error "Unrecognised program: $1"; shift ;;
@@ -678,7 +684,7 @@ function get_architecture {
_cputype="$(uname -m)" _cputype="$(uname -m)"
_clibtype="gnu" _clibtype="gnu"
APP_FILTER="arm64|amd64|aarch64|i686|x86_64|x86-64|x64|musl|gnu|windows|darwin|linux|android|exe|sig|sha256" APP_FILTER="arm64|freebsd|openbsd|amd64|aarch64|i686|x86_64|x86-64|x64|musl|gnu|windows|darwin|linux|android|exe|sig|sha256"
if [ "${_ostype}" = Linux ]; then if [ "${_ostype}" = Linux ]; then
if [ "$(uname -o || true)" = Android ]; then if [ "$(uname -o || true)" = Android ]; then
@@ -731,6 +737,11 @@ function get_architecture {
;; ;;
FreeBSD) FreeBSD)
_ostype=unknown-freebsd _ostype=unknown-freebsd
APP_FILTER=$(echo $APP_FILTER | sed -e "s/freebsd|//gi")
;;
OpenBSD)
_ostype=unknown-freebsd
APP_FILTER=$(echo $APP_FILTER | sed -e "s/openbsd|//gi")
;; ;;
NetBSD) NetBSD)
_ostype=unknown-netbsd _ostype=unknown-netbsd