STANAANDREY

install local

Jan 7th, 2026
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # --- Configuration ---
  4. INSTALL_DIR="$HOME/Applications"
  5. DESKTOP_DIR="$HOME/.local/share/applications"
  6.  
  7. # --- Colors ---
  8. GREEN='\033[0;32m'
  9. BLUE='\033[0;34m'
  10. NC='\033[0m'
  11.  
  12. echo -e "${BLUE}=========================================${NC}"
  13. echo -e "${BLUE}   Auto Local Installer (Fixed)          ${NC}"
  14. echo -e "${BLUE}=========================================${NC}"
  15.  
  16. # 1. Find the file (Simplified Logic)
  17. echo "Scanning directory for installer files..."
  18.  
  19. # We look for files ending in .tar.gz, .zip, or .AppImage
  20. # We take the first one we find.
  21. TARGET_FILE=$(ls *.tar.gz *.tgz *.zip *.AppImage 2>/dev/null | head -n 1)
  22.  
  23. if [ -z "$TARGET_FILE" ]; then
  24.     echo -e "${RED}Error: No installation file (.tar.gz, .zip, .AppImage) found.${NC}"
  25.     echo "Files found in this directory:"
  26.     ls -lh
  27.     read -p "Press Enter to exit..."
  28.     exit 1
  29. fi
  30.  
  31. echo -e "${GREEN}Found file: $TARGET_FILE${NC}"
  32.  
  33. # 2. Derive App Name
  34. # Remove version numbers and extensions to get a clean name
  35. SAFE_NAME=$(echo "$TARGET_FILE" | sed -E 's/(-[0-9].*|\.tar\.gz|\.tgz|\.zip|\.AppImage)//g')
  36. # Capitalize first letter
  37. PRETTY_NAME=$(echo "$SAFE_NAME" | sed 's/./\U&/')
  38.  
  39. echo "App Name detected: $PRETTY_NAME"
  40. FINAL_DEST="$INSTALL_DIR/$SAFE_NAME"
  41.  
  42. # 3. Process the file
  43. echo -e "\n${GREEN}==> Installing...${NC}"
  44. mkdir -p "$INSTALL_DIR"
  45.  
  46. # Clean destination if it exists
  47. rm -rf "$FINAL_DEST"
  48. mkdir -p "$FINAL_DEST"
  49.  
  50. # Extract based on extension
  51. case "$TARGET_FILE" in
  52.     *.tar.gz|*.tgz|*.tar.xz)
  53.         echo "Extracting tarball..."
  54.         tar -xf "$TARGET_FILE" -C "$FINAL_DEST" --strip-components=1 2>/dev/null || tar -xf "$TARGET_FILE" -C "$FINAL_DEST"
  55.         ;;
  56.     *.zip)
  57.         echo "Extracting zip..."
  58.         unzip -q "$TARGET_FILE" -d "$FINAL_DEST"
  59.         ;;
  60.     *.AppImage)
  61.         echo "Setting up AppImage..."
  62.         cp "$TARGET_FILE" "$FINAL_DEST/$SAFE_NAME.AppImage"
  63.         chmod +x "$FINAL_DEST/$SAFE_NAME.AppImage"
  64.         ;;
  65. esac
  66.  
  67. # 4. Find the Executable
  68. cd "$FINAL_DEST"
  69.  
  70. # Explicit check for JetBrains Toolbox
  71. if [ -f "jetbrains-toolbox" ]; then
  72.     EXEC_PATH="$FINAL_DEST/jetbrains-toolbox"
  73. elif [ -f "AppRun" ]; then
  74.     EXEC_PATH="$FINAL_DEST/AppRun"
  75. else
  76.     # Fallback: Find the largest executable file
  77.     EXEC_PATH=$(find . -maxdepth 2 -type f -executable | sort -rn | head -n 1)
  78.    
  79.     # Fix relative path
  80.     if [[ "$EXEC_PATH" == .* ]]; then
  81.         EXEC_PATH="$FINAL_DEST/${EXEC_PATH#./}"
  82.     fi
  83. fi
  84.  
  85. if [ -z "$EXEC_PATH" ]; then
  86.     echo -e "${RED}Could not automatically find the executable.${NC}"
  87.     echo "Opening folder for manual check..."
  88.     xdg-open "$FINAL_DEST"
  89.     read -p "Press Enter to exit..."
  90.     exit 1
  91. fi
  92.  
  93. echo -e "Executable found at: $EXEC_PATH"
  94.  
  95. # 5. Create Shortcut
  96. SHORTCUT="$DESKTOP_DIR/$SAFE_NAME.desktop"
  97.  
  98. cat > "$SHORTCUT" <<EOF
  99. [Desktop Entry]
  100. Type=Application
  101. Name=$PRETTY_NAME
  102. Exec="$EXEC_PATH"
  103. Icon=utilities-terminal
  104. Terminal=false
  105. Categories=Development;Utility;
  106. EOF
  107.  
  108. chmod +x "$SHORTCUT"
  109. update-desktop-database "$DESKTOP_DIR" 2>/dev/null
  110.  
  111. echo -e "${BLUE}=========================================${NC}"
  112. echo -e "${GREEN}SUCCESS!${NC}"
  113. echo -e "You can run the app by searching '$PRETTY_NAME' in your menu."
  114. echo -e "${BLUE}=========================================${NC}"
Add Comment
Please, Sign In to add comment