1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 13:16:47 +00:00

Install simplified

This commit is contained in:
Tw93
2025-12-28 14:04:31 +08:00
parent 9f1bc402ee
commit 8cecb3ff73

View File

@@ -40,10 +40,11 @@ fi; }
VERBOSE=1 VERBOSE=1
# Icons (duplicated from lib/core/common.sh - necessary as install.sh runs standalone) # Icons (duplicated from lib/core/common.sh - necessary as install.sh runs standalone)
readonly ICON_SUCCESS="✓" # Note: Don't use 'readonly' here to avoid conflicts when sourcing common.sh later
readonly ICON_ADMIN="" ICON_SUCCESS=""
readonly ICON_CONFIRM="" ICON_ADMIN=""
readonly ICON_ERROR="" ICON_CONFIRM=""
ICON_ERROR="☻"
# Logging functions # Logging functions
log_info() { [[ ${VERBOSE} -eq 1 ]] && echo -e "${BLUE}$1${NC}"; } log_info() { [[ ${VERBOSE} -eq 1 ]] && echo -e "${BLUE}$1${NC}"; }
@@ -61,6 +62,21 @@ SOURCE_DIR=""
# Default action (install|update) # Default action (install|update)
ACTION="install" ACTION="install"
# Check if we need sudo for install directory operations
needs_sudo() {
[[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ ! -w "$INSTALL_DIR" ]]
}
# Execute command with sudo if needed
# Usage: maybe_sudo cp source dest
maybe_sudo() {
if needs_sudo; then
sudo "$@"
else
"$@"
fi
}
show_help() { show_help() {
cat << 'EOF' cat << 'EOF'
Mole Installation Script Mole Installation Script
@@ -120,13 +136,18 @@ resolve_source_dir() {
start_line_spinner "Fetching Mole source..." start_line_spinner "Fetching Mole source..."
if command -v curl > /dev/null 2>&1; then if command -v curl > /dev/null 2>&1; then
if curl -fsSL -o "$tmp/mole.tar.gz" "https://github.com/tw93/mole/archive/refs/heads/main.tar.gz"; then if curl -fsSL -o "$tmp/mole.tar.gz" "https://github.com/tw93/mole/archive/refs/heads/main.tar.gz" 2>/dev/null; then
stop_line_spinner if tar -xzf "$tmp/mole.tar.gz" -C "$tmp" 2>/dev/null; then
tar -xzf "$tmp/mole.tar.gz" -C "$tmp" stop_line_spinner
# Extracted folder name: mole-main # Extracted folder name: Mole-main (capital M)
if [[ -d "$tmp/mole-main" ]]; then if [[ -d "$tmp/Mole-main" ]]; then
SOURCE_DIR="$tmp/mole-main" SOURCE_DIR="$tmp/Mole-main"
return 0 return 0
# Fallback for lowercase (in case GitHub changes it)
elif [[ -d "$tmp/mole-main" ]]; then
SOURCE_DIR="$tmp/mole-main"
return 0
fi
fi fi
fi fi
fi fi
@@ -239,11 +260,7 @@ check_requirements() {
create_directories() { create_directories() {
# Create install directory if it doesn't exist # Create install directory if it doesn't exist
if [[ ! -d "$INSTALL_DIR" ]]; then if [[ ! -d "$INSTALL_DIR" ]]; then
if [[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ ! -w "$(dirname "$INSTALL_DIR")" ]]; then maybe_sudo mkdir -p "$INSTALL_DIR"
sudo mkdir -p "$INSTALL_DIR"
else
mkdir -p "$INSTALL_DIR"
fi
fi fi
# Create config directory # Create config directory
@@ -268,14 +285,11 @@ install_files() {
# Copy main executable when destination differs # Copy main executable when destination differs
if [[ -f "$SOURCE_DIR/mole" ]]; then if [[ -f "$SOURCE_DIR/mole" ]]; then
if [[ "$source_dir_abs" != "$install_dir_abs" ]]; then if [[ "$source_dir_abs" != "$install_dir_abs" ]]; then
if [[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ ! -w "$INSTALL_DIR" ]]; then if needs_sudo; then
log_admin "Admin access required for /usr/local/bin" log_admin "Admin access required for /usr/local/bin"
sudo cp "$SOURCE_DIR/mole" "$INSTALL_DIR/mole"
sudo chmod +x "$INSTALL_DIR/mole"
else
cp "$SOURCE_DIR/mole" "$INSTALL_DIR/mole"
chmod +x "$INSTALL_DIR/mole"
fi fi
maybe_sudo cp "$SOURCE_DIR/mole" "$INSTALL_DIR/mole"
maybe_sudo chmod +x "$INSTALL_DIR/mole"
log_success "Installed mole to $INSTALL_DIR" log_success "Installed mole to $INSTALL_DIR"
fi fi
else else
@@ -288,13 +302,8 @@ install_files() {
if [[ "$source_dir_abs" == "$install_dir_abs" ]]; then if [[ "$source_dir_abs" == "$install_dir_abs" ]]; then
log_success "mo alias already present" log_success "mo alias already present"
else else
if [[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ ! -w "$INSTALL_DIR" ]]; then maybe_sudo cp "$SOURCE_DIR/mo" "$INSTALL_DIR/mo"
sudo cp "$SOURCE_DIR/mo" "$INSTALL_DIR/mo" maybe_sudo chmod +x "$INSTALL_DIR/mo"
sudo chmod +x "$INSTALL_DIR/mo"
else
cp "$SOURCE_DIR/mo" "$INSTALL_DIR/mo"
chmod +x "$INSTALL_DIR/mo"
fi
log_success "Installed mo alias" log_success "Installed mo alias"
fi fi
fi fi
@@ -338,11 +347,7 @@ install_files() {
# Update the mole script to use the config directory when installed elsewhere # Update the mole script to use the config directory when installed elsewhere
if [[ "$source_dir_abs" != "$install_dir_abs" ]]; then if [[ "$source_dir_abs" != "$install_dir_abs" ]]; then
if [[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ ! -w "$INSTALL_DIR" ]]; then maybe_sudo sed -i '' "s|SCRIPT_DIR=.*|SCRIPT_DIR=\"$CONFIG_DIR\"|" "$INSTALL_DIR/mole"
sudo sed -i '' "s|SCRIPT_DIR=.*|SCRIPT_DIR=\"$CONFIG_DIR\"|" "$INSTALL_DIR/mole"
else
sed -i '' "s|SCRIPT_DIR=.*|SCRIPT_DIR=\"$CONFIG_DIR\"|" "$INSTALL_DIR/mole"
fi
fi fi
} }
@@ -435,21 +440,15 @@ uninstall_mole() {
# Remove executable # Remove executable
if [[ -f "$INSTALL_DIR/mole" ]]; then if [[ -f "$INSTALL_DIR/mole" ]]; then
if [[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ ! -w "$INSTALL_DIR" ]]; then if needs_sudo; then
log_admin "Admin access required" log_admin "Admin access required"
sudo rm -f "$INSTALL_DIR/mole"
else
rm -f "$INSTALL_DIR/mole"
fi fi
maybe_sudo rm -f "$INSTALL_DIR/mole"
log_success "Removed mole executable" log_success "Removed mole executable"
fi fi
if [[ -f "$INSTALL_DIR/mo" ]]; then if [[ -f "$INSTALL_DIR/mo" ]]; then
if [[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ ! -w "$INSTALL_DIR" ]]; then maybe_sudo rm -f "$INSTALL_DIR/mo"
sudo rm -f "$INSTALL_DIR/mo"
else
rm -f "$INSTALL_DIR/mo"
fi
log_success "Removed mo alias" log_success "Removed mo alias"
fi fi