Skip to content

Commit c43469b

Browse files
committed
modify bash script
1 parent 72563ef commit c43469b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

setup.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,36 @@ executeCommand() {
2020
echo "$result"
2121
}
2222

23-
# Check if Node.js and npm are installed
23+
# Check if Node.js is installed
2424
if ! command -v node &>/dev/null; then
25-
echo -e "${RED}Ensure you have Node.js installed on your system.${RESET}"
25+
echo -e "${RED}Node.js is not installed. Please install Node.js to proceed.${RESET}"
26+
exit 1
27+
fi
28+
29+
# Check if npm is installed
30+
if ! command -v npm &>/dev/null; then
31+
echo -e "${RED}npm is not installed. Please install npm to proceed.${RESET}"
2632
exit 1
2733
fi
2834

2935
# Check if Wrangler is installed
3036
if ! command -v wrangler &>/dev/null; then
3137
echo -e "${YELLOW}Wrangler is not installed. Installing Wrangler...${RESET}"
3238
executeCommand "npm install -g wrangler &>/dev/null"
39+
if [ $? -ne 0 ]; then
40+
echo -e "${YELLOW}Retrying Wrangler installation with sudo...${RESET}"
41+
executeCommand "sudo npm install -g wrangler &>/dev/null"
42+
if [ $? -ne 0 ]; then
43+
echo -e "${RED}Failed to install Wrangler.${RESET}"
44+
exit 1
45+
fi
46+
fi
3347
fi
3448

3549
# Check if the repository is already cloned
3650
REPO_DIR="gradle-mirror-cloudflare-worker"
3751
REPO_URL="https://github.com/ehsannarmani/gradle-mirror-cloudflare-worker"
52+
3853
if [ -d "$REPO_DIR" ]; then
3954
echo -e "${CYAN}Repository already cloned.${RESET}"
4055
else
@@ -50,7 +65,7 @@ fi
5065
cd "$REPO_DIR" || exit
5166

5267
# Check if Wrangler is logged in by running `wrangler whoami`
53-
echo -e "${CYAN}Checking if you are logged in to wrangler...${RESET}"
68+
echo -e "${CYAN}Checking if you are logged in to Wrangler...${RESET}"
5469

5570
whoami_output=$(wrangler whoami 2>&1)
5671

@@ -84,3 +99,7 @@ else
8499
echo -e "${RED}Error: Unable to extract the worker URL from the deployment output.${RESET}"
85100
exit 1
86101
fi
102+
103+
# Cleanup: Delete the repository folder if it was cloned in this session
104+
cd .. || exit
105+
rm -rf "$REPO_DIR"

0 commit comments

Comments
 (0)