-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkage.sh
executable file
·157 lines (116 loc) · 3.35 KB
/
linkage.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
#
# a first cut at a setup script... try to setup
# various files, perms, and ownerships
#
#
# some basic vars
#
dhome="/etc/d3ck"
#
# XXX - should get the next from conf or something
#
# new fangled associative arrays...
declare -A d3ck
declare -A versions
d3ck['nginx']=1.5
d3ck['node']=0.12
#
# This really has to be run as root
#
me=$(whoami | awk '{print $1}')
if [ $me != 'root' ] ; then
echo This must be run as root, not $me, sorry!
exit 2
fi
#
# next, check a few version number minimums....
#
# actual versions
versions['nginx']=$(nginx -v 2>&1 | sed 's@^.*/@@')
versions['node']=$(node --version|sed 's/.//')
# echo nginx min: ${d3ck['nginx']}
# echo node min: ${d3ck['node']}
# weird loopy syntax
for exe in "${!d3ck[@]}" ; do
echo testing $exe, must be version ${d3ck[$exe]} or better
./exe/min_version.sh ${versions[$exe]} ${d3ck[$exe]}
if [ $? != 0 ] ; then
echo -e "\tFailure: ${versions[$exe]} < ${d3ck[$exe]}"
exit 3
else
echo -e "\tSuccess! ${versions[$exe]} >= ${d3ck[$exe]}"
fi
done
#
# start putting things in
#
if [ $(pwd) != $dhome -a ! -s $dhome ] ; then
echo creating symlink in /etc/d3ck to current directory
rm -f /etc/d3ck
ln -s `pwd` /etc/d3ck
fi
echo creating additional symlinks...
#
# test if the last command actually worked
#
live_or_die () {
if [ $? != 0 ] ; then
echo "... failure..."
exit 4
fi
}
#
# check to see if a file/link exists, move it aside, if not, symlink to the target
#
check_n_link() {
file="$1"
target="$2"
if [ -f $file -o -s $file ] ; then
# give me a break, lol
if [ -f $file.$$ -o -s $file.$$ ]; then
echo things are weird... $file.$$ exists... bailing out for safety\!
exit 5
fi
echo moving $file to $file.$$ so we can link to d3ck\'s version
mv $file $file.$$
fi
echo "creating symlink from $file -> $target"
ln -s $target $file
live_or_die
}
# redis has been a bit squirrely with naming... not sure what it is right now ;(
check_n_link /etc/redis/redis.conf /etc/d3ck/redis/redis.conf
check_n_link /etc/init.d/d3ck /etc/d3ck/init.d.d3ck
check_n_link /usr/local/sbin/d3ckd /etc/d3ck/sbin.d3ckd
# check_n_link(/etc/udev/rules.d/10-d3ck-key.rules) tbd
mkdir /etc/d3ck/nginx
mkdir /etc/d3ck/nginx/tmp
mkdir /etc/d3ck/nginx/cache
chown -R nobody /etc/d3ck/nginx
mkdir /etc/d3ck/tmp
mkdir /etc/d3ck/uploads
mkdir /etc/d3ck/logs
mkdir /etc/d3ck/redis
mkdir /etc/d3ck/d3cks
mkdir /etc/d3ck/d3cks/staging
mkdir -p /etc/d3ck/f-u-openssl/clients
chown redis.redis /etc/d3ck/redis
touch /etc/d3ck/logs/client_vpn.log
touch /etc/d3ck/logs/server_vpn.log
chmod 777 /etc/d3ck/logs/client_vpn.log
chmod 777 /etc/d3ck/logs/server_vpn.log
chown -R $me /etc/d3ck
chown -R redis /etc/d3ck/redis
chmod 755 /etc/d3ck
chmod 777 /etc/d3ck/tmp
chmod 777 /etc/d3ck/logs
rm -f /etc/d3ck/logs/*
ln -s /etc/d3ck/redis/redis.conf /etc/redis/redis.conf
ln -s /etc/d3ck/init.d.d3ck /etc/init.d/d3ck
ln -s /etc/d3ck/sbin.d3ckd /usr/local/sbin/d3ckd
ln -s /etc/d3ck/10-d3ck-key.rules /etc/udev/rules.d/10-d3ck-key.rules
# in addition, some don't understand certain conf directives... here's
# an alternate configuration file to use if, when redis starts, it dies
/etc/init.d/*redis* start
cd /etc/d3ck/node_modules; tar xvf ../nx.tar.gz; cd ./exec-sync2; npm install