mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 15:04:42 +00:00
Better maintenance and stronger
This commit is contained in:
10
install.sh
10
install.sh
@@ -156,7 +156,15 @@ get_source_version() {
|
|||||||
get_installed_version() {
|
get_installed_version() {
|
||||||
local binary="$INSTALL_DIR/mole"
|
local binary="$INSTALL_DIR/mole"
|
||||||
if [[ -x "$binary" ]]; then
|
if [[ -x "$binary" ]]; then
|
||||||
"$binary" --version 2> /dev/null | awk 'NF {print $NF; exit}'
|
# Try running the binary first (preferred method)
|
||||||
|
local version
|
||||||
|
version=$("$binary" --version 2> /dev/null | awk 'NF {print $NF; exit}')
|
||||||
|
if [[ -n "$version" ]]; then
|
||||||
|
echo "$version"
|
||||||
|
else
|
||||||
|
# Fallback: parse VERSION from file (in case binary is broken)
|
||||||
|
sed -n 's/^VERSION="\(.*\)"$/\1/p' "$binary" | head -n1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
68
mole
68
mole
@@ -223,39 +223,35 @@ update_mole() {
|
|||||||
echo "Installing update..."
|
echo "Installing update..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run installer with visible output (but capture for error handling)
|
# Helper function to process installer output
|
||||||
local install_output
|
process_install_output() {
|
||||||
if install_output=$("$tmp_installer" --prefix "$install_dir" --config "$HOME/.config/mole" --update 2>&1); then
|
local output="$1"
|
||||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||||
|
|
||||||
local filtered_output
|
local filtered_output
|
||||||
filtered_output=$(printf '%s\n' "$install_output" | sed '/^$/d')
|
filtered_output=$(printf '%s\n' "$output" | sed '/^$/d')
|
||||||
if [[ -n "$filtered_output" ]]; then
|
if [[ -n "$filtered_output" ]]; then
|
||||||
printf '\n%s\n' "$filtered_output"
|
printf '\n%s\n' "$filtered_output"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Only show success message if installer didn't already do so
|
# Only show success message if installer didn't already do so
|
||||||
if ! printf '%s\n' "$install_output" | grep -Eq "Updated to latest version|Already on latest version"; then
|
if ! printf '%s\n' "$output" | grep -Eq "Updated to latest version|Already on latest version"; then
|
||||||
local new_version
|
local new_version
|
||||||
new_version=$("$mole_path" --version 2> /dev/null | awk 'NF {print $NF}' || echo "")
|
new_version=$("$mole_path" --version 2> /dev/null | awk 'NF {print $NF}' || echo "")
|
||||||
printf '\n%s\n\n' "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version (${new_version:-unknown})"
|
printf '\n%s\n\n' "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version (${new_version:-unknown})"
|
||||||
else
|
else
|
||||||
printf '\n'
|
printf '\n'
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run installer with visible output (but capture for error handling)
|
||||||
|
local install_output
|
||||||
|
if install_output=$("$tmp_installer" --prefix "$install_dir" --config "$HOME/.config/mole" --update 2>&1); then
|
||||||
|
process_install_output "$install_output"
|
||||||
else
|
else
|
||||||
# Retry without --update flag
|
# Retry without --update flag
|
||||||
if install_output=$("$tmp_installer" --prefix "$install_dir" --config "$HOME/.config/mole" 2>&1); then
|
if install_output=$("$tmp_installer" --prefix "$install_dir" --config "$HOME/.config/mole" 2>&1); then
|
||||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
process_install_output "$install_output"
|
||||||
local filtered_output
|
|
||||||
filtered_output=$(printf '%s\n' "$install_output" | sed '/^$/d')
|
|
||||||
if [[ -n "$filtered_output" ]]; then
|
|
||||||
printf '\n%s\n' "$filtered_output"
|
|
||||||
fi
|
|
||||||
if ! printf '%s\n' "$install_output" | grep -Eq "Updated to latest version|Already on latest version"; then
|
|
||||||
local new_version
|
|
||||||
new_version=$("$mole_path" --version 2> /dev/null | awk 'NF {print $NF}' || echo "")
|
|
||||||
printf '\n%s\n\n' "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version (${new_version:-unknown})"
|
|
||||||
else
|
|
||||||
printf '\n'
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||||
rm -f "$tmp_installer"
|
rm -f "$tmp_installer"
|
||||||
@@ -287,15 +283,25 @@ remove_mole() {
|
|||||||
is_homebrew=true
|
is_homebrew=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check common manual install locations
|
# Find mole installations using which/command
|
||||||
local -a common_paths=(
|
local found_mole
|
||||||
|
found_mole=$(command -v mole 2>/dev/null || true)
|
||||||
|
if [[ -n "$found_mole" && -f "$found_mole" ]]; then
|
||||||
|
# Check if it's not a Homebrew symlink
|
||||||
|
if [[ ! -L "$found_mole" ]] || ! readlink "$found_mole" | grep -q "Cellar/mole"; then
|
||||||
|
manual_installs+=("$found_mole")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Also check common locations as fallback
|
||||||
|
local -a fallback_paths=(
|
||||||
"/usr/local/bin/mole"
|
"/usr/local/bin/mole"
|
||||||
"$HOME/.local/bin/mole"
|
"$HOME/.local/bin/mole"
|
||||||
"/opt/local/bin/mole"
|
"/opt/local/bin/mole"
|
||||||
)
|
)
|
||||||
|
|
||||||
for path in "${common_paths[@]}"; do
|
for path in "${fallback_paths[@]}"; do
|
||||||
if [[ -f "$path" ]]; then
|
if [[ -f "$path" && "$path" != "$found_mole" ]]; then
|
||||||
# Check if it's not a Homebrew symlink
|
# Check if it's not a Homebrew symlink
|
||||||
if [[ ! -L "$path" ]] || ! readlink "$path" | grep -q "Cellar/mole"; then
|
if [[ ! -L "$path" ]] || ! readlink "$path" | grep -q "Cellar/mole"; then
|
||||||
manual_installs+=("$path")
|
manual_installs+=("$path")
|
||||||
@@ -303,14 +309,22 @@ remove_mole() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
local -a alias_candidates=(
|
# Find mo alias
|
||||||
|
local found_mo
|
||||||
|
found_mo=$(command -v mo 2>/dev/null || true)
|
||||||
|
if [[ -n "$found_mo" && -f "$found_mo" ]]; then
|
||||||
|
alias_installs+=("$found_mo")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Also check common locations for mo
|
||||||
|
local -a alias_fallback=(
|
||||||
"/usr/local/bin/mo"
|
"/usr/local/bin/mo"
|
||||||
"$HOME/.local/bin/mo"
|
"$HOME/.local/bin/mo"
|
||||||
"/opt/local/bin/mo"
|
"/opt/local/bin/mo"
|
||||||
)
|
)
|
||||||
|
|
||||||
for alias in "${alias_candidates[@]}"; do
|
for alias in "${alias_fallback[@]}"; do
|
||||||
if [[ -f "$alias" ]]; then
|
if [[ -f "$alias" && "$alias" != "$found_mo" ]]; then
|
||||||
alias_installs+=("$alias")
|
alias_installs+=("$alias")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -477,7 +491,9 @@ interactive_main_menu() {
|
|||||||
tty_name=$(tty 2> /dev/null || echo "")
|
tty_name=$(tty 2> /dev/null || echo "")
|
||||||
if [[ -n "$tty_name" ]]; then
|
if [[ -n "$tty_name" ]]; then
|
||||||
local flag_file
|
local flag_file
|
||||||
flag_file="/tmp/mole_intro_$(echo "$tty_name" | tr -c '[:alnum:]_' '_')"
|
local cache_dir="$HOME/.cache/mole"
|
||||||
|
mkdir -p "$cache_dir" 2> /dev/null
|
||||||
|
flag_file="$cache_dir/intro_$(echo "$tty_name" | tr -c '[:alnum:]_' '_')"
|
||||||
if [[ ! -f "$flag_file" ]]; then
|
if [[ ! -f "$flag_file" ]]; then
|
||||||
animate_mole_intro
|
animate_mole_intro
|
||||||
touch "$flag_file" 2> /dev/null || true
|
touch "$flag_file" 2> /dev/null || true
|
||||||
|
|||||||
Reference in New Issue
Block a user