Merge pull request #3679 from Raven24/grimreaper-develop

Remove non-portable bashisms from most of the scripts. ++
This commit is contained in:
Jonne Haß 2012-11-10 09:06:23 -08:00
commit 8b89a5ca00
6 changed files with 154 additions and 73 deletions

14
.rvmrc
View file

@ -1,19 +1,19 @@
#!/bin/bash #!/bin/sh
source ./script/env/ruby_env . ./script/env/ruby_env
if [ -e '.rvmrc.local' ]; then if [ -e '.rvmrc.local' ]; then
source .rvmrc.local; . .rvmrc.local;
elif [ -e '.rvmrc_custom' ] ; then elif [ -e '.rvmrc_custom' ] ; then
source .rvmrc_custom; . .rvmrc_custom;
else else
if rvm list strings | grep -q "$ruby_version" ; then if rvm list strings | grep -q "$ruby_version" ; then
rvm --create use "$ruby_version@$gemset" rvm --create use "$ruby_version@$gemset"
else else
echo -e "\e[00;31mPLEASE INSTALL RUBY $ruby_version WITH \`rvm install $ruby_version\`" printf "\e[00;31mPLEASE INSTALL RUBY $ruby_version WITH \`rvm install $ruby_version\`"
echo -e "Don't forget to run \`cd .. && cd -\` afterwards!\e[00m" printf "Don't forget to run \`cd .. && cd -\` afterwards!\e[00m"
return 1 return 1
fi fi
fi fi
source ./script/env/ensure_right_rubygems . ./script/env/ensure_right_rubygems

View file

@ -16,6 +16,7 @@
* MessagesController. [#3657](https://github.com/diaspora/diaspora/pull/3657) * MessagesController. [#3657](https://github.com/diaspora/diaspora/pull/3657)
* **Fixed setting:** `follow_diasporahq` has now to be set to `true` to enable following the DiasporaHQ account. Was `false` * **Fixed setting:** `follow_diasporahq` has now to be set to `true` to enable following the DiasporaHQ account. Was `false`
* Removal of some bash-/linux-isms from most of the scripts, rework of 'script/install.sh' output methods. [#3679](https://github.com/diaspora/diaspora/pull/3679)
## Features ## Features

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/sh
# Ensure known RubyGems version # Ensure known RubyGems version
envdir="$(readlink -e $(dirname $0))/../env" envdir="$(readlink -e $(dirname $0))/../env"
source "$envdir/ruby_env" . "$envdir/ruby_env"
source "$envdir/ensure_right_rubygems" . "$envdir/ensure_right_rubygems"

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# Create a database.yml for the right database # Create a database.yml for the right database

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
### ###
# MAKE ME BETTER # MAKE ME BETTER
@ -68,6 +68,7 @@ D_RUBY_VERSION="1.9.3-p194"
RVM_DETECTED=false RVM_DETECTED=false
JS_RUNTIME_DETECTED=false JS_RUNTIME_DETECTED=false
ONE_UP="\e[1A"
#### #### #### ####
# # # #
@ -84,11 +85,61 @@ JS_RUNTIME_DETECTED=false
# EOF # EOF
define(){ IFS='\n' read -r -d '' ${1}; } define(){ IFS='\n' read -r -d '' ${1}; }
# expand aliases in this script # add padding to the left of a given string to
shopt -s expand_aliases # fill to a given amount of characters with a
# given char or space
# example:
# lpad 7 "test" "-"
lpad() {
LEN=$1
TXT=$2
CHR=$3
PAD=""
# alias echo to alway print \newlines L_PAD=$(($LEN - ${#TXT}))
alias echo='echo -e' if [ $L_PAD -ne 0 ] ; then
PAD=$(printf "%*s" ${L_PAD} " ")
fi
if [ ${#CHR} -ne 0 ] ; then
PAD=$(printf "$PAD" | tr " " "$CHR")
fi
PAD="${PAD}${TXT}"
printf "%s" "$PAD"
}
# log function
# prints a given message with the given log level to STDOUT
logf() {
MSG=$1
LVL=$2
L_LEN=7
if [ ${#LVL} -ne 0 ] ; then
LVL="[$(lpad $(($L_LEN-2)) $LVL " ")]"
else
LVL=$(lpad $L_LEN "" "-")
fi
printf "%s -- %s\\n" "$LVL" "$MSG"
}
# short functions for various log levels
log_err() {
logf "$1" "error"
}
log_wrn() {
logf "$1" "warn"
}
log_dbg() {
logf "$1" "debug"
}
log_inf() {
logf "$1" "info"
}
# run a command or print the error # run a command or print the error
run_or_error() { run_or_error() {
@ -100,11 +151,9 @@ run_or_error() {
# nicely output error messages and quit # nicely output error messages and quit
error() { error() {
echo "\n" log_err "$1"
echo "[ERROR] -- $1" logf "have a look at our wiki: $D_WIKI_URL"
echo " --" logf "or join us on IRC: $D_IRC_URL"
echo " -- have a look at our wiki: $D_WIKI_URL"
echo " -- or join us on IRC: $D_IRC_URL"
exit 1 exit 1
} }
@ -118,7 +167,7 @@ interactive_check() {
fd=0 #stdin fd=0 #stdin
if [[ -t "$fd" || -p /dev/stdin ]]; then if [[ -t "$fd" || -p /dev/stdin ]]; then
# all is well # all is well
echo "" printf "\n"
else else
# non-interactive # non-interactive
TMPFILE=`mktemp` TMPFILE=`mktemp`
@ -134,13 +183,18 @@ interactive_check() {
# check if all necessary binaries are available # check if all necessary binaries are available
binaries_check() { binaries_check() {
for exe in "${!BINARIES[@]}"; do for exe in "${!BINARIES[@]}"; do
echo -n "checking for $exe... " LOG_MSG="checking for $exe... "
which "${BINARIES[$exe]}" log_inf "$LOG_MSG"
EXE_PATH=$(which "${BINARIES[$exe]}")
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
error "you are missing the '${BINARIES[$exe]}' command, please install '$exe'"; error "you are missing the '${BINARIES[$exe]}' command, please install '$exe'";
else
printf "$ONE_UP"
log_inf "$LOG_MSG found"
fi fi
done done
echo "" printf "\n"
} }
# check for rvm # check for rvm
@ -152,28 +206,31 @@ to install, manage and work with multiple ruby environments.
For more details check out https://rvm.io// For more details check out https://rvm.io//
EOT EOT
rvm_check() { rvm_check() {
echo -n "checking for rvm... " LOG_MSG="checking for rvm... "
log_inf "$LOG_MSG"
fn_exists rvm fn_exists rvm
if [ $? -eq 0 ] ; then if [ $? -eq 0 ] ; then
RVM_DETECTED=true RVM_DETECTED=true
# seems we don't have it loaded, try to do so # seems we don't have it loaded, try to do so
elif [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then elif [ -s "$HOME/.rvm/scripts/rvm" ] ; then
source "$HOME/.rvm/scripts/rvm" >/dev/null 2>&1 source "$HOME/.rvm/scripts/rvm" >/dev/null 2>&1
RVM_DETECTED=true RVM_DETECTED=true
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
source "/usr/local/rvm/scripts/rvm" >/dev/null 2>&1 source "/usr/local/rvm/scripts/rvm" >/dev/null 2>&1
RVM_DETECTED=true RVM_DETECTED=true
fi fi
if $RVM_DETECTED ; then if $RVM_DETECTED ; then
echo "found" printf "$ONE_UP"
log_inf "$LOG_MSG found"
else else
echo "not found" log_wrn "not found"
echo "$RVM_MSG" logf "$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 fi
echo "" printf "\n"
} }
# prepare ruby with rvm # prepare ruby with rvm
@ -183,16 +240,19 @@ install_or_use_ruby() {
fi fi
# make sure we have the correct ruby version available # make sure we have the correct ruby version available
echo -n "checking your ruby version... " LOG_MSG="checking your ruby version... "
log_inf "$LOG_MSG"
rvm use $D_RUBY_VERSION >/dev/null 2>&1 rvm use $D_RUBY_VERSION >/dev/null 2>&1
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "not ok" log_wrn "not ok"
rvm --force install $D_RUBY_VERSION rvm --force install $D_RUBY_VERSION
else else
echo "ok" printf "$ONE_UP"
log_inf "$LOG_MSG ok"
fi fi
echo "" printf "\n"
} }
# trust and load rvmrc # trust and load rvmrc
@ -209,15 +269,18 @@ load_rvmrc() {
fi fi
# load .rvmrc # load .rvmrc
echo -n "loading .rvmrc ... " LOG_MSG="loading .rvmrc ... "
source ".rvmrc" log_inf "$LOG_MSG"
. ".rvmrc"
#rvm rvmrc load #rvm rvmrc load
if [ $? -eq 0 ] ; then if [ $? -eq 0 ] ; then
echo "ok" printf "$ONE_UP"
log_inf "$LOG_MSG ok"
else else
echo "not ok" log_wrn "not ok"
fi fi
echo "" printf "\n"
} }
# rvm doesn't need sudo, otherwise we do have to use it :( # rvm doesn't need sudo, otherwise we do have to use it :(
@ -227,7 +290,7 @@ rvm_or_sudo() {
else else
eval "$1" eval "$1"
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "\nrunning '$1' didn't succeed, trying again with sudo...\n" log_wrn "running '$1' didn't succeed, trying again with sudo..."
run_or_error "sudo $1" run_or_error "sudo $1"
fi fi
fi fi
@ -246,7 +309,8 @@ For more information on ExecJS, visit
-- https://github.com/sstephenson/execjs -- https://github.com/sstephenson/execjs
EOT EOT
js_runtime_check() { js_runtime_check() {
echo -n "checking for a JavaScript runtime... " LOG_MSG="checking for a JavaScript runtime... "
log_inf "$LOG_MSG"
# Node.js # Node.js
which node >/dev/null 2>&1 which node >/dev/null 2>&1
@ -255,7 +319,7 @@ js_runtime_check() {
fi fi
# TheRubyRacer # TheRubyRacer
(echo "require 'v8'" | ruby) >/dev/null 2>&1 (printf "require 'v8'" | ruby) >/dev/null 2>&1
if [ $? -eq 0 ] ; then if [ $? -eq 0 ] ; then
JS_RUNTIME_DETECTED=true JS_RUNTIME_DETECTED=true
fi fi
@ -265,13 +329,14 @@ js_runtime_check() {
## ##
if $JS_RUNTIME_DETECTED ; then if $JS_RUNTIME_DETECTED ; then
echo "ok" printf "$ONE_UP"
log_inf "$LOG_MSG found"
else else
echo "not ok" log_err "not ok"
echo "$JS_RT_MSG" printf "$JS_RT_MSG"
error "can't continue without a JS runtime" error "can't continue without a JS runtime"
fi fi
echo "" printf "\n"
} }
# make ourselves comfy # make ourselves comfy
@ -280,6 +345,7 @@ prepare_install_env() {
load_rvmrc load_rvmrc
js_runtime_check js_runtime_check
log_inf "making sure the 'bundler' gem is installed"
rvm_or_sudo "gem install bundler" rvm_or_sudo "gem install bundler"
} }
@ -291,30 +357,30 @@ sane_environment_check() {
# find or set up a working git environment # find or set up a working git environment
git_stuff_check() { git_stuff_check() {
echo "Where would you like to put the git clone, or, where is your existing git clone?" printf "Where would you like to put the git clone, or, where is your existing git clone?\n"
echo "(please use a full path, not '~' or '.')" printf "(please use a full path, not '~' or '.')\n"
read -e -p "-> " D_GIT_CLONE_PATH read -e -p "-> " D_GIT_CLONE_PATH
echo "" printf "\n"
test -d "$D_GIT_CLONE_PATH" \ test -d "$D_GIT_CLONE_PATH" \
&& cd "$D_GIT_CLONE_PATH" \ && cd "$D_GIT_CLONE_PATH" \
&& git status # folder exists? go there. is a good git clone? && git status # folder exists? go there. is a good git clone?
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# not a git repo, create it? # not a git repo, create it?
echo "the folder you specified does not exist or doesn't contain a git repo" printf "the folder you specified does not exist or doesn't contain a git repo\n"
read -p "Press [Enter] to create it... " read -p "Press [Enter] to create it and contine... "
run_or_error "mkdir -p -v \"$D_GIT_CLONE_PATH\"" # only if it doesn't exist 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\"" run_or_error "git clone \"$D_REMOTE_REPO_URL\" \"$D_GIT_CLONE_PATH\""
else else
run_or_error "git checkout master" run_or_error "git checkout master"
run_or_error "git pull" run_or_error "git pull"
fi fi
echo "" printf "\n"
} }
# handle database decision # handle database decision
database_question() { database_question() {
echo "Which database type are you using?" printf "Which database type are you using? [1|2]\n"
select choice in "MySQL" "PgSQL"; do select choice in "MySQL" "PgSQL"; do
case $choice in case $choice in
MySQL ) MySQL )
@ -335,31 +401,42 @@ database_question() {
# ask for database credentials # ask for database credentials
database_credentials() { database_credentials() {
read -e -p "hostname: " D_DB_HOST read -e -p "DB hostname: " D_DB_HOST
read -e -p "username: " D_DB_USER read -e -p "DB username: " D_DB_USER
read -e -p "password: " D_DB_PASS read -e -p "DB password: " D_DB_PASS
run_or_error "sed -i'' -e \"s/\(host:\)[^\n]*/\1 $D_DB_HOST/g\" \"$D_DB_CONFIG_FILE\"" run_or_error "sed -i'' -e \"s/\(host:\)[^\n]*/\1 $D_DB_HOST/g\" \"$D_DB_CONFIG_FILE\""
run_or_error "sed -i'' -e \"s/\(username:\)[^\n]*/\1 $D_DB_USER/g\" \"$D_DB_CONFIG_FILE\"" run_or_error "sed -i'' -e \"s/\(username:\)[^\n]*/\1 $D_DB_USER/g\" \"$D_DB_CONFIG_FILE\""
run_or_error "sed -i'' -e \"s/\(password:\)[^\n]*/\1 $D_DB_PASS/g\" \"$D_DB_CONFIG_FILE\"" run_or_error "sed -i'' -e \"s/\(password:\)[^\n]*/\1 $D_DB_PASS/g\" \"$D_DB_CONFIG_FILE\""
printf "\n"
} }
# setup database # setup database
# (assume we are in the Diaspora directory) # (assume we are in the Diaspora directory)
define DATABASE_CHK_MSG << 'EOT'
you can now check the generated database config file in './config/database.yml'
and see if the specified values are correct.
EOT
database_setup() { database_setup() {
echo "Database setup" log_inf "Database setup"
run_or_error "cp config/database.yml.example \"$D_DB_CONFIG_FILE\"" run_or_error "cp config/database.yml.example \"$D_DB_CONFIG_FILE\""
database_question database_question
database_credentials database_credentials
echo ""
printf "$DATABASE_CHK_MSG"
read -p "Press [Enter] to continue... "
printf "\n"
} }
# install all the gems with bundler # install all the gems with bundler
# (assume we are in the Diaspora directory) # (assume we are in the Diaspora directory)
prepare_gem_bundle() { prepare_gem_bundle() {
echo "installing all required gems..." log_inf "installing all required gems..."
rvm_or_sudo "bundle install" rvm_or_sudo "bundle install"
echo "" printf "\n"
} }
@ -390,7 +467,7 @@ Follow the guide in our wiki, instead:
##################################################################### #####################################################################
EOT EOT
echo "$WELCOME_MSG" printf "$WELCOME_MSG"
read -p "Press [Enter] to continue... " read -p "Press [Enter] to continue... "
@ -411,18 +488,19 @@ prepare_install_env
database_setup database_setup
echo "copying diaspora.yml.example to diaspora.yml" # diaspora config
log_inf "copying diaspora.yml.example to diaspora.yml"
run_or_error "cp config/diaspora.yml.example config/diaspora.yml" run_or_error "cp config/diaspora.yml.example config/diaspora.yml"
echo "" printf "\n"
# bundle gems # bundle gems
prepare_gem_bundle prepare_gem_bundle
echo "creating the default database specified in config/database.yml. please wait..." log_inf "creating the default database specified in config/database.yml. please wait..."
run_or_error "bundle exec rake db:schema:load_if_ruby --trace" run_or_error "bundle exec rake db:schema:load_if_ruby --trace"
echo "" printf "\n"
define GOODBYE_MSG <<EOT define GOODBYE_MSG <<EOT
##################################################################### #####################################################################
@ -444,7 +522,7 @@ For further information read the wiki at $D_WIKI_URL
or join us on IRC $D_IRC_URL or join us on IRC $D_IRC_URL
EOT EOT
echo "$GOODBYE_MSG" printf "$GOODBYE_MSG"
exit 0 exit 0

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# Copyright (c) 2010-2011, Diaspora Inc. This file is # Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
@ -27,7 +27,8 @@ fi
# Setup environment # Setup environment
if [ -z "$RAILS_ENV" ]; then if [ -z "$RAILS_ENV" ]; then
export RAILS_ENV=$(bundle exec ruby ./script/get_config.rb server.rails_environment) RAILS_ENV=$(bundle exec ruby ./script/get_config.rb server.rails_environment)
export RAILS_ENV
fi fi
os=`uname -s` os=`uname -s`
@ -40,7 +41,8 @@ eval $(bundle exec ruby ./script/get_config.rb \
) )
if [ -z "$DB" ]; then if [ -z "$DB" ]; then
export DB=$db DB=$db
export DB
fi fi
if [ "$single_process_mode" = "true" -o "$embed_resque_worker" = "true" ]; then if [ "$single_process_mode" = "true" -o "$embed_resque_worker" = "true" ]; then
@ -56,7 +58,7 @@ do
done done
# Check if already running/port blocked # Check if already running/port blocked
function chk_service chk_service()
{ {
port=${1:?Missing port} port=${1:?Missing port}
case $os in case $os in
@ -92,7 +94,7 @@ if [ ! -e public/source.tar.gz ]; then
fi fi
# Check if assets are precompiled # Check if assets are precompiled
if [ "$RAILS_ENV" == 'production' ]; then if [ "$RAILS_ENV" = 'production' ]; then
if [ ! -e 'public/assets/default.css' ]; then if [ ! -e 'public/assets/default.css' ]; then
echo "FATAL: You're running in production mode without having assets precompiled." >&2 echo "FATAL: You're running in production mode without having assets precompiled." >&2
echo "Now and after each update before you restart the application, run:" >&2 echo "Now and after each update before you restart the application, run:" >&2