Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # --- Configuration ---
- INSTALL_DIR="$HOME/Applications"
- DESKTOP_DIR="$HOME/.local/share/applications"
- # --- Colors ---
- GREEN='\033[0;32m'
- BLUE='\033[0;34m'
- NC='\033[0m'
- echo -e "${BLUE}=========================================${NC}"
- echo -e "${BLUE} Auto Local Installer (Fixed) ${NC}"
- echo -e "${BLUE}=========================================${NC}"
- # 1. Find the file (Simplified Logic)
- echo "Scanning directory for installer files..."
- # We look for files ending in .tar.gz, .zip, or .AppImage
- # We take the first one we find.
- TARGET_FILE=$(ls *.tar.gz *.tgz *.zip *.AppImage 2>/dev/null | head -n 1)
- if [ -z "$TARGET_FILE" ]; then
- echo -e "${RED}Error: No installation file (.tar.gz, .zip, .AppImage) found.${NC}"
- echo "Files found in this directory:"
- ls -lh
- read -p "Press Enter to exit..."
- exit 1
- fi
- echo -e "${GREEN}Found file: $TARGET_FILE${NC}"
- # 2. Derive App Name
- # Remove version numbers and extensions to get a clean name
- SAFE_NAME=$(echo "$TARGET_FILE" | sed -E 's/(-[0-9].*|\.tar\.gz|\.tgz|\.zip|\.AppImage)//g')
- # Capitalize first letter
- PRETTY_NAME=$(echo "$SAFE_NAME" | sed 's/./\U&/')
- echo "App Name detected: $PRETTY_NAME"
- FINAL_DEST="$INSTALL_DIR/$SAFE_NAME"
- # 3. Process the file
- echo -e "\n${GREEN}==> Installing...${NC}"
- mkdir -p "$INSTALL_DIR"
- # Clean destination if it exists
- rm -rf "$FINAL_DEST"
- mkdir -p "$FINAL_DEST"
- # Extract based on extension
- case "$TARGET_FILE" in
- *.tar.gz|*.tgz|*.tar.xz)
- echo "Extracting tarball..."
- tar -xf "$TARGET_FILE" -C "$FINAL_DEST" --strip-components=1 2>/dev/null || tar -xf "$TARGET_FILE" -C "$FINAL_DEST"
- ;;
- *.zip)
- echo "Extracting zip..."
- unzip -q "$TARGET_FILE" -d "$FINAL_DEST"
- ;;
- *.AppImage)
- echo "Setting up AppImage..."
- cp "$TARGET_FILE" "$FINAL_DEST/$SAFE_NAME.AppImage"
- chmod +x "$FINAL_DEST/$SAFE_NAME.AppImage"
- ;;
- esac
- # 4. Find the Executable
- cd "$FINAL_DEST"
- # Explicit check for JetBrains Toolbox
- if [ -f "jetbrains-toolbox" ]; then
- EXEC_PATH="$FINAL_DEST/jetbrains-toolbox"
- elif [ -f "AppRun" ]; then
- EXEC_PATH="$FINAL_DEST/AppRun"
- else
- # Fallback: Find the largest executable file
- EXEC_PATH=$(find . -maxdepth 2 -type f -executable | sort -rn | head -n 1)
- # Fix relative path
- if [[ "$EXEC_PATH" == .* ]]; then
- EXEC_PATH="$FINAL_DEST/${EXEC_PATH#./}"
- fi
- fi
- if [ -z "$EXEC_PATH" ]; then
- echo -e "${RED}Could not automatically find the executable.${NC}"
- echo "Opening folder for manual check..."
- xdg-open "$FINAL_DEST"
- read -p "Press Enter to exit..."
- exit 1
- fi
- echo -e "Executable found at: $EXEC_PATH"
- # 5. Create Shortcut
- SHORTCUT="$DESKTOP_DIR/$SAFE_NAME.desktop"
- cat > "$SHORTCUT" <<EOF
- [Desktop Entry]
- Type=Application
- Name=$PRETTY_NAME
- Exec="$EXEC_PATH"
- Icon=utilities-terminal
- Terminal=false
- Categories=Development;Utility;
- EOF
- chmod +x "$SHORTCUT"
- update-desktop-database "$DESKTOP_DIR" 2>/dev/null
- echo -e "${BLUE}=========================================${NC}"
- echo -e "${GREEN}SUCCESS!${NC}"
- echo -e "You can run the app by searching '$PRETTY_NAME' in your menu."
- echo -e "${BLUE}=========================================${NC}"
Add Comment
Please, Sign In to add comment