From 4dcc2957f9b7e46dd9f77a55b9b61535e83278b0 Mon Sep 17 00:00:00 2001 From: Joey Turner Date: Tue, 19 Nov 2024 14:40:09 -0600 Subject: [PATCH 01/16] Create module_atuin install remove logout and status for @atuinsh repo atuin --- tools/modules/software/module_atuin | 81 +++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tools/modules/software/module_atuin diff --git a/tools/modules/software/module_atuin b/tools/modules/software/module_atuin new file mode 100644 index 00000000..19a0a484 --- /dev/null +++ b/tools/modules/software/module_atuin @@ -0,0 +1,81 @@ +#!/bin/bash + +#declare -A module_options + +module_options+=( + ["module_atuin,author"]="@atuinsh" + ["module_atuin,maintainer"]="@armbian @Tearran" + ["module_atuin,testers"]="@Tearran" + ["module_atuin,feature"]="module_atuin" + ["module_atuin,example"]="help install remove logout status" + ["module_atuin,desc"]="Module to install logout and uninstall Atuin." + ["module_atuin,port"]="" + ["module_atuin,status"]="review" +) + +function module_atuin() { + local title="atuin" + local condition + condition=$(command -v atuin) + + # Convert the example string to an array + local commands + IFS=' ' read -r -a commands <<< "${module_options["module_atuin,example"]}" + + case "$1" in + "${commands[0]}") # Help Command + echo -e "\nUsage: ${module_options["module_atuin,feature"]} " + echo -e "Commands: ${module_options["module_atuin,example"]}\n" + echo "Available commands:" + if [[ -n "$condition" ]]; then + echo -e " remove\t- Uninstall $title" + echo -e " logout\t- Log out from $title" + else + echo -e " install\t- Install $title" + fi + echo -e " status\t- Check installation status of $title." + ;; + "${commands[1]}") # Install Command + echo "Installing $title..." + # Installation logic for Atuin + # Uncomment the next line for actual installation + curl -sSL https://raw.githubusercontent.com/atuinsh/atuin/main/install.sh | sh + echo "Warning: Please exit and restart your shell to reload the changes." + ;; + "${commands[2]}") # Remove Command + if [[ -n "$condition" ]]; then + echo "Removing $title..." + atuin logout + sudo rm -f "$(command -v atuin)" + rm -rf ~/.config/atuin ~/.local/share/atuin ~/.atuin + sed -i '/atuin init/d' ~/.bashrc ~/.zshrc ~/.fishrc ~/.bash_profile ~/.zprofile ~/.profile 2>/dev/null + echo "Atuin uninstallation complete. Please restart your shell." + else + echo "Atuin is not installed." + fi + ;; + "${commands[3]}") # Logout Command + if [[ -n "$condition" ]]; then + echo "Logging out of $title..." + atuin logout + echo "Logout complete." + else + echo "$title is not installed. Cannot log out." + fi + ;; + "${commands[-1]}") # Status Command + echo "Status of $title installation:" + if [[ -z "$condition" ]]; then + echo "$title is not installed." + else + echo "$title is installed." + fi + ;; + *) # Unknown Command + echo -e "Unknown command: $1\n" + echo -e "Available commands: ${module_options["module_atuin,example"]}" + ;; + esac +} + +#module_atuin "$@" From 790d81ab8d79ade337749678a5949792b11c7898 Mon Sep 17 00:00:00 2001 From: Joey Date: Tue, 19 Nov 2024 20:13:23 -0700 Subject: [PATCH 02/16] draft for container --- tools/modules/software/module_atuin | 76 ++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/tools/modules/software/module_atuin b/tools/modules/software/module_atuin index 19a0a484..81b766c5 100644 --- a/tools/modules/software/module_atuin +++ b/tools/modules/software/module_atuin @@ -1,6 +1,6 @@ #!/bin/bash -#declare -A module_options +declare -A module_options module_options+=( ["module_atuin,author"]="@atuinsh" @@ -79,3 +79,77 @@ function module_atuin() { } #module_atuin "$@" + +module_options+=( + ["module_atuin_docker,author"]="@armbian" + ["module_atuin_docker,ref_link"]="https://github.com/atuinsh/atuin" + ["module_atuin_docker,feature"]="module_atuin_docker" + ["module_atuin_docker,desc"]="Install/uninstall/check status of Atuin Docker container" + ["module_atuin_docker,example"]="help install remove status" + ["module_atuin_docker,status"]="Active" +) + +module_atuin_docker() { + local title="Atuin (Docker)" + local image="ghcr.io/atuinsh/atuin:c5c5e9d@sha256:74c90013ec60a25b071b068c430ffaebd3b19cf96dc4ececc859bc266cba8b71" + local container="atuin_docker" + + # Check Docker installation and container/image presence + if command -v docker &>/dev/null; then + local container_exists=$(docker container ls -a --format '{{.Names}}' | grep -x "$container") + local image_exists=$(docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -F "${image%%@*}") + fi + + # Convert the example string to an array + local commands + IFS=' ' read -r -a commands <<< "${module_options["module_atuin_docker,example"]}" + + case "$1" in + "${commands[0]}") # Help Command + echo -e "\nUsage: ${module_options["module_atuin_docker,feature"]} " + echo -e "Commands: ${module_options["module_atuin_docker,example"]}" + echo "Available commands:" + if [[ "${container_exists}" ]] || [[ "${image_exists}" ]]; then + echo -e " status\t- Show the status of the $title container." + echo -e " uninstall\t- Remove $title." + else + echo -e " install\t- Install $title." + fi + echo + ;; + install) # Install Command + if ! command -v docker &>/dev/null; then + echo "Docker is not installed. Installing Docker..." + # Uncomment the next line to implement Docker installation + # install_docker + fi + echo "Pulling Atuin Docker image..." + docker pull "$image" + echo "Running Atuin Docker container..." + docker run --rm --name "$container" "$image" + echo "$title installation and container setup complete." + ;; + remove) # Uninstall Command + echo "Removing Atuin Docker container and image..." + [[ "${container_exists}" ]] && docker container rm -f "$container" + [[ "${image_exists}" ]] && docker image rm "$image" + echo "$title uninstallation complete." + ;; + "${commands[-1]}") # Status Command + if [[ "${container_exists}" ]] || [[ "${image_exists}" ]]; then + echo "$title is installed and/or running." + [[ "${container_exists}" ]] && echo "Container: $container is running." + [[ "${image_exists}" ]] && echo "Image: $image is available." + else + echo "$title is not installed or running." + fi + ;; + *) # Unknown Command + echo -e "Unknown command: $1\n" + echo -e "Available commands: ${module_options["module_atuin_docker,example"]}" + ;; + esac +} + +# Uncomment to test the function + module_atuin_docker "$@" From 2ac9c336684d2399600ee8d5e5cbdb03d5f14bbe Mon Sep 17 00:00:00 2001 From: Joey Date: Tue, 19 Nov 2024 21:22:13 -0700 Subject: [PATCH 03/16] docker consept --- tools/modules/software/module_atuin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/modules/software/module_atuin b/tools/modules/software/module_atuin index 81b766c5..c542a6ff 100644 --- a/tools/modules/software/module_atuin +++ b/tools/modules/software/module_atuin @@ -78,7 +78,7 @@ function module_atuin() { esac } -#module_atuin "$@" +module_atuin "$@" module_options+=( ["module_atuin_docker,author"]="@armbian" @@ -152,4 +152,4 @@ module_atuin_docker() { } # Uncomment to test the function - module_atuin_docker "$@" +# module_atuin_docker "$@" From a981d4ce63e93640642eb86c22db0dd6f040980c Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 20 Nov 2024 01:53:21 -0700 Subject: [PATCH 04/16] add atuin config --- tools/modules/software/module_atuin | 83 ++++------------------------- 1 file changed, 10 insertions(+), 73 deletions(-) diff --git a/tools/modules/software/module_atuin b/tools/modules/software/module_atuin index c542a6ff..bfdced70 100644 --- a/tools/modules/software/module_atuin +++ b/tools/modules/software/module_atuin @@ -9,6 +9,7 @@ module_options+=( ["module_atuin,feature"]="module_atuin" ["module_atuin,example"]="help install remove logout status" ["module_atuin,desc"]="Module to install logout and uninstall Atuin." + ["module_atuin,remote"]="https://services.armbian.de/atuin" ["module_atuin,port"]="" ["module_atuin,status"]="review" ) @@ -39,7 +40,8 @@ function module_atuin() { echo "Installing $title..." # Installation logic for Atuin # Uncomment the next line for actual installation - curl -sSL https://raw.githubusercontent.com/atuinsh/atuin/main/install.sh | sh + #curl -sSL https://raw.githubusercontent.com/atuinsh/atuin/main/install.sh | sh + [[ -f ~/.config/atuin/config.toml ]] && set_atuin_config > ~/.config/atuin/config.toml echo "Warning: Please exit and restart your shell to reload the changes." ;; "${commands[2]}") # Remove Command @@ -78,78 +80,13 @@ function module_atuin() { esac } -module_atuin "$@" - -module_options+=( - ["module_atuin_docker,author"]="@armbian" - ["module_atuin_docker,ref_link"]="https://github.com/atuinsh/atuin" - ["module_atuin_docker,feature"]="module_atuin_docker" - ["module_atuin_docker,desc"]="Install/uninstall/check status of Atuin Docker container" - ["module_atuin_docker,example"]="help install remove status" - ["module_atuin_docker,status"]="Active" -) -module_atuin_docker() { - local title="Atuin (Docker)" - local image="ghcr.io/atuinsh/atuin:c5c5e9d@sha256:74c90013ec60a25b071b068c430ffaebd3b19cf96dc4ececc859bc266cba8b71" - local container="atuin_docker" - - # Check Docker installation and container/image presence - if command -v docker &>/dev/null; then - local container_exists=$(docker container ls -a --format '{{.Names}}' | grep -x "$container") - local image_exists=$(docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -F "${image%%@*}") - fi - - # Convert the example string to an array - local commands - IFS=' ' read -r -a commands <<< "${module_options["module_atuin_docker,example"]}" - - case "$1" in - "${commands[0]}") # Help Command - echo -e "\nUsage: ${module_options["module_atuin_docker,feature"]} " - echo -e "Commands: ${module_options["module_atuin_docker,example"]}" - echo "Available commands:" - if [[ "${container_exists}" ]] || [[ "${image_exists}" ]]; then - echo -e " status\t- Show the status of the $title container." - echo -e " uninstall\t- Remove $title." - else - echo -e " install\t- Install $title." - fi - echo - ;; - install) # Install Command - if ! command -v docker &>/dev/null; then - echo "Docker is not installed. Installing Docker..." - # Uncomment the next line to implement Docker installation - # install_docker - fi - echo "Pulling Atuin Docker image..." - docker pull "$image" - echo "Running Atuin Docker container..." - docker run --rm --name "$container" "$image" - echo "$title installation and container setup complete." - ;; - remove) # Uninstall Command - echo "Removing Atuin Docker container and image..." - [[ "${container_exists}" ]] && docker container rm -f "$container" - [[ "${image_exists}" ]] && docker image rm "$image" - echo "$title uninstallation complete." - ;; - "${commands[-1]}") # Status Command - if [[ "${container_exists}" ]] || [[ "${image_exists}" ]]; then - echo "$title is installed and/or running." - [[ "${container_exists}" ]] && echo "Container: $container is running." - [[ "${image_exists}" ]] && echo "Image: $image is available." - else - echo "$title is not installed or running." - fi - ;; - *) # Unknown Command - echo -e "Unknown command: $1\n" - echo -e "Available commands: ${module_options["module_atuin_docker,example"]}" - ;; - esac +function set_atuin_config() { + cat << EOF +## address of the sync server +sync_address = "${module_options["module_atuin,remote"]}" +EOF } -# Uncomment to test the function -# module_atuin_docker "$@" + +module_atuin "$@" From 1ac52b164e007576d58cfbc82ae3d8676d4bb30c Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 20 Nov 2024 01:55:40 -0700 Subject: [PATCH 05/16] fix install uncomment --- tools/modules/software/module_atuin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/modules/software/module_atuin b/tools/modules/software/module_atuin index bfdced70..2517cd43 100644 --- a/tools/modules/software/module_atuin +++ b/tools/modules/software/module_atuin @@ -40,7 +40,7 @@ function module_atuin() { echo "Installing $title..." # Installation logic for Atuin # Uncomment the next line for actual installation - #curl -sSL https://raw.githubusercontent.com/atuinsh/atuin/main/install.sh | sh + curl -sSL https://raw.githubusercontent.com/atuinsh/atuin/main/install.sh | sh [[ -f ~/.config/atuin/config.toml ]] && set_atuin_config > ~/.config/atuin/config.toml echo "Warning: Please exit and restart your shell to reload the changes." ;; From 51c8657954d7be40924ca717376bac30a35cbe1f Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 20 Nov 2024 12:55:47 -0700 Subject: [PATCH 06/16] update atuin config generation --- tools/modules/software/module_atuin | 52 ++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/tools/modules/software/module_atuin b/tools/modules/software/module_atuin index 2517cd43..386cd0c0 100644 --- a/tools/modules/software/module_atuin +++ b/tools/modules/software/module_atuin @@ -7,7 +7,7 @@ module_options+=( ["module_atuin,maintainer"]="@armbian @Tearran" ["module_atuin,testers"]="@Tearran" ["module_atuin,feature"]="module_atuin" - ["module_atuin,example"]="help install remove logout status" + ["module_atuin,example"]="help install remove reset logout status" ["module_atuin,desc"]="Module to install logout and uninstall Atuin." ["module_atuin,remote"]="https://services.armbian.de/atuin" ["module_atuin,port"]="" @@ -29,8 +29,9 @@ function module_atuin() { echo -e "Commands: ${module_options["module_atuin,example"]}\n" echo "Available commands:" if [[ -n "$condition" ]]; then - echo -e " remove\t- Uninstall $title" + echo -e " reset \t- reset config to atuin default" echo -e " logout\t- Log out from $title" + echo -e " remove\t- Uninstall $title" else echo -e " install\t- Install $title" fi @@ -41,7 +42,7 @@ function module_atuin() { # Installation logic for Atuin # Uncomment the next line for actual installation curl -sSL https://raw.githubusercontent.com/atuinsh/atuin/main/install.sh | sh - [[ -f ~/.config/atuin/config.toml ]] && set_atuin_config > ~/.config/atuin/config.toml + [[ -f ~/.config/atuin/config.toml ]] && generate_atuin_config echo "Warning: Please exit and restart your shell to reload the changes." ;; "${commands[2]}") # Remove Command @@ -56,7 +57,13 @@ function module_atuin() { echo "Atuin is not installed." fi ;; - "${commands[3]}") # Logout Command + "${commands[3]}") # Logout Command + if [[ -n "$condition" ]]; then + echo "config reset $title..." + atuin + fi + ;; + "${commands[4]}") # Logout Command if [[ -n "$condition" ]]; then echo "Logging out of $title..." atuin logout @@ -80,13 +87,40 @@ function module_atuin() { esac } +function generate_atuin_config() { + local output_file="$HOME/.config/atuin/config.toml" + + # Ensure the target directory exists + mkdir -p "$(dirname "$output_file")" + + # Configuration template as a here-document + cat <<'EOF' > "$output_file" +sync_address = "https://services.armbian.de/atuin" +db_path = "~/.local/share/atuin/history.db" +key_path = "~/.local/share/atuin/key" +session_path = "~/.local/share/atuin/session" +auto_sync = false +# update_check = true +# sync_frequency = "10m" + +[sync] +records = true + +[daemon] +# enabled = false +# sync_frequency = 300 +# socket_path = "~/.local/share/atuin/atuin.sock" +# systemd_socket = false -function set_atuin_config() { - cat << EOF -## address of the sync server -sync_address = "${module_options["module_atuin,remote"]}" EOF + + echo "Configuration file created at $output_file" } -module_atuin "$@" +# Uncomment one for testing +# set_atuin_config +# generate_atuin_config +module_atuin "$1" +#"$@" + From e037a8c95230f78db82086f916bbc3a34a3dc197 Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 20 Nov 2024 14:29:44 -0700 Subject: [PATCH 07/16] add for sudo use --- tools/modules/software/module_atuin | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/modules/software/module_atuin b/tools/modules/software/module_atuin index 386cd0c0..a63139ab 100644 --- a/tools/modules/software/module_atuin +++ b/tools/modules/software/module_atuin @@ -2,6 +2,8 @@ declare -A module_options + + module_options+=( ["module_atuin,author"]="@atuinsh" ["module_atuin,maintainer"]="@armbian @Tearran" @@ -15,6 +17,15 @@ module_options+=( ) function module_atuin() { + + if [ "$EUID" -eq 0 ]; then + USER_HOME=$(eval echo ~${SUDO_USER}) + HOME=$USER_HOME + else + USER_HOME=$HOME + fi + # Determine the appropriate home directory + local title="atuin" local condition condition=$(command -v atuin) @@ -42,7 +53,7 @@ function module_atuin() { # Installation logic for Atuin # Uncomment the next line for actual installation curl -sSL https://raw.githubusercontent.com/atuinsh/atuin/main/install.sh | sh - [[ -f ~/.config/atuin/config.toml ]] && generate_atuin_config + generate_atuin_config echo "Warning: Please exit and restart your shell to reload the changes." ;; "${commands[2]}") # Remove Command @@ -57,10 +68,10 @@ function module_atuin() { echo "Atuin is not installed." fi ;; - "${commands[3]}") # Logout Command + "${commands[3]}") # setup defaults if [[ -n "$condition" ]]; then - echo "config reset $title..." - atuin + echo "config reset $title to armbian defaults" + generate_atuin_config fi ;; "${commands[4]}") # Logout Command @@ -88,7 +99,11 @@ function module_atuin() { } function generate_atuin_config() { - local output_file="$HOME/.config/atuin/config.toml" + + # Use USER_HOME for file operations + echo "Creating files in $USER_HOME" + sleep 1 + local output_file="$USER_HOME/.config/atuin/config.toml" # Ensure the target directory exists mkdir -p "$(dirname "$output_file")" From f4f1fe2e1a139f2aeec3b08f8e8ba76145fc5437 Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 20 Nov 2024 14:41:33 -0700 Subject: [PATCH 08/16] removed missed sudo --- tools/modules/software/module_atuin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/modules/software/module_atuin b/tools/modules/software/module_atuin index a63139ab..4000702c 100644 --- a/tools/modules/software/module_atuin +++ b/tools/modules/software/module_atuin @@ -60,7 +60,7 @@ function module_atuin() { if [[ -n "$condition" ]]; then echo "Removing $title..." atuin logout - sudo rm -f "$(command -v atuin)" + rm -f "$(command -v atuin)" rm -rf ~/.config/atuin ~/.local/share/atuin ~/.atuin sed -i '/atuin init/d' ~/.bashrc ~/.zshrc ~/.fishrc ~/.bash_profile ~/.zprofile ~/.profile 2>/dev/null echo "Atuin uninstallation complete. Please restart your shell." From 43398d4a6acf5d5bb8b2ac7be7c788ebd2e4904e Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 21 Nov 2024 15:19:54 -0700 Subject: [PATCH 09/16] added sh to use --api --- tools/modules/software/module_atuin | 141 -------------- tools/modules/software/module_atuin.sh | 257 +++++++++++++++++++++++++ 2 files changed, 257 insertions(+), 141 deletions(-) delete mode 100644 tools/modules/software/module_atuin create mode 100644 tools/modules/software/module_atuin.sh diff --git a/tools/modules/software/module_atuin b/tools/modules/software/module_atuin deleted file mode 100644 index 4000702c..00000000 --- a/tools/modules/software/module_atuin +++ /dev/null @@ -1,141 +0,0 @@ -#!/bin/bash - -declare -A module_options - - - -module_options+=( - ["module_atuin,author"]="@atuinsh" - ["module_atuin,maintainer"]="@armbian @Tearran" - ["module_atuin,testers"]="@Tearran" - ["module_atuin,feature"]="module_atuin" - ["module_atuin,example"]="help install remove reset logout status" - ["module_atuin,desc"]="Module to install logout and uninstall Atuin." - ["module_atuin,remote"]="https://services.armbian.de/atuin" - ["module_atuin,port"]="" - ["module_atuin,status"]="review" -) - -function module_atuin() { - - if [ "$EUID" -eq 0 ]; then - USER_HOME=$(eval echo ~${SUDO_USER}) - HOME=$USER_HOME - else - USER_HOME=$HOME - fi - # Determine the appropriate home directory - - local title="atuin" - local condition - condition=$(command -v atuin) - - # Convert the example string to an array - local commands - IFS=' ' read -r -a commands <<< "${module_options["module_atuin,example"]}" - - case "$1" in - "${commands[0]}") # Help Command - echo -e "\nUsage: ${module_options["module_atuin,feature"]} " - echo -e "Commands: ${module_options["module_atuin,example"]}\n" - echo "Available commands:" - if [[ -n "$condition" ]]; then - echo -e " reset \t- reset config to atuin default" - echo -e " logout\t- Log out from $title" - echo -e " remove\t- Uninstall $title" - else - echo -e " install\t- Install $title" - fi - echo -e " status\t- Check installation status of $title." - ;; - "${commands[1]}") # Install Command - echo "Installing $title..." - # Installation logic for Atuin - # Uncomment the next line for actual installation - curl -sSL https://raw.githubusercontent.com/atuinsh/atuin/main/install.sh | sh - generate_atuin_config - echo "Warning: Please exit and restart your shell to reload the changes." - ;; - "${commands[2]}") # Remove Command - if [[ -n "$condition" ]]; then - echo "Removing $title..." - atuin logout - rm -f "$(command -v atuin)" - rm -rf ~/.config/atuin ~/.local/share/atuin ~/.atuin - sed -i '/atuin init/d' ~/.bashrc ~/.zshrc ~/.fishrc ~/.bash_profile ~/.zprofile ~/.profile 2>/dev/null - echo "Atuin uninstallation complete. Please restart your shell." - else - echo "Atuin is not installed." - fi - ;; - "${commands[3]}") # setup defaults - if [[ -n "$condition" ]]; then - echo "config reset $title to armbian defaults" - generate_atuin_config - fi - ;; - "${commands[4]}") # Logout Command - if [[ -n "$condition" ]]; then - echo "Logging out of $title..." - atuin logout - echo "Logout complete." - else - echo "$title is not installed. Cannot log out." - fi - ;; - "${commands[-1]}") # Status Command - echo "Status of $title installation:" - if [[ -z "$condition" ]]; then - echo "$title is not installed." - else - echo "$title is installed." - fi - ;; - *) # Unknown Command - echo -e "Unknown command: $1\n" - echo -e "Available commands: ${module_options["module_atuin,example"]}" - ;; - esac -} - -function generate_atuin_config() { - - # Use USER_HOME for file operations - echo "Creating files in $USER_HOME" - sleep 1 - local output_file="$USER_HOME/.config/atuin/config.toml" - - # Ensure the target directory exists - mkdir -p "$(dirname "$output_file")" - - # Configuration template as a here-document - cat <<'EOF' > "$output_file" -sync_address = "https://services.armbian.de/atuin" -db_path = "~/.local/share/atuin/history.db" -key_path = "~/.local/share/atuin/key" -session_path = "~/.local/share/atuin/session" -auto_sync = false -# update_check = true -# sync_frequency = "10m" - -[sync] -records = true - -[daemon] -# enabled = false -# sync_frequency = 300 -# socket_path = "~/.local/share/atuin/atuin.sock" -# systemd_socket = false - -EOF - - echo "Configuration file created at $output_file" -} - - -# Uncomment one for testing -# set_atuin_config -# generate_atuin_config -module_atuin "$1" -#"$@" - diff --git a/tools/modules/software/module_atuin.sh b/tools/modules/software/module_atuin.sh new file mode 100644 index 00000000..8af1d2fd --- /dev/null +++ b/tools/modules/software/module_atuin.sh @@ -0,0 +1,257 @@ +#!/bin/bash + +#declare -A module_options + +module_options+=( + ["module_atuin,author"]="@atuinsh" + ["module_atuin,maintainer"]="@armbian @Tearran" + ["module_atuin,testers"]="@Tearran" + ["module_atuin,feature"]="module_atuin" + ["module_atuin,example"]="help install remove reset" + ["module_atuin,desc"]="Module to install logout and uninstall Atuin." + ["module_atuin,remote"]="https://services.armbian.de/atuin" + ["module_atuin,port"]="" + ["module_atuin,status"]="review" +) + +function module_atuin() { + + local user_name user_home + if [[ $EUID -eq 0 ]]; then + user_name=${SUDO_USER:-$USER} # Use SUDO_USER or fallback to $user + user_home=$(eval echo ~"$user_name") + else + user_name=$USER + user_home=$HOME + fi + + local title="atuin" + local condition + condition=$(command -v atuin) + + # Convert the example string to an array + local commands + IFS=' ' read -r -a commands <<< "${module_options["module_atuin,example"]}" + + case "$1" in + help) # Help Command + echo -e "\nUsage: ${module_options["module_atuin,feature"]} " + echo -e "Commands: ${module_options["module_atuin,example"]}\n" + echo "Available commands:" + if [[ -n "$condition" ]]; then + echo -e " reset \t- reset config to atuin default" + echo -e " logout\t- Log out from $title" + echo -e " remove\t- Uninstall $title" + else + echo -e " install\t- Install $title" + fi + echo -e " status\t- Check installation status of $title." + ;; + install) # Install Command + echo "Installing $title..." + # Installation logic for Atuin + # Uncomment the next line for actual installation + set_atuin + generate_atuin_config + echo "Warning: Please exit and restart your shell to reload the changes." + ;; + remove) # Remove Command + echo "Under constrution Removing $title..." + remove_atuin + + + ;; + "${commands[3]}") # setup defaults + if [[ -n "$condition" ]]; then + echo "config reset $title to armbian defaults" + generate_atuin_config + fi + ;; + *) # Unknown Command + echo -e "Unknown command: $1\n" + echo -e "Available commands: ${module_options["module_atuin,example"]}" + ;; + esac +} + +set_atuin() { + # Ensure correct user environment if running as root + local user_name user_home + if [[ $EUID -eq 0 ]]; then + # Check if SUDO_USER is set + if [ -z "$SUDO_USER" ]; then + echo "Error: Unknown user. SUDO_USER is not set." >&2 + exit 1 + fi + user_name=$SUDO_USER + user_home=$(eval echo ~"$user_name") + else + user_name=$USER + user_home=$HOME + fi + + # Define variables + atuin_url="https://github.com/atuinsh/atuin/releases/download/v18.4.0-beta.3/atuin-x86_64-unknown-linux-gnu.tar.gz" + atuin_dir="$user_home/.atuin/bin" + atuin_binary="atuin" + bash_preexec_file="$user_home/.bash-preexec.sh" + atuin_bashrc_file="$user_home/.bashrc" + + # Create target directory as the user (not as root) + mkdir -p "$atuin_dir" + # Ensure correct ownership (user should own these files) + chown "$user_name:$user_name" "$atuin_dir" + + # Download and install as the correct user + if [[ ! -f "$user_home/atuin.tar.gz" ]]; then + echo "Downloading Atuin installer..." + wget -q --show-progress "$atuin_url" -O "$user_home/atuin.tar.gz" || { echo "Error: Failed to download the file." >&2; exit 1; } + else + echo "File already exists. Skipping download." + fi + + # Extract the tar.gz file as the user + echo "Extracting Atuin binary..." + tar -xvzf "$user_home/atuin.tar.gz" -C "$user_home" + + # Move the binary to the desired location as the user + echo "Moving Atuin binary to $atuin_dir..." + mv "$user_home/atuin-aarch64-unknown-linux-gnu/$atuin_binary" "$atuin_dir/$atuin_binary" + + # Clean up the extracted folder (leave the tar file for testing) + echo "Cleaning up extracted folder..." + rm -rf "$user_home/atuin-aarch64-unknown-linux-gnu" + + # Change ownership of the Atuin binary to the user + chown "$user_name:$user_name" "$atuin_dir/$atuin_binary" + + generate_atuin_config + + # Create env file for shell (sh compatible) as the user + echo "Creating env file to set PATH..." + cat < "$atuin_dir/env" +#!/bin/sh +# Add binaries to PATH if they aren't added yet +# Affix colons on either side of \$PATH to simplify matching +case ":${PATH}:" in + *:"\$HOME/.atuin/bin":*) + ;; + *) + # Prepending path in case a system-installed binary needs to be overridden + export PATH="\$HOME/.atuin/bin:\$PATH" + ;; +esac +EOL + echo "Env file created at $atuin_dir/env" + + # Ensure the user can update their .bashrc file + echo "Updating .bashrc..." + if ! grep -q ". \$HOME/.atuin/bin/env" "$atuin_bashrc_file"; then + echo ". \$HOME/.atuin/bin/env" >> "$atuin_bashrc_file" + echo "Added . $HOME/.atuin/bin/env to .bashrc" + fi + + # Ensure the user can update .bash-preexec.sh + if [[ ! -f "$bash_preexec_file" ]]; then + echo "~/.bash-preexec.sh not found. Downloading..." + wget -q https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -O "$bash_preexec_file" || { echo "Error: Failed to download .bash-preexec.sh" >&2; exit 1; } + fi + if ! grep -q '[[ -f "$user_home"/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' "$atuin_bashrc_file"; then + echo '[[ -f "$user_home"/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> "$atuin_bashrc_file" + fi + + # Ensure eval "$(atuin init bash)" is in .bashrc + if ! grep -q 'eval "$(atuin init bash)"' "$atuin_bashrc_file"; then + echo 'eval "$(atuin init bash)"' >> "$atuin_bashrc_file" + fi + + # Make sure all directories and files are owned by the user + chown -R "$user_name:$user_name" "$user_home/.atuin" + + echo "Atuin installation complete!" +} + + +remove_atuin() { + # Ensure correct user environment if running as root + local user_name user_home + if [[ $EUID -eq 0 ]]; then + # Check if SUDO_USER is set + if [ -z "$SUDO_USER" ]; then + echo "Error: Unknown user. SUDO_USER is not set." >&2 + exit 1 + fi + user_name=$SUDO_USER + user_home=$(eval echo ~"$user_name") + else + user_name=$USER + user_home=$HOME + fi + + # Check if Atuin is installed and proceed with removal + echo "Removing Atuin..." + + # Define file paths to remove + atuin_bin_path="$user_home/.atuin/bin/atuin" + atuin_config_dir="$user_home/.config/atuin" + atuin_local_share_dir="$user_home/.local/share/atuin" + atuin_home_dir="$user_home/.atuin" + bash_preexec_file="$user_home/.bash-preexec.sh" + atuin_bashrc_file="$user_home/.bashrc" + + # Remove Atuin binary and related directories + rm -f "$atuin_bin_path" + rm -rf "$atuin_config_dir" "$atuin_local_share_dir" "$atuin_home_dir" + + # Remove lines related to Atuin from .bashrc + echo "Removing Atuin references from .bashrc..." + sed -i '/\[\[ -f ~\/.bash-preexec.sh \]\] && source ~\/.bash-preexec.sh/d' "$atuin_bashrc_file" + sed -i '/eval "\$(atuin init bash)"/d' "$atuin_bashrc_file" + + echo "Atuin uninstallation complete. Please restart your shell." + +} + + + +function generate_atuin_config() { + + local user_name user_home + if [[ $EUID -eq 0 ]]; then + user_name=${SUDO_USER:-$USER} # Use SUDO_USER or fallback to $user + user_home=$(eval echo ~"$user_name") + else + user_name=$USER + user_home=$HOME + fi + # Use USER_HOME for file operations + echo "Creating files in $user_home" + local ouput_folder=".config/atuin" + local output_file="config.toml" + + # Ensure the target directory exists + mkdir -p "$user_home/$ouput_folder" + chown $user_name:$user_name "$user_home/$ouput_folder" + # Configuration template as a here-document + cat <<'EOF' > "$user_home/$ouput_folder/$output_file" +sync_address = "https://services.armbian.de/atuin" +db_path = "~/.local/share/atuin/history.db" +key_path = "~/.local/share/atuin/key" +session_path = "~/.local/share/atuin/session" +# auto_sync = false +# update_check = true +# sync_frequency = "10m" + +[sync] +records = true + +EOF + + # Change ownership of the configuration file to the non-root user + chown $user_name:$user_name "$user_home/$ouput_folder/$output_file" + + echo "Configuration file created at $user_home/$ouput_folder/$output_file" + +} + +#module_atuin "$1" From 7513218a544cd5846b1990bdc8d76c505fbb4792 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 21 Nov 2024 15:23:43 -0700 Subject: [PATCH 10/16] fix: style --- tools/modules/software/module_atuin.sh | 236 ++++++++++++------------- 1 file changed, 118 insertions(+), 118 deletions(-) diff --git a/tools/modules/software/module_atuin.sh b/tools/modules/software/module_atuin.sh index 8af1d2fd..580a4224 100644 --- a/tools/modules/software/module_atuin.sh +++ b/tools/modules/software/module_atuin.sh @@ -75,61 +75,61 @@ function module_atuin() { } set_atuin() { - # Ensure correct user environment if running as root - local user_name user_home - if [[ $EUID -eq 0 ]]; then - # Check if SUDO_USER is set - if [ -z "$SUDO_USER" ]; then - echo "Error: Unknown user. SUDO_USER is not set." >&2 - exit 1 - fi - user_name=$SUDO_USER - user_home=$(eval echo ~"$user_name") - else - user_name=$USER - user_home=$HOME - fi - - # Define variables - atuin_url="https://github.com/atuinsh/atuin/releases/download/v18.4.0-beta.3/atuin-x86_64-unknown-linux-gnu.tar.gz" - atuin_dir="$user_home/.atuin/bin" - atuin_binary="atuin" - bash_preexec_file="$user_home/.bash-preexec.sh" - atuin_bashrc_file="$user_home/.bashrc" - - # Create target directory as the user (not as root) - mkdir -p "$atuin_dir" - # Ensure correct ownership (user should own these files) - chown "$user_name:$user_name" "$atuin_dir" - - # Download and install as the correct user - if [[ ! -f "$user_home/atuin.tar.gz" ]]; then - echo "Downloading Atuin installer..." - wget -q --show-progress "$atuin_url" -O "$user_home/atuin.tar.gz" || { echo "Error: Failed to download the file." >&2; exit 1; } - else - echo "File already exists. Skipping download." - fi - - # Extract the tar.gz file as the user - echo "Extracting Atuin binary..." - tar -xvzf "$user_home/atuin.tar.gz" -C "$user_home" - - # Move the binary to the desired location as the user - echo "Moving Atuin binary to $atuin_dir..." - mv "$user_home/atuin-aarch64-unknown-linux-gnu/$atuin_binary" "$atuin_dir/$atuin_binary" - - # Clean up the extracted folder (leave the tar file for testing) - echo "Cleaning up extracted folder..." - rm -rf "$user_home/atuin-aarch64-unknown-linux-gnu" - - # Change ownership of the Atuin binary to the user - chown "$user_name:$user_name" "$atuin_dir/$atuin_binary" - - generate_atuin_config - - # Create env file for shell (sh compatible) as the user - echo "Creating env file to set PATH..." - cat < "$atuin_dir/env" + # Ensure correct user environment if running as root + local user_name user_home + if [[ $EUID -eq 0 ]]; then + # Check if SUDO_USER is set + if [ -z "$SUDO_USER" ]; then + echo "Error: Unknown user. SUDO_USER is not set." >&2 + exit 1 + fi + user_name=$SUDO_USER + user_home=$(eval echo ~"$user_name") + else + user_name=$USER + user_home=$HOME + fi + + # Define variables + atuin_url="https://github.com/atuinsh/atuin/releases/download/v18.4.0-beta.3/atuin-x86_64-unknown-linux-gnu.tar.gz" + atuin_dir="$user_home/.atuin/bin" + atuin_binary="atuin" + bash_preexec_file="$user_home/.bash-preexec.sh" + atuin_bashrc_file="$user_home/.bashrc" + + # Create target directory as the user (not as root) + mkdir -p "$atuin_dir" + # Ensure correct ownership (user should own these files) + chown "$user_name:$user_name" "$atuin_dir" + + # Download and install as the correct user + if [[ ! -f "$user_home/atuin.tar.gz" ]]; then + echo "Downloading Atuin installer..." + wget -q --show-progress "$atuin_url" -O "$user_home/atuin.tar.gz" || { echo "Error: Failed to download the file." >&2; exit 1; } + else + echo "File already exists. Skipping download." + fi + + # Extract the tar.gz file as the user + echo "Extracting Atuin binary..." + tar -xvzf "$user_home/atuin.tar.gz" -C "$user_home" + + # Move the binary to the desired location as the user + echo "Moving Atuin binary to $atuin_dir..." + mv "$user_home/atuin-aarch64-unknown-linux-gnu/$atuin_binary" "$atuin_dir/$atuin_binary" + + # Clean up the extracted folder (leave the tar file for testing) + echo "Cleaning up extracted folder..." + rm -rf "$user_home/atuin-aarch64-unknown-linux-gnu" + + # Change ownership of the Atuin binary to the user + chown "$user_name:$user_name" "$atuin_dir/$atuin_binary" + + generate_atuin_config + + # Create env file for shell (sh compatible) as the user + echo "Creating env file to set PATH..." + cat < "$atuin_dir/env" #!/bin/sh # Add binaries to PATH if they aren't added yet # Affix colons on either side of \$PATH to simplify matching @@ -142,73 +142,73 @@ case ":${PATH}:" in ;; esac EOL - echo "Env file created at $atuin_dir/env" - - # Ensure the user can update their .bashrc file - echo "Updating .bashrc..." - if ! grep -q ". \$HOME/.atuin/bin/env" "$atuin_bashrc_file"; then - echo ". \$HOME/.atuin/bin/env" >> "$atuin_bashrc_file" - echo "Added . $HOME/.atuin/bin/env to .bashrc" - fi - - # Ensure the user can update .bash-preexec.sh - if [[ ! -f "$bash_preexec_file" ]]; then - echo "~/.bash-preexec.sh not found. Downloading..." - wget -q https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -O "$bash_preexec_file" || { echo "Error: Failed to download .bash-preexec.sh" >&2; exit 1; } - fi - if ! grep -q '[[ -f "$user_home"/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' "$atuin_bashrc_file"; then - echo '[[ -f "$user_home"/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> "$atuin_bashrc_file" - fi - - # Ensure eval "$(atuin init bash)" is in .bashrc - if ! grep -q 'eval "$(atuin init bash)"' "$atuin_bashrc_file"; then - echo 'eval "$(atuin init bash)"' >> "$atuin_bashrc_file" - fi - - # Make sure all directories and files are owned by the user - chown -R "$user_name:$user_name" "$user_home/.atuin" - - echo "Atuin installation complete!" + echo "Env file created at $atuin_dir/env" + + # Ensure the user can update their .bashrc file + echo "Updating .bashrc..." + if ! grep -q ". \$HOME/.atuin/bin/env" "$atuin_bashrc_file"; then + echo ". \$HOME/.atuin/bin/env" >> "$atuin_bashrc_file" + echo "Added . $HOME/.atuin/bin/env to .bashrc" + fi + + # Ensure the user can update .bash-preexec.sh + if [[ ! -f "$bash_preexec_file" ]]; then + echo "~/.bash-preexec.sh not found. Downloading..." + wget -q https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -O "$bash_preexec_file" || { echo "Error: Failed to download .bash-preexec.sh" >&2; exit 1; } + fi + if ! grep -q '[[ -f "$user_home"/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' "$atuin_bashrc_file"; then + echo '[[ -f "$user_home"/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> "$atuin_bashrc_file" + fi + + # Ensure eval "$(atuin init bash)" is in .bashrc + if ! grep -q 'eval "$(atuin init bash)"' "$atuin_bashrc_file"; then + echo 'eval "$(atuin init bash)"' >> "$atuin_bashrc_file" + fi + + # Make sure all directories and files are owned by the user + chown -R "$user_name:$user_name" "$user_home/.atuin" + + echo "Atuin installation complete!" } remove_atuin() { - # Ensure correct user environment if running as root - local user_name user_home - if [[ $EUID -eq 0 ]]; then - # Check if SUDO_USER is set - if [ -z "$SUDO_USER" ]; then - echo "Error: Unknown user. SUDO_USER is not set." >&2 - exit 1 - fi - user_name=$SUDO_USER - user_home=$(eval echo ~"$user_name") - else - user_name=$USER - user_home=$HOME - fi - - # Check if Atuin is installed and proceed with removal - echo "Removing Atuin..." - - # Define file paths to remove - atuin_bin_path="$user_home/.atuin/bin/atuin" - atuin_config_dir="$user_home/.config/atuin" - atuin_local_share_dir="$user_home/.local/share/atuin" - atuin_home_dir="$user_home/.atuin" - bash_preexec_file="$user_home/.bash-preexec.sh" - atuin_bashrc_file="$user_home/.bashrc" - - # Remove Atuin binary and related directories - rm -f "$atuin_bin_path" - rm -rf "$atuin_config_dir" "$atuin_local_share_dir" "$atuin_home_dir" - - # Remove lines related to Atuin from .bashrc - echo "Removing Atuin references from .bashrc..." - sed -i '/\[\[ -f ~\/.bash-preexec.sh \]\] && source ~\/.bash-preexec.sh/d' "$atuin_bashrc_file" - sed -i '/eval "\$(atuin init bash)"/d' "$atuin_bashrc_file" - - echo "Atuin uninstallation complete. Please restart your shell." + # Ensure correct user environment if running as root + local user_name user_home + if [[ $EUID -eq 0 ]]; then + # Check if SUDO_USER is set + if [ -z "$SUDO_USER" ]; then + echo "Error: Unknown user. SUDO_USER is not set." >&2 + exit 1 + fi + user_name=$SUDO_USER + user_home=$(eval echo ~"$user_name") + else + user_name=$USER + user_home=$HOME + fi + + # Check if Atuin is installed and proceed with removal + echo "Removing Atuin..." + + # Define file paths to remove + atuin_bin_path="$user_home/.atuin/bin/atuin" + atuin_config_dir="$user_home/.config/atuin" + atuin_local_share_dir="$user_home/.local/share/atuin" + atuin_home_dir="$user_home/.atuin" + bash_preexec_file="$user_home/.bash-preexec.sh" + atuin_bashrc_file="$user_home/.bashrc" + + # Remove Atuin binary and related directories + rm -f "$atuin_bin_path" + rm -rf "$atuin_config_dir" "$atuin_local_share_dir" "$atuin_home_dir" + + # Remove lines related to Atuin from .bashrc + echo "Removing Atuin references from .bashrc..." + sed -i '/\[\[ -f ~\/.bash-preexec.sh \]\] && source ~\/.bash-preexec.sh/d' "$atuin_bashrc_file" + sed -i '/eval "\$(atuin init bash)"/d' "$atuin_bashrc_file" + + echo "Atuin uninstallation complete. Please restart your shell." } From a5a9efc58320e13d0cd62b529f70ded489de7c6e Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 21 Nov 2024 17:28:30 -0700 Subject: [PATCH 11/16] fix: style --- tools/modules/software/module_atuin.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/modules/software/module_atuin.sh b/tools/modules/software/module_atuin.sh index 580a4224..417ee48d 100644 --- a/tools/modules/software/module_atuin.sh +++ b/tools/modules/software/module_atuin.sh @@ -1,4 +1,3 @@ -#!/bin/bash #declare -A module_options From aa974ddde31e4ee2c1e9fdc6512c69ccbbdfa31c Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 21 Nov 2024 17:31:45 -0700 Subject: [PATCH 12/16] fix style --- tools/modules/software/module_atuin.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/modules/software/module_atuin.sh b/tools/modules/software/module_atuin.sh index 417ee48d..931cd985 100644 --- a/tools/modules/software/module_atuin.sh +++ b/tools/modules/software/module_atuin.sh @@ -73,7 +73,7 @@ function module_atuin() { esac } -set_atuin() { +function set_atuin() { # Ensure correct user environment if running as root local user_name user_home if [[ $EUID -eq 0 ]]; then @@ -133,12 +133,12 @@ set_atuin() { # Add binaries to PATH if they aren't added yet # Affix colons on either side of \$PATH to simplify matching case ":${PATH}:" in - *:"\$HOME/.atuin/bin":*) - ;; - *) - # Prepending path in case a system-installed binary needs to be overridden - export PATH="\$HOME/.atuin/bin:\$PATH" - ;; + *:"\$HOME/.atuin/bin":*) + ;; + *) + # Prepending path in case a system-installed binary needs to be overridden + export PATH="\$HOME/.atuin/bin:\$PATH" + ;; esac EOL echo "Env file created at $atuin_dir/env" From 5e8ac7394eaa75ef68a6cb881ce3de29705e36a7 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 21 Nov 2024 18:49:45 -0700 Subject: [PATCH 13/16] style and tuning --- tools/modules/software/module_atuin.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/modules/software/module_atuin.sh b/tools/modules/software/module_atuin.sh index 931cd985..2d6a7a1e 100644 --- a/tools/modules/software/module_atuin.sh +++ b/tools/modules/software/module_atuin.sh @@ -67,8 +67,8 @@ function module_atuin() { fi ;; *) # Unknown Command - echo -e "Unknown command: $1\n" - echo -e "Available commands: ${module_options["module_atuin,example"]}" + echo -e "Unknown command: $1\n" + echo -e "Available commands: ${module_options["module_atuin,example"]}" ;; esac } @@ -143,11 +143,10 @@ esac EOL echo "Env file created at $atuin_dir/env" - # Ensure the user can update their .bashrc file echo "Updating .bashrc..." - if ! grep -q ". \$HOME/.atuin/bin/env" "$atuin_bashrc_file"; then - echo ". \$HOME/.atuin/bin/env" >> "$atuin_bashrc_file" - echo "Added . $HOME/.atuin/bin/env to .bashrc" + if ! grep -q ". ~/.atuin/bin/env" "$atuin_bashrc_file"; then + echo ". ~/.atuin/bin/env" >> "$atuin_bashrc_file" + echo "Added . ~/.atuin/bin/env to .bashrc" fi # Ensure the user can update .bash-preexec.sh @@ -155,8 +154,8 @@ EOL echo "~/.bash-preexec.sh not found. Downloading..." wget -q https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -O "$bash_preexec_file" || { echo "Error: Failed to download .bash-preexec.sh" >&2; exit 1; } fi - if ! grep -q '[[ -f "$user_home"/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' "$atuin_bashrc_file"; then - echo '[[ -f "$user_home"/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> "$atuin_bashrc_file" + if ! grep -q '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' "$atuin_bashrc_file"; then + echo '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> "$atuin_bashrc_file" fi # Ensure eval "$(atuin init bash)" is in .bashrc From c0f1643f4c61a3a539a86f3bf770e9d0d358b2ad Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 21 Nov 2024 19:01:13 -0700 Subject: [PATCH 14/16] fix style --- tools/modules/software/module_atuin.sh | 53 +++++++++++--------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/tools/modules/software/module_atuin.sh b/tools/modules/software/module_atuin.sh index 2d6a7a1e..8935f608 100644 --- a/tools/modules/software/module_atuin.sh +++ b/tools/modules/software/module_atuin.sh @@ -33,38 +33,32 @@ function module_atuin() { IFS=' ' read -r -a commands <<< "${module_options["module_atuin,example"]}" case "$1" in - help) # Help Command - echo -e "\nUsage: ${module_options["module_atuin,feature"]} " - echo -e "Commands: ${module_options["module_atuin,example"]}\n" - echo "Available commands:" - if [[ -n "$condition" ]]; then + help) + # Help Command + echo -e "\nUsage: ${module_options["module_atuin,feature"]} " + echo -e "Commands: ${module_options["module_atuin,example"]}\n" + echo "Available commands:" echo -e " reset \t- reset config to atuin default" echo -e " logout\t- Log out from $title" echo -e " remove\t- Uninstall $title" - else - echo -e " install\t- Install $title" - fi - echo -e " status\t- Check installation status of $title." ;; - install) # Install Command - echo "Installing $title..." - # Installation logic for Atuin - # Uncomment the next line for actual installation - set_atuin - generate_atuin_config - echo "Warning: Please exit and restart your shell to reload the changes." + install) + # Install Command + echo "Installing $title..." + # Installation logic for Atuin + # Uncomment the next line for actual installation + set_atuin + generate_atuin_config + echo "Warning: Please exit and restart your shell to reload the changes." ;; - remove) # Remove Command + remove) + # Remove Command echo "Under constrution Removing $title..." remove_atuin - - ;; - "${commands[3]}") # setup defaults - if [[ -n "$condition" ]]; then + reset) echo "config reset $title to armbian defaults" generate_atuin_config - fi ;; *) # Unknown Command echo -e "Unknown command: $1\n" @@ -74,7 +68,12 @@ function module_atuin() { } function set_atuin() { - # Ensure correct user environment if running as root + # Define variables + atuin_url="https://github.com/atuinsh/atuin/releases/download/v18.4.0-beta.3/atuin-x86_64-unknown-linux-gnu.tar.gz" + atuin_dir="$user_home/.atuin/bin" + atuin_binary="atuin" + bash_preexec_file="$user_home/.bash-preexec.sh" + atuin_bashrc_file="$user_home/.bashrc" local user_name user_home if [[ $EUID -eq 0 ]]; then # Check if SUDO_USER is set @@ -89,13 +88,6 @@ function set_atuin() { user_home=$HOME fi - # Define variables - atuin_url="https://github.com/atuinsh/atuin/releases/download/v18.4.0-beta.3/atuin-x86_64-unknown-linux-gnu.tar.gz" - atuin_dir="$user_home/.atuin/bin" - atuin_binary="atuin" - bash_preexec_file="$user_home/.bash-preexec.sh" - atuin_bashrc_file="$user_home/.bashrc" - # Create target directory as the user (not as root) mkdir -p "$atuin_dir" # Ensure correct ownership (user should own these files) @@ -211,7 +203,6 @@ remove_atuin() { } - function generate_atuin_config() { local user_name user_home From 83b7c80b653cbb85529f7359c08df30498bece59 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 21 Nov 2024 20:22:13 -0700 Subject: [PATCH 15/16] fix remove left line in bashrc --- tools/modules/software/module_atuin.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/modules/software/module_atuin.sh b/tools/modules/software/module_atuin.sh index 8935f608..23b83e4d 100644 --- a/tools/modules/software/module_atuin.sh +++ b/tools/modules/software/module_atuin.sh @@ -137,8 +137,8 @@ EOL echo "Updating .bashrc..." if ! grep -q ". ~/.atuin/bin/env" "$atuin_bashrc_file"; then - echo ". ~/.atuin/bin/env" >> "$atuin_bashrc_file" - echo "Added . ~/.atuin/bin/env to .bashrc" + echo -e ". ~/.atuin/bin/env" >> "$atuin_bashrc_file" + #echo "Added . ~/.atuin/bin/env to .bashrc" fi # Ensure the user can update .bash-preexec.sh @@ -147,12 +147,13 @@ EOL wget -q https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -O "$bash_preexec_file" || { echo "Error: Failed to download .bash-preexec.sh" >&2; exit 1; } fi if ! grep -q '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' "$atuin_bashrc_file"; then - echo '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> "$atuin_bashrc_file" + echo ' ' >> "$atuin_bashrc_file" + echo -e '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> "$atuin_bashrc_file" fi # Ensure eval "$(atuin init bash)" is in .bashrc if ! grep -q 'eval "$(atuin init bash)"' "$atuin_bashrc_file"; then - echo 'eval "$(atuin init bash)"' >> "$atuin_bashrc_file" + echo -e '\neval "$(atuin init bash)"' >> "$atuin_bashrc_file" fi # Make sure all directories and files are owned by the user @@ -195,6 +196,7 @@ remove_atuin() { # Remove lines related to Atuin from .bashrc echo "Removing Atuin references from .bashrc..." + sed -i '/\. ~\/\.atuin\/bin\/env/d' "$atuin_bashrc_file" sed -i '/\[\[ -f ~\/.bash-preexec.sh \]\] && source ~\/.bash-preexec.sh/d' "$atuin_bashrc_file" sed -i '/eval "\$(atuin init bash)"/d' "$atuin_bashrc_file" From f3f6bf67f08b1eda85a731bcab6ca967c3af64d6 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 21 Nov 2024 20:55:07 -0700 Subject: [PATCH 16/16] update help --- tools/modules/software/module_atuin.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/modules/software/module_atuin.sh b/tools/modules/software/module_atuin.sh index 23b83e4d..cf4cccf5 100644 --- a/tools/modules/software/module_atuin.sh +++ b/tools/modules/software/module_atuin.sh @@ -38,9 +38,9 @@ function module_atuin() { echo -e "\nUsage: ${module_options["module_atuin,feature"]} " echo -e "Commands: ${module_options["module_atuin,example"]}\n" echo "Available commands:" - echo -e " reset \t- reset config to atuin default" - echo -e " logout\t- Log out from $title" - echo -e " remove\t- Uninstall $title" + echo -e " install\t- setup $title in $user_home " + echo -e " reset \t- reset config to atuin default" + echo -e " remove\t- Uninstall $title" ;; install) # Install Command