-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap-bash
More file actions
executable file
·74 lines (64 loc) · 1.66 KB
/
Copy pathbootstrap-bash
File metadata and controls
executable file
·74 lines (64 loc) · 1.66 KB
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
69
70
71
72
73
74
#!/bin/bash
# Configuration
###############
# Functions
###########
function show_help {
echo "Create a new bash script from a template"
echo "Usage: $0 [options] [filename]"
echo "Options:"
echo -e "-h\tShow this help"
}
# Ask a question, defaults to yes
function yes_no_question () {
read -r -p "$1 [Y/n] " response
response=${response,,}
if [[ "$response" =~ ^(yes|y|)$ ]]; then
return 0
else
return 1
fi
}
# Ask a question, defaults to no
function no_yes_question () {
read -r -p "$1 [Y/n] " response
response=${response,,}
if [[ "$response" =~ ^(no|n|)$ ]]; then
return 0
else
return 1
fi
}
# Useful Variables
##################
# Directory containing this script
# (no matter where it is called from)
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
script_dir="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# Script
########
new_script_name="$1"
# Read Command Line Arguments
while getopts "h" opt; do
case "$opt" in
h)
show_help
exit 0
;;
esac
done
# Verify Parameters
if [ -z "$new_script_name" ]
then
echo -e "Path for new script:"
read new_script_name
fi
# Copy Template to New File
echo -e "Generating new script in $new_script_name..."
eval "cp $script_dir/bootstrap/bash $new_script_name"
eval "chmod +x $new_script_name"