-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.sh
executable file
·68 lines (60 loc) · 1.61 KB
/
new.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
if [ "$(id -u)" -ne 0 ]; then
echo "Please run as root." >&2
exit 1
fi
export $(grep -v '^#' .env | xargs)
while getopts 'n:p:l:h' opt; do
case "$opt" in
n)
arg="$OPTARG"
NAME=${OPTARG}
;;
p)
arg="$OPTARG"
PORT=${OPTARG}
;;
l)
arg="$OPTARG"
PROJECTLOCATON=${OPTARG}
;;
? | h)
echo "Usage: $(basename $0) [-n name] [-p port] [-l path to project] [-h]"
exit 1
;;
esac
done
#shift "$(($OPTIND -1))"
# If port is in use, then bail out.
if lsof -i:$PORT | grep -q 'COMMAND'; then
echo "Port ${PORT} is in use. See here:"
lsof -i:$PORT
exit 1
fi
# If name is in use by Docker, then bail out.
if docker ps -a -f name=$NAME | grep -q "${NAME}"; then
echo "Name ('${NAME}') is already in use."
exit 1
fi
# ensure project location path is not already in use.
if [ -d ${PROJECTLOCATON}/${NAME} ]; then
echo "Location exists - ${PROJECTLOCATON}/${NAME}"
exit 1
fi
THEUSER="x"
if [ "$(id -u)" -ne 0 ]; then THEUSER=$USER; else THEUSER=$SUDO_USER; fi
# Do the things.
echo "Doing the things"
mkdir -p ${PROJECTLOCATON}/${NAME}
mkdir -p ${PROJECTLOCATON}/${NAME}/appdata
currentuser=$(who | awk 'NR==1{print $1}')
echo "#!/bin/sh\n\nssh -p ${PORT} james@localhost" >>$PROJECTLOCATON/$NAME/$NAME
chmod +x ${PROJECTLOCATON}/${NAME}/${NAME}
chown -R ${currentuser} ${PROJECTLOCATON}/${NAME}
ln ${PROJECTLOCATON}/${NAME}/${NAME} /usr/local/bin/${NAME}
cp ./docker-compose.yml ${PROJECTLOCATON}/${NAME}/
cp ./.env ${PROJECTLOCATON}/${NAME}/
cd ${PROJECTLOCATON}/${NAME}
echo "APPNAME=${NAME}" >>${PROJECTLOCATON}/${NAME}/.env
echo "PORT=${PORT}" >>${PROJECTLOCATON}/${NAME}/.env
docker compose -p ${NAME} up -d