forked from backlogs/redmine_backlogs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbl-setup
executable file
·185 lines (154 loc) · 5.7 KB
/
rbl-setup
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
#!/bin/bash
set -e
function errmsg {
echo "$1"
exit 1
}
function removegem {
REMGEM=`gem list | grep "$1.*$2" | wc -l`
if [[ \"$REMGEM\" != \"0\" ]]; then
gem uninstall $1 -v=$2
fi
}
command -v ruby >/dev/null 2>&1 || errmsg "no ruby available"
RUBYVER=`ruby --version | awk '{print $2}' | awk -F. '{print $1 "." $2}'`
export RVM="yes"
command -v rvm >/dev/null 2>&1 || export RVM="no"
while getopts "hp:igdc:" OPT; do
case $OPT in
h) print_usage 0;;
p) PLATFORM="$OPTARG";;
i) INSTALL="yes";;
g) GEMS="yes";;
d) DATABASE="yes";;
c) BACKLOGS_CONFIG="$OPTARG";;
w) WORKSPACE="$OPTARG";;
[?]) print_usage 1;;
esac
done
if [ -z "$BACKLOGS_CONFIG" ]; then
BACKLOGS_CONFIG="$HOME/.backlogs.rc"
fi
if [ ! -f $BACKLOGS_CONFIG ]; then
errmsg "$BACKLOGS_CONFIG does not exist"
fi
source $BACKLOGS_CONFIG
if [ -z "$PLATFORM" -a "$RVM" = "yes" ]; then
PLATFORM=`rvm-prompt g | sed -e 's/@//'`
fi
if [ -z "$PLATFORM" ]; then
errmsg "no platform selected"
fi
case $PLATFORM in
redmine) VERSION=1.4.2;;
chiliproject) VERSION=3.1.0;;
*) errmsg "Unsupported platform '$PLATFORM'";;
esac
if [ "$DATABASE" = "yes" ]; then
if [ -z "$DBROOTPW" ]; then
errmsg "No DB root password set"
fi
if [ -z "$DBUSERPW" ]; then
errmsg "No DB user password set"
fi
if [ -z "$DBUSER" ]; then
DBUSER=$PLATFORM
fi
fi
if [ -z "$WORKSPACE" ]; then
WORKSPACE="$HOME/redmine"
fi
if [ ! -e $WORKSPACE ]; then
errmsg "$WORKSPACE does not exist"
fi
echo Workspace: $WORKSPACE
echo Config: $BACKLOGS_CONFIG
echo Install: $INSTALL
echo Gems: $GEMS
echo Database: $DATABASE
if [ "$INSTALL" = "yes" ]; then
if [ ! -e "$WORKSPACE/$PLATFORM-$RUBYVER" ]; then
mkdir "$WORKSPACE/$PLATFORM-$RUBYVER"
fi
if [ ! -f "$WORKSPACE/$PLATFORM-$RUBYVER/database.yml" -a ! -f "$WORKSPACE/setup/$PLATFORM-$RUBYVER/database.yml" ] ; then
errmsg "$WORKSPACE/setup/$PLATFORM-$RUBYVER/database.yml not found"
fi
fi
export RAILS_ENV=development
cd "$WORKSPACE"
if [ "$INSTALL" = "yes" ] ; then
rm -rf "$WORKSPACE/$PLATFORM-$RUBYVER"
case $PLATFORM in
redmine)
svn co "http://redmine.rubyforge.org/svn/tags/$VERSION" "redmine-$RUBYVER"
;;
chiliproject)
git clone http://github.com/chiliproject/chiliproject.git "chiliproject-$RUBYVER"
cd "$WORKSPACE/chiliproject-$RUBYVER"
git fetch --tags
git checkout "v$VERSION"
;;
esac
cd "$WORKSPACE/$PLATFORM-$RUBYVER"
ln -s "$WORKSPACE/redmine_backlogs" "$WORKSPACE/$PLATFORM-$RUBYVER/vendor/plugins"
ln -s "$WORKSPACE/redmine_backlogs/features" "$WORKSPACE/$PLATFORM-$RUBYVER"
cp "$WORKSPACE/setup/$PLATFORM-$RUBYVER/database.yml" "$WORKSPACE/$PLATFORM-$RUBYVER/config/database.yml"
echo rvm use `ruby --version | awk '{print $2}' | sed -e 's/p.*//'`@$PLATFORM > "$WORKSPACE/$PLATFORM-$RUBYVER/.rvmrc"
sed -i -e"s/gem 'capybara'/gem 'capybara', '~>1.1.0'/" Gemfile
fi
if [ "$RVM" = "yes" -a "$GEMS" = "yes" ] ; then
rvm --force gemset empty $PLATFORM
case $RUBYVER in
1.8) rvm rubygems 1.6.2;; # removes annoying "Gem.source_index is deprecated, use Specification." warnings
1.9) rvm rubygems latest-1.8;;
esac
fi
if [ "$GEMS" = "yes" ]; then
cd "$WORKSPACE/$PLATFORM-$RUBYVER"
touch "$WORKSPACE/$PLATFORM-$RUBYVER/backlogs.dev"
gem install bundler
bundle install --system
#bundle install --path=vendor/bundle
DUPLICATES=`gem list | grep -v '^rake ' | grep -v '^rack ' | grep -v '^bundler' | grep , | wc -l`
if [[ \"$DUPLICATES\" != \"0\" ]]; then
echo 'Duplicate gems! Aborting installation'
gem list | grep ,
exit
fi
fi
if [ "$DATABASE" = "yes" ] ; then
cd "$WORKSPACE/$PLATFORM-$RUBYVER"
DBINSTALLED=`echo show databases | mysql -u root -p$DBROOTPW | grep $PLATFORM | wc -l`
if [[ "$DBINSTALLED" != "0" ]]; then
mysqladmin -f -u root -p$DBROOTPW drop $PLATFORM
fi
echo "create database $PLATFORM character set utf8;" | mysql -u root -p$DBROOTPW mysql
DBUSEREXISTS=`echo "select concat(User, '@', Host) from mysql.user;" | mysql -u root -p$DBROOTPW | grep "$DBUSER@localhost" | wc -l`
if [[ "$DBUSEREXISTS" = "0" ]]; then
echo "create user '$DBUSER'@'localhost' identified by '$DBUSERPW';" mysql -u root -p$DBROOTPW mysql
echo "create user '$DBUSER'@'localhost' identified by '$DBUSERPW';" | mysql -u root -p$DBROOTPW mysql
fi
echo "grant all privileges on $PLATFORM.* to '$DBUSER'@'%';" | mysql -u root -p$DBROOTPW mysql
echo "grant all privileges on $PLATFORM.* to 'root'@'%';" | mysql -u root -p$DBROOTPW mysql
if [ -f "$WORKSPACE/setup/$PLATFORM.sql.gz" ]; then
zcat "$WORKSPACE/setup/$PLATFORM.sql.gz" | mysql -u root -p$DBROOTPW $PLATFORM
echo "update users set auth_source_id = NULL;" | mysql -u root -p$DBROOTPW $PLATFORM
fi
bundle exec rake $TRACE db:migrate
bundle exec rake $TRACE generate_session_store
if [ ! -f "$WORKSPACE/setup/$PLATFORM.sql.gz" ]; then
REDMINE_LANG=en bundle exec rake $TRACE redmine:load_default_data
fi
bundle exec rake $TRACE db:migrate:plugins
bundle exec rake $TRACE redmine:backlogs:prepare_fixtures
labels=no story_trackers=Story task_tracker=Task bundle exec rake $TRACE redmine:backlogs:install
fi
# if Options.adminpw.to_s != ''
# script.database "cd ~/redmine/#{Options.platform}"
# script.database "./script/runner \"User.find(:all).reject{|user| user.login.to_s == ''}.each{|user| user.password, user.password_confirmation = '#{Options.adminpw}'; user.auth_source = nil; user.save!; puts '** password for ' + user.login + ' set to #{Options.adminpw}'}\""
if [ "$INSTALL" = "yes" ] ; then
command -v bundle >/dev/null 2>&1 || errmsg "Please set up gem environment first"
cd "$WORKSPACE/$PLATFORM-$RUBYVER"
./script/generate cucumber --skip --spork
rake redmine:backlogs:prepare_fixtures
fi