Skip to content

Commit 71bd0e0

Browse files
committed
Add feature to put the script in path for easy execution
1 parent 5b89c53 commit 71bd0e0

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

deploy.sh

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#!/usr/bin/env bash
2-
## ./deploy.sh
3-
## Deploys a web app to given SERVERS
2+
## Deploys a web app to given servers. Check out
3+
## This script is designed for Debian-based systems. Support for other distros will be added later.
44
## Copyright (C) 2025 Buffer Park. All rights reserved.
55
## MIT License
66

7-
set -e
8-
trap 'echo -e "\n${BRed}Error: An error occurred during deployment. Please check your inputs and try again.${Color_Off}"' ERR
9-
107
SOURCE="${BASH_SOURCE[0]}"
118
while [ -L "$SOURCE" ]; do
129
DIR="$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)"
@@ -16,8 +13,32 @@ done
1613
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)"
1714
source "$SCRIPT_DIR/awesome.conf" # For colors and Usage message
1815

19-
cd ..
16+
set -e
17+
trap 'echo -e "\n${BRed}Error: An error occurred during deployment. Please check your inputs and try again.${Color_Off}"' ERR
2018

19+
SCRIPT_PATH="$DIR/$(basename "$SOURCE")"
20+
IN_PATH=false
21+
IFS=':' read -ra PATH_DIRS <<< "$PATH"
22+
for dir in "${PATH_DIRS[@]}"; do
23+
if [[ "$SCRIPT_PATH" == "$dir/"* ]]; then
24+
IN_PATH=true
25+
break
26+
fi
27+
done
28+
29+
if ! $IN_PATH && [[ ! -f /usr/local/bin/deploy && ! -L /usr/local/bin/deploy ]]; then
30+
echo "Warning: Script is not in your \$PATH. Adding it will allow you to run it from anywhere."
31+
read -p "Do you want to add it to your \$PATH? (y/n) " answer
32+
if [[ "$answer" == "y" || "$answer" == "Y" ]]; then
33+
echo "Adding script to your \$PATH..."
34+
sudo ln -s "$SCRIPT_PATH" /usr/local/bin/deploy
35+
echo -e "Script added to your \$PATH. You can now run it from anywhere with the command:${BCyan} deploy [options] ${Color_Off}\n"
36+
else
37+
echo "Script not added to your \$PATH. You can run it using the full path: $SCRIPT_PATH"
38+
fi
39+
fi
40+
41+
cd ..
2142
for i in "$@"; do
2243
if [[ $i =~ ^--config= ]]; then
2344
config="${i#*=}"
@@ -63,7 +84,7 @@ for i in "$@"; do
6384
SETUP_COMMAND=""
6485
if ! [[ "$NUMBER" =~ ^[0-9]+$ ]]; then
6586
echo -e "${BRed}Error: Invalid number of commands '$NUMBER'. Please provide a number.${Color_Off}"
66-
exit 1
87+
exit 1O
6788
fi
6889
for ((i=1; i<=NUMBER; i++)); do
6990
printf "${BCyan}Enter command $i: ${Color_Off}"
@@ -105,8 +126,8 @@ done
105126
KEEP=${KEEP:-5}
106127

107128
if [ -z "$PROJECT_NAME" ]; then
108-
echo -e "${BYellow}WARNING: PROJECT_NAME is not set in your environment. Falling back to user input. ${Color_Off}\n"
109-
echo -e "${BCyan}What is your project name?${Color_Off}"
129+
echo -e "${BYellow}WARNING: PROJECT_NAME is not set in your config. Falling back to user input. ${Color_Off}\n"
130+
echo -e "${BCyan}What is your project's name?${Color_Off}"
110131
read -r PROJECT_NAME
111132
if [ -z "$PROJECT_NAME" ]; then
112133
echo -e "${BRed}Error: No project name provided. Exiting...${Color_Off}"
@@ -224,7 +245,7 @@ echo -e "Deployment will commence in 10 seconds. Check if you entered correct in
224245

225246
spinner="/|\\-/"
226247
for ((j=10; j>0; j--)); do
227-
echo -ne "${Yellow}Starting deployment in $j seconds... ${spinner:$((j%4)):1} \r"
248+
echo -ne "${Yellow}\tStarting deployment in $j seconds... ${spinner:$((j%4)):1} \r"
228249
sleep 1
229250
done
230251
echo -e "\n"

0 commit comments

Comments
 (0)