Samrand 1 год назад
Родитель
Сommit
4046bac79f
1 измененных файлов с 48 добавлено и 19 удалено
  1. 48 19
      easy-install.sh

+ 48 - 19
easy-install.sh

@@ -1,52 +1,81 @@
 #!/bin/bash
 
 # Check if Docker is installed
-if ! [ -x "$(command -v docker)" ]; then
+if ! command -v docker &>/dev/null; then
   read -p "Docker is not installed. Do you want to install Docker? (Y/n): " INSTALL_DOCKER
-  if [ ${INSTALL_DOCKER:-Y} == "Y" ]; then
-    sudo su -c "bash <(wget -qO- https://get.docker.com)" root
-    apt install -y docker-compose
+  if [[ "${INSTALL_DOCKER:-Y}" =~ ^[Yy]$ ]]; then
+    curl -fsSL https://get.docker.com | sudo bash
+    if ! command -v docker &>/dev/null; then
+      echo "Docker installation failed. Exiting."
+      exit 1
+    fi
+    # Install Docker Compose
+    sudo apt update && sudo apt install -y docker-compose
+    if ! command -v docker-compose &>/dev/null; then
+      echo "Docker Compose installation failed. Exiting."
+      exit 1
+    fi
   else
     echo "Exiting setup. Docker installation required."
     exit 1
   fi
 fi
 
-# Continue with the rest of the script...
+# Clone the Git repository only if it doesn't already exist
+REPO_NAME="v2ray-nginx-cloudflare"
+REPO_URL="https://github.com/samrand96/v2ray-nginx-cloudflare.git"
 
+if [ -d "$REPO_NAME" ]; then
+  echo "Repository $REPO_NAME already exists. Skipping cloning."
+else
+  if ! git clone "$REPO_URL"; then
+    echo "Failed to clone the repository. Exiting."
+    exit 1
+  fi
+fi
 
-# Clone the git repository
-git clone https://github.com/samrandhaji/v2ray-nginx-cloudflare.git
-cd v2ray-nginx-cloudflare
+# Navigate to the repository directory
+cd "$REPO_NAME" || { echo "Failed to navigate to the repository directory. Exiting."; exit 1; }
 
 # Generate random UUID
 read -p "Do you want to use a custom UUID? (Y/n): " CUSTOM_UUID
-if [ ${CUSTOM_UUID:-Y} == "Y" ]; then
+if [[ "${CUSTOM_UUID:-Y}" =~ ^[Yy]$ ]]; then
   read -p "Enter your custom UUID: " UUID
+  UUID=${UUID:-$(cat /proc/sys/kernel/random/uuid)}
 else
   UUID=$(cat /proc/sys/kernel/random/uuid)
 fi
 
-
 # Update the <UPSTREAM-UUID> field in config.json
-sed -i "s#<UPSTREAM-UUID>#$UUID#g" ./v2ray/config/config.json
+if ! sed -i "s#<UPSTREAM-UUID>#$UUID#g" ./v2ray/config/config.json; then
+  echo "Failed to update UUID in config.json. Exiting."
+  exit 1
+fi
 
 # Prompt for domain and email
 read -p "Enter your domain: " DOMAIN
 read -p "Enter your email: " EMAIL
 
 # Replace placeholders in docker-compose.yml
-sed -i "s#YOUR_DOMAIN#$DOMAIN#g" ./docker-compose.yml
-sed -i "s#YOUR_EMAIL#$EMAIL#g" ./docker-compose.yml
+if ! sed -i "s#YOUR_DOMAIN#$DOMAIN#g" ./docker-compose.yml || ! sed -i "s#YOUR_EMAIL#$EMAIL#g" ./docker-compose.yml; then
+  echo "Failed to update placeholders in docker-compose.yml. Exiting."
+  exit 1
+fi
 
 # Compose the Docker setup
-docker-compose up -d
+if ! docker-compose up -d; then
+  echo "Failed to start Docker containers. Exiting."
+  exit 1
+fi
 
 # Prompt for CDN usage
-read -p "Now go and adjust CDN Settings: In your CDN, activate the proxy option for the record to enhance the delivery capabilities. When you finished press Enter " USE_CDN
-if [ ${USE_CDN:-Y} == "Y" ]; then
-  # Turn on proxy mode in A record inside the CDN
-  # Run the vmess.py file
+read -p "Now go and adjust CDN settings. Activate the proxy option in your CDN for the record to enhance delivery capabilities. Press Enter when finished." USE_CDN
+if [[ "${USE_CDN:-Y}" =~ ^[Yy]$ ]]; then
   chmod +x vmess.py
-  ./vmess.py
+  if ! ./vmess.py; then
+    echo "Failed to execute vmess.py. Exiting."
+    exit 1
+  fi
 fi
+
+echo "Setup completed successfully."