-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx-configurator
executable file
·60 lines (48 loc) · 1.37 KB
/
nginx-configurator
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
#!/bin/bash
# Nginx-configurator
# Tool for fast managing nginx configs
case $1 in
reg)
if [ -z "$2" ]; then
echo "Error: No FILE argument supplied"
exit 1
fi
if ! [ -f $2 ]; then
echo "Error: FILE does not exist"
exit 1
fi
real="`pwd $2`/`basename $2`"
alias="/etc/nginx/conf.d/`basename $real`.conf"
if [ -f $alias ]; then
echo "Error: Cannot register FILE, because alias already exist: $alias"
exit 1
fi
cmd="sudo ln -s $real $alias"
echo $cmd
`$cmd`
;;
unreg)
if [ -z "$2" ]; then
echo "Error: No ALIAS argument supplied"
exit 1
fi
alias="/etc/nginx/conf.d/$2.conf"
if ! [ -f $alias ]; then
echo "Error: No config with specified alias"
exit 1
fi
cmd="sudo rm $alias"
echo $cmd
`$cmd`
;;
list)
ls -lh /etc/nginx/conf.d/ | sed "1 d" | awk '{print $9 " " $10 " " $11}'
;;
*)
echo 'Usage:'
echo 'nginx-configurator reg FILE Register FILE in /etc/nginx/conf.d/*'
echo 'nginx-configurator unreg ALIAS Unregister ALIAS-configuration'
echo 'nginx-configurator list List all registered configs'
;;
esac
exit 0