uninstall.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/bin/bash
  2. # uninstall.sh - Uninstalls OpenCode Agents
  3. set -e
  4. # Colors
  5. RED='\033[0;31m'
  6. GREEN='\033[0;32m'
  7. YELLOW='\033[1;33m'
  8. BLUE='\033[0;34m'
  9. NC='\033[0m' # No Color
  10. echo ""
  11. echo -e "${BLUE}OpenCode Agents Uninstaller${NC}"
  12. echo "=============================="
  13. echo ""
  14. # Parse arguments
  15. UNINSTALL_TYPE=""
  16. FORCE=false
  17. while [[ $# -gt 0 ]]; do
  18. case $1 in
  19. --global)
  20. UNINSTALL_TYPE="global"
  21. shift
  22. ;;
  23. --local)
  24. UNINSTALL_TYPE="local"
  25. shift
  26. ;;
  27. --force)
  28. FORCE=true
  29. shift
  30. ;;
  31. --help|-h)
  32. echo "Usage: ./uninstall.sh [options]"
  33. echo ""
  34. echo "Options:"
  35. echo " --global Uninstall from ~/.config/opencode"
  36. echo " --local Uninstall from current directory .opencode/"
  37. echo " --force Skip confirmation prompts"
  38. echo " --help Show this help message"
  39. echo ""
  40. exit 0
  41. ;;
  42. *)
  43. echo "Unknown option: $1"
  44. echo "Use --help for usage information"
  45. exit 1
  46. ;;
  47. esac
  48. done
  49. # Determine uninstall location
  50. if [ -z "$UNINSTALL_TYPE" ]; then
  51. echo "Select uninstall location:"
  52. echo " 1) Local (.opencode/ in current directory)"
  53. echo " 2) Global (~/.config/opencode/)"
  54. echo ""
  55. read -p "Enter your choice [1-2]: " choice
  56. case $choice in
  57. 1) UNINSTALL_TYPE="local" ;;
  58. 2) UNINSTALL_TYPE="global" ;;
  59. *)
  60. echo -e "${RED}Invalid choice${NC}"
  61. exit 1
  62. ;;
  63. esac
  64. fi
  65. # Set target directory
  66. if [ "$UNINSTALL_TYPE" == "global" ]; then
  67. TARGET_DIR="$HOME/.config/opencode"
  68. else
  69. TARGET_DIR="$(pwd)/.opencode"
  70. fi
  71. echo ""
  72. echo -e "${YELLOW}Uninstall location:${NC} $TARGET_DIR"
  73. echo ""
  74. # Check if installation exists
  75. if [ ! -f "$TARGET_DIR/.opencode-agents-version" ]; then
  76. echo -e "${YELLOW}⚠️ No OpenCode Agents installation found at: $TARGET_DIR${NC}"
  77. echo ""
  78. echo "This directory may contain other files or a manual installation."
  79. echo ""
  80. if [ "$FORCE" != "true" ]; then
  81. read -p "Continue with uninstall anyway? (y/N): " -n 1 -r
  82. echo ""
  83. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  84. echo "Uninstall cancelled."
  85. exit 0
  86. fi
  87. fi
  88. else
  89. # Show installation info
  90. echo "Installation details:"
  91. cat "$TARGET_DIR/.opencode-agents-version"
  92. echo ""
  93. fi
  94. # Confirm uninstall
  95. if [ "$FORCE" != "true" ]; then
  96. echo -e "${RED}⚠️ This will remove all OpenCode Agents files from: $TARGET_DIR${NC}"
  97. echo ""
  98. echo "The following will be removed:"
  99. echo " - $TARGET_DIR/agent/"
  100. echo " - $TARGET_DIR/command/"
  101. echo " - $TARGET_DIR/context/"
  102. echo " - $TARGET_DIR/.opencode-agents-version"
  103. echo ""
  104. read -p "Are you sure you want to uninstall? (y/N): " -n 1 -r
  105. echo ""
  106. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  107. echo "Uninstall cancelled."
  108. exit 0
  109. fi
  110. fi
  111. # Perform uninstall
  112. echo ""
  113. echo "Uninstalling..."
  114. removed_count=0
  115. # Remove agent directory
  116. if [ -d "$TARGET_DIR/agent" ]; then
  117. rm -rf "$TARGET_DIR/agent"
  118. echo -e "${GREEN}✓${NC} Removed agents"
  119. removed_count=$((removed_count + 1))
  120. fi
  121. # Remove command directory
  122. if [ -d "$TARGET_DIR/command" ]; then
  123. rm -rf "$TARGET_DIR/command"
  124. echo -e "${GREEN}✓${NC} Removed commands"
  125. removed_count=$((removed_count + 1))
  126. fi
  127. # Remove context directory
  128. if [ -d "$TARGET_DIR/context" ]; then
  129. rm -rf "$TARGET_DIR/context"
  130. echo -e "${GREEN}✓${NC} Removed context files"
  131. removed_count=$((removed_count + 1))
  132. fi
  133. # Remove version file
  134. if [ -f "$TARGET_DIR/.opencode-agents-version" ]; then
  135. rm -f "$TARGET_DIR/.opencode-agents-version"
  136. echo -e "${GREEN}✓${NC} Removed installation metadata"
  137. fi
  138. # Remove AGENTS.md.new if it exists
  139. if [ -f "$TARGET_DIR/AGENTS.md.new" ]; then
  140. rm -f "$TARGET_DIR/AGENTS.md.new"
  141. echo -e "${GREEN}✓${NC} Removed AGENTS.md.new"
  142. fi
  143. # Check if directory is now empty
  144. if [ -d "$TARGET_DIR" ]; then
  145. if [ -z "$(ls -A "$TARGET_DIR")" ]; then
  146. read -p "Remove empty directory $TARGET_DIR? (y/N): " -n 1 -r
  147. echo ""
  148. if [[ $REPLY =~ ^[Yy]$ ]]; then
  149. rmdir "$TARGET_DIR"
  150. echo -e "${GREEN}✓${NC} Removed directory"
  151. fi
  152. else
  153. echo ""
  154. echo -e "${YELLOW}ℹ${NC} Directory not empty. Remaining files:"
  155. ls -la "$TARGET_DIR"
  156. fi
  157. fi
  158. echo ""
  159. echo -e "${GREEN}✅ Uninstall complete!${NC}"
  160. echo ""
  161. if [ $removed_count -eq 0 ]; then
  162. echo "No OpenCode Agents files were found to remove."
  163. else
  164. echo "Removed $removed_count component(s)."
  165. fi
  166. echo ""
  167. echo "To reinstall, run:"
  168. echo " ./install.sh"
  169. echo ""
  170. exit 0