install script improvements [ci skip]

This commit is contained in:
Florian Staudacher 2012-04-25 15:12:04 +02:00
parent 87ceabc0ba
commit 3ff94b0312

View file

@ -75,6 +75,14 @@ shopt -s expand_aliases
# alias echo to alway print \newlines
alias echo='echo -e'
# run a command or print the error
run_or_error() {
eval "$1"
if [ $? -ne 0 ]; then
error "executing '$1' failed."
fi
}
# nicely output error messages and quit
error() {
echo "\n"
@ -87,20 +95,20 @@ error() {
# shell interactive or not
interactive_check() {
case $- in
*i*) # interactive
# all is well, continue
;;
*) # non-interactive
TMPFILE='mktemp'
curl -s -o "$TMPFILE" "$D_INSTALL_SCRIPT_URL"
chmod +x "$TMPFILE"
exec 0< /dev/tty
bash -i "$TMPFILE"
rm "$TMPFILE"
exit 0
;;
esac
fd=0 #stdin
if [[ -t "$fd" || -p /dev/stdin ]]; then
# all is well
echo ""
else
# non-interactive
TMPFILE='mktemp'
curl -s -o "$TMPFILE" "$D_INSTALL_SCRIPT_URL"
chmod +x "$TMPFILE"
exec 0< /dev/tty
bash -i "$TMPFILE"
rm "$TMPFILE"
exit 0
fi
}
# check if all necessary binaries are available
@ -108,7 +116,7 @@ binaries_check() {
for exe in $BINARIES; do
echo -n "checking for $exe... "
which "$exe"
if [ $? -gt 0 ]; then
if [ $? -ne 0 ]; then
error "you are missing $exe";
fi
done
@ -124,11 +132,14 @@ to install, manage and work with multiple ruby environments.
For more details check out https://rvm.io//
EOT
rvm_check() {
echo "checking for rvm..."
echo -n "checking for rvm... "
rvm >/dev/null 2>&1
if [ $? -gt 0 ]; then
if [ $? -eq 0 ]; then
echo "found"
else
echo "not found"
echo "$RVM_MSG"
read -p "Press [Enter] to continue without RVM or abort this script and install RVM"
read -p "Press [Enter] to continue without RVM or abort this script and install RVM..."
fi
echo ""
}
@ -141,23 +152,23 @@ sane_environment_check() {
# find or set up a working git environment
git_stuff_check() {
echo "Where would you like to put the git clone?"
echo "(or, where is your existing git clone)?"
echo "Where would you like to put the git clone, or, where is your existing git clone?"
echo "(please use a full path, not '~' or '.')"
read -e -p "-> " D_GIT_CLONE_PATH
echo ""
test -d "$D_GIT_CLONE_PATH" \
&& cd "$D_GIT_CLONE_PATH" \
&& git status # folder exists? go there. is a good git clone?
if [ $? -gt 0 ]; then
mkdir "$D_GIT_CLONE_PATH" # only if it doesn't exist
if [ $? -ne 0 ]; then
# not a git repo, create it?
echo "the folder you specified does not contain a git repo"
echo "the folder you specified does not exist or doesn't contain a git repo"
read -p "Press [Enter] to create it... "
git clone "$D_REMOTE_REPO_URL" "$D_GIT_CLONE_PATH"
run_or_error "mkdir -p -v \"$D_GIT_CLONE_PATH\"" # only if it doesn't exist
run_or_error "git clone \"$D_REMOTE_REPO_URL\" \"$D_GIT_CLONE_PATH\""
else
git checkout master
git pull
run_or_error "git checkout master"
run_or_error "git pull"
fi
echo ""
}
@ -175,8 +186,8 @@ database_question() {
PgSQL )
D_DB="postgres"
# replace default with postgres
sed -i'' -r 's/(<<: \*mysql)/#\1/g' $D_DB_CONFIG_FILE
sed -i'' -r 's/(#(<<: \*postgres))/\2/g' $D_DB_CONFIG_FILE
run_or_error "sed -i'' -r 's/(<<: \*mysql)/#\1/g' \"$D_DB_CONFIG_FILE\""
run_or_error "sed -i'' -r 's/(#(<<: \*postgres))/\2/g' \"$D_DB_CONFIG_FILE\""
break
;;
esac
@ -189,16 +200,16 @@ database_credentials() {
read -e -p "username: " D_DB_USER
read -e -p "password: " D_DB_PASS
sed -i'' -r "s/(host:)[^\n]*/\1 $D_DB_HOST/g" $D_DB_CONFIG_FILE
sed -i'' -r "s/(username:)[^\n]*/\1 $D_DB_USER/g" $D_DB_CONFIG_FILE
sed -i'' -r "s/(password:)[^\n]*/\1 $D_DB_PASS/g" $D_DB_CONFIG_FILE
run_or_error "sed -i'' -r \"s/(host:)[^\n]*/\1 $D_DB_HOST/g\" \"$D_DB_CONFIG_FILE\""
run_or_error "sed -i'' -r \"s/(username:)[^\n]*/\1 $D_DB_USER/g\" \"$D_DB_CONFIG_FILE\""
run_or_error "sed -i'' -r \"s/(password:)[^\n]*/\1 $D_DB_PASS/g\" \"$D_DB_CONFIG_FILE\""
}
# setup database
# (assume we are in the Diaspora directory)
database_setup() {
echo "Database setup"
cp config/database.yml.example config/database.yml
run_or_error "cp config/database.yml.example \"$D_DB_CONFIG_FILE\""
database_question
database_credentials
echo ""
@ -238,7 +249,7 @@ git_stuff_check
# goto working directory
cd "$D_GIT_CLONE_PATH"
run_or_error "cd \"$D_GIT_CLONE_PATH\""
# configure database setup
@ -246,15 +257,16 @@ database_setup
echo "copying application.yml.example to application.yml"
cp config/application.yml.example config/application.yml
run_or_error "cp config/application.yml.example config/application.yml"
echo ""
echo "bundling..."
bundle install
run_or_error "bundle install"
echo ""
echo "creating and migrating default database in config/database.yml. please wait..."
rake db:create db:migrate --trace
run_or_error "rake db:create db:migrate --trace"
# I think we could use 'rake db:setup' here...
echo ""
define GOODBYE_MSG <<'EOT'