-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_pysite.sh
executable file
·195 lines (170 loc) · 5.54 KB
/
deploy_pysite.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
# ensure that exceptions are treated as such and program exists!
set -e
# =================================================
# = deploy_pysite version 0.1.0
# =
# = Created by Gezim Hoxha
# = License: GPL 2
# =
# = If you're using virtualenv, this script will
# = install PIP packages and even build
# = build packages from source then install
# = them into your virtual environment.
# = See SETTINGS section for instructions.
# =
# = July, 2010
# =
# = TO DO
# = -
# =================================================
# = REQUIRES
# = bash >=3.1
# = curl
# = pip
# =================================================
usage="
USAGE: \n
Modify nonpip_packages and pip_packages according to your needs. These can be found in the source
of this script in SETTINGS section.\n
Once SETTINGS have been modified, activate your virtual environment, then call this script. \n
If you're not using virtualenvwrapper, set VIRTUAL_ENV environment variable
to your virtual environemt directory. \n
\n
Also, you may want to ensure that the download dir is set to where you want it in SETTINGS section.
"
# ensure we're in a virtual environment
if [[ "$VIRTUAL_ENV" = "" ]]
then
echo -e $usage
exit 5
fi
# =================================================
# ====================SETTINGS=====================
# =================================================
# Directory to store source archives
dg_downloads_dir="$HOME/downloads"
# Add/remove non-pip packages you [don't] want to install here.
# IMPORTANT: Only .tar.gz packages are supported.
#
# You must add a package URL and function pair to nonpip_packages array.
# If no custom install is required (i.e. normal ./config, make, make install will do) leave
# function call empty. For example:
# "http://www.example.com/pack.tar.gz" ""
# If you need custom install calls, create a function that makes those calls in CUSTOM FUNCTIONS
# area below. The function calls can include arguments.
# For example:
# "http://www.example.com/pack02.tar.gz" "install_pack02"
# Or with a function call argument:
# "http://www.example.com/pack04.tar.gz" "install_package four"
#
# MAKE SURE YOU USE QUOTES.
#
nonpip_packages=(
"http://oligarchy.co.uk/xapian/1.0.21/xapian-core-1.0.21.tar.gz"
""
"http://oligarchy.co.uk/xapian/1.0.21/xapian-bindings-1.0.21.tar.gz"
"function_xapian_bindings"
)
# Add/remove pip packages you [don't] want to install here.
# Version is included to ensure you get the same packages
# whenever you install.
# Example:
# "django" "1.2.1"
#
# MAKE SURE YOU USE QUOTES.
#
pip_packages=(
"django" "1.2.1"
"django-haystack" "1.0.1-final"
"xapian-haystack" "1.1.3beta"
"MySQL-python" "1.2.3c1"
)
# =================================================
# =================CUSTOM FUNCTIONS================
# You should use variables such as $VIRTUAL_ENV.
# =================================================
function_xapian_bindings()
{
./configure --with-python XAPIAN_CONFIG="$VIRTUAL_ENV/bin/xapian-config" --prefix="$VIRTUAL_ENV"
make
make install
}
# =================================================
# ====================REAL CODE====================
# ===Don't touch unless you are sure you need to.==
# =================================================
# =================================================
# Create the downloads dir.
# Nothing will happen if it already exists.
mkdir -p "$dg_downloads_dir"
temp_file="/tmp/$(basename $0).$$.tmp"
# Build and install non-pip packages
build_install()
{
for ((i=0; i<${#nonpip_packages[@]}; i+=2))
do
#pip_install "${pip_packages[i]}" "${pip_packages[i+1]}"
#get package name
package_name="${nonpip_packages[i]##*/}"
package_dir="${package_name%.tar.gz}"
echo "Installing $package_name to $VIRTUAL_ENV with..."
cd "$dg_downloads_dir"
# Check if directory exists.
# -d test doesn't work on case insensitive FS's (e.g. OS X)
if (cd "$package_dir" 2>/dev/null)
then
cd "$package_dir"
elif [ -f "$package_name" ]
then
# if package is already downloaded
tar xzf "$package_name"
cd "$package_dir"
else
curl -sS "${nonpip_packages[i]}" -O > /dev/null
tar xzf "$package_name"
cd "$package_dir"
fi
# if odd array index has no function, do a standard make
# Otherwise, run custom function.
custom_function=${nonpip_packages[i+1]}
if [[ "$custom_function" = "" ]]
then
set -x
./configure --prefix="$VIRTUAL_ENV" >>"$temp_file" 2>&1
make >>"$temp_file" 2>&1
make install >>"$temp_file" 2>&1
set +x
else
set -x
"$custom_function" >>"$temp_file" 2>&1
set +x
fi
echo "...done."
done
}
# Install pip packages
# param: $1 is the package name
# param: $2 is the package version
# The package version is required
# to ensure the exact setup is installed everytime.
pip_install()
{
if (( $# != 2 ))
then
echo "pip_install requires 2 arguments."
return 25
fi
echo "Installing $1 to $VIRTUAL_ENV with..."
set -x
pip install "$1"=="$2" >>"$temp_file" 2>&1
set +x
echo "...done."
}
# Now install the packages if they're enabled.
build_install
for ((i=0; i<${#pip_packages[@]}; i+=2))
do
pip_install "${pip_packages[i]}" "${pip_packages[i+1]}"
done
echo -e "\nInstall was successful. See $temp_file for details."