1 | #!/bin/sh |
---|
2 | # |
---|
3 | # |
---|
4 | # Author: Dennis Stam |
---|
5 | # |
---|
6 | # $Id: cmt_deploy.sh 13322 2011-08-25 09:08:00Z jaap $ |
---|
7 | # $URL: https://subtrac.sara.nl/osd/beowulf/svn/trunk/sara_cmt/bin/cmt_deploy.sh $ |
---|
8 | |
---|
9 | # change te permissions |
---|
10 | perms(){ |
---|
11 | echo "Ensuring correct permissions" |
---|
12 | chmod 0500 "${DESTDIR}/sara_cmt/cmt.py" |
---|
13 | chmod 0600 "${DESTDIR}/sara_cmt/sara_cmt/settings_db.py" |
---|
14 | } |
---|
15 | |
---|
16 | # create an db file when we install for the first time |
---|
17 | create_db_file(){ |
---|
18 | echo "Creating settings_db.py file" |
---|
19 | read -p "Database username, followed by [ENTER]: " db_user |
---|
20 | read -p "Database password, followed by [ENTER]: " db_pass |
---|
21 | |
---|
22 | cat > "${DESTDIR}/sara_cmt/sara_cmt/settings_db.py" <<DELIM |
---|
23 | DATABASES = { |
---|
24 | 'default': { |
---|
25 | 'ENGINE': 'django.db.backends.postgresql_psycopg2', |
---|
26 | 'NAME': 'sara_cmt', |
---|
27 | 'USER': '${db_user}', |
---|
28 | 'PASSWORD': '${db_pass}', |
---|
29 | 'HOST': 'cmt.hpcv.sara.nl' |
---|
30 | } |
---|
31 | } |
---|
32 | DELIM |
---|
33 | |
---|
34 | } |
---|
35 | |
---|
36 | # create a symlink in /usr/sbin |
---|
37 | create_link(){ |
---|
38 | |
---|
39 | if [ ! -e "/usr/sbin/sara_cmt" ] |
---|
40 | then |
---|
41 | ln -s "${DESTDIR}/sara_cmt/cmt.py" /usr/sbin/sara_cmt |
---|
42 | else |
---|
43 | echo "Link/file already exists, skipping create_link step" |
---|
44 | fi |
---|
45 | } |
---|
46 | |
---|
47 | # copy the files to the destination |
---|
48 | copy_files(){ |
---|
49 | echo "Copying files" |
---|
50 | |
---|
51 | if [ -e "${DESTDIR}" ] |
---|
52 | then |
---|
53 | mkdir -p $DESTDIR |
---|
54 | fi |
---|
55 | |
---|
56 | echo "cp -r \"${TMPDIR}/cmt-export\" \"${DESTDIR}/sara_cmt\"" |
---|
57 | cp -r "${TMPDIR}/cmt-export" "${DESTDIR}/sara_cmt" |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | get_files(){ |
---|
62 | # exporting the svn tree |
---|
63 | echo "svn export -r \"${REVISION}\" --username \"${USER}\" \"${SRC_URL}\" ${TMPDIR}/cmt-export" |
---|
64 | svn export -r "${REVISION}" --username "${USER}" "${SRC_URL}" ${TMPDIR}/cmt-export |
---|
65 | |
---|
66 | # Removing the files |
---|
67 | echo "\n data exported from svn, removing server/development specific files:" |
---|
68 | echo " ${TMPDIR}/cmt-export/doc (Available at http://cmt.hpcv.sara.nl/doc/ )" |
---|
69 | echo " ${TMPDIR}/cmt-export/sara_cmt/apache" |
---|
70 | echo " ${TMPDIR}/cmt-export/sara_cmt/api" |
---|
71 | echo " ${TMPDIR}/cmt-export/sara_cmt/log" |
---|
72 | echo " ${TMPDIR}/cmt-export/sara_cmt/fixtures" |
---|
73 | echo " ${TMPDIR}/cmt-export/sara_cmt/cluster/migrations" |
---|
74 | echo "\n again a sleep for 2 sec" |
---|
75 | sleep 3 |
---|
76 | rm -rf "${TMPDIR}/cmt-export/doc" \ |
---|
77 | "${TMPDIR}/cmt-export/sara_cmt/apache" \ |
---|
78 | "${TMPDIR}/cmt-export/sara_cmt/api" \ |
---|
79 | "${TMPDIR}/cmt-export/sara_cmt/log" \ |
---|
80 | "${TMPDIR}/cmt-export/sara_cmt/log" \ |
---|
81 | "${TMPDIR}/cmt-export/sara_cmt/fixtures" \ |
---|
82 | "${TMPDIR}/cmt-export/sara_cmt/cluster/migrations" |
---|
83 | } |
---|
84 | |
---|
85 | set_template_dir(){ |
---|
86 | |
---|
87 | echo "Creating a template dir" |
---|
88 | read -p "Enter your clustername, followed by [ENTER]: " cluster |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | # A very very simple argument parser |
---|
93 | while true |
---|
94 | do |
---|
95 | case "${1}" in |
---|
96 | -d|--destdir) |
---|
97 | OPT_DEST=$2 |
---|
98 | shift 2 |
---|
99 | ;; |
---|
100 | -u|--user) |
---|
101 | OPT_USER=$2 |
---|
102 | shift 2 |
---|
103 | ;; |
---|
104 | -r|--revision) |
---|
105 | OPT_REVISION=$2 |
---|
106 | shift 2 |
---|
107 | ;; |
---|
108 | -u|--url|--src) |
---|
109 | OPT_SRC=$2 |
---|
110 | shift 2 |
---|
111 | ;; |
---|
112 | -t|--tmp) |
---|
113 | OPT_TMP=$2 |
---|
114 | shift 2 |
---|
115 | ;; |
---|
116 | *) |
---|
117 | break |
---|
118 | ;; |
---|
119 | esac |
---|
120 | done |
---|
121 | |
---|
122 | # Store the information we need, if not specified use the default value |
---|
123 | DESTDIR="${OPT_DEST:=/opt}" |
---|
124 | USER="${OPT_USER:=$(whoami)}" |
---|
125 | REVISION="${OPT_REVISION:=5900}" |
---|
126 | TMP_DEFAULT="/tmp/sara_cmt-$(tr -cd 0-9 </dev/urandom | head -c 3)" |
---|
127 | TMPDIR="${OPT_TMP:=$TMP_DEFAULT}" |
---|
128 | SRC_URL=${OPT_SRC:="https://subtrac.sara.nl/osd/beowulf/svn/trunk/sara_cmt"} |
---|
129 | |
---|
130 | # CUA does not have a root login, so when someone is root ask his realname |
---|
131 | if [ -z "${USER}" -o "x${USER}" = "xroot" ] |
---|
132 | then |
---|
133 | echo "You did not specify a username or your username is root!" |
---|
134 | read -p "Your CUA username, followed by [ENTER]: " USER |
---|
135 | fi |
---|
136 | |
---|
137 | # Create the tmpdir |
---|
138 | if [ ! -e "${TMPDIR}" ] |
---|
139 | then |
---|
140 | mkdir $TMPDIR |
---|
141 | fi |
---|
142 | |
---|
143 | ## Some information |
---|
144 | echo "Using the following information:" |
---|
145 | echo " Source : ${SRC_URL}" |
---|
146 | echo " Revision : ${REVISION}" |
---|
147 | echo " Destination : ${DESTDIR}" |
---|
148 | echo " CUA username : ${USER}" |
---|
149 | echo " TMP destination : ${TMPDIR}" |
---|
150 | echo "\n sleeping for 2 sec to allow you to read the above information!" |
---|
151 | sleep 2 |
---|
152 | |
---|
153 | # Check if we already have an installation |
---|
154 | if [ -e "${DESTDIR}/sara_cmt/revision" ] |
---|
155 | then |
---|
156 | |
---|
157 | if [ "$(cat ${DESTDIR}/sara_cmt/revision)" = "${REVISION}" ] |
---|
158 | then |
---|
159 | echo "You already have the 'latest' version" |
---|
160 | else |
---|
161 | echo "You already have sara_cmt, backing up some files:" |
---|
162 | echo " ${DESTDIR}/sara_cmt/sara_cmt/settings.py" |
---|
163 | echo " ${DESTDIR}/sara_cmt/sara_cmt/settings_db.py" |
---|
164 | cp "${DESTDIR}/sara_cmt/sara_cmt/settings.py" "${DESTDIR}/sara_cmt/sara_cmt/settings_db.py" "${TMPDIR}/" |
---|
165 | rm -rf "${DESTDIR}/sara_cmt" |
---|
166 | get_files |
---|
167 | copy_files |
---|
168 | cp "${TMPDIR}/settings.py" "${TMPDIR}/settings_db.py" "${DESTDIR}/sara_cmt/sara_cmt/" |
---|
169 | perms |
---|
170 | create_link |
---|
171 | echo "${REVISION}" > "${DESTDIR}/sara_cmt/revision" |
---|
172 | fi |
---|
173 | else |
---|
174 | get_files |
---|
175 | copy_files |
---|
176 | create_db_file |
---|
177 | perms |
---|
178 | create_link |
---|
179 | |
---|
180 | echo "Please adjust settings.py in ${DESTDIR}/sara_cmt/sara_cmt to the correct template directory" |
---|
181 | |
---|
182 | echo "${REVISION}" > "${DESTDIR}/sara_cmt/revision" |
---|
183 | fi |
---|
184 | |
---|
185 | ## Cleaning up |
---|
186 | rm -rf $TMPDIR |
---|
187 | |
---|
188 | |
---|