-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-set
executable file
·52 lines (42 loc) · 1.62 KB
/
docker-set
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
#!/usr/bin/env bash
# user will run: ./docker-set -p <name-of-pre-run-script>
# this script will:
# 1. validate option -p
# 2. script will ask if you want to backup current pre-run file if it exists - if so, what name. save as pre-run/pre-run-<name>
# 3. this script will: find in pre-run/pre-run-<name-of-pre-run-script> and cp to pre-run/pre-run
####
# 1. Validate option -p
# command is: ./docker-set -p <name-of-pre-run-script>
# get the <name-of-pre-run-script> from the command
# store in variable P
while getopts ":hp:" opt; do
case $opt in
h) printf "ℹ️ How to use:\n./docker-set -p <pre-run-script-suffix>\n"
exit 1
;;
p) P="$OPTARG"
;;
\?) printf "============ ❌ Invalid option -$OPTARG\n" >&2
exit 1
;;
esac
done
# if P is empty or the file pre-run/pre-run-$P does not exist - exit
if [ -z "$P" ] || [ ! -f pre-run/pre-run-$P ]; then
printf "============ ❌ pre-run/pre-run-$P does not exist\n"
exit 1
fi
# 2. does pre-run/pre-run exist? do you want to back it up? what name to save as?
if [ -f pre-run/pre-run ]; then
read -p "============ 🤔 Pre-run script detected. Backup pre-run/pre-run? (y/n)" -n 1 -r
printf "\n"
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "============ 🤔 What name to save as? " -r
printf "\n"
cp pre-run/pre-run pre-run/pre-run-$REPLY
printf "============ ✅ pre-run/pre-run saved as pre-run/pre-run-$REPLY\n"
fi
fi
# 3. find in pre-run/pre-run-<name-of-pre-run-script> and cp to pre-run/pre-run
cp pre-run/pre-run-$P pre-run/pre-run
printf "============ ✅ pre-run/pre-run-$P copied to pre-run/pre-run\n"