install script improvements [ci skip]
This commit is contained in:
parent
87ceabc0ba
commit
3ff94b0312
1 changed files with 49 additions and 37 deletions
|
|
@ -75,6 +75,14 @@ shopt -s expand_aliases
|
||||||
# alias echo to alway print \newlines
|
# alias echo to alway print \newlines
|
||||||
alias echo='echo -e'
|
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
|
# nicely output error messages and quit
|
||||||
error() {
|
error() {
|
||||||
echo "\n"
|
echo "\n"
|
||||||
|
|
@ -87,28 +95,28 @@ error() {
|
||||||
|
|
||||||
# shell interactive or not
|
# shell interactive or not
|
||||||
interactive_check() {
|
interactive_check() {
|
||||||
case $- in
|
fd=0 #stdin
|
||||||
*i*) # interactive
|
if [[ -t "$fd" || -p /dev/stdin ]]; then
|
||||||
# all is well, continue
|
# all is well
|
||||||
;;
|
echo ""
|
||||||
*) # non-interactive
|
else
|
||||||
TMPFILE='mktemp'
|
# non-interactive
|
||||||
curl -s -o "$TMPFILE" "$D_INSTALL_SCRIPT_URL"
|
TMPFILE='mktemp'
|
||||||
chmod +x "$TMPFILE"
|
curl -s -o "$TMPFILE" "$D_INSTALL_SCRIPT_URL"
|
||||||
exec 0< /dev/tty
|
chmod +x "$TMPFILE"
|
||||||
bash -i "$TMPFILE"
|
exec 0< /dev/tty
|
||||||
rm "$TMPFILE"
|
bash -i "$TMPFILE"
|
||||||
exit 0
|
rm "$TMPFILE"
|
||||||
;;
|
exit 0
|
||||||
esac
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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... "
|
echo -n "checking for $exe... "
|
||||||
which "$exe"
|
which "$exe"
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
error "you are missing $exe";
|
error "you are missing $exe";
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
@ -124,11 +132,14 @@ 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 "checking for rvm..."
|
echo -n "checking for rvm... "
|
||||||
rvm >/dev/null 2>&1
|
rvm >/dev/null 2>&1
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "found"
|
||||||
|
else
|
||||||
|
echo "not found"
|
||||||
echo "$RVM_MSG"
|
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
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
@ -141,23 +152,23 @@ 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?"
|
echo "Where would you like to put the git clone, or, where is your existing git clone?"
|
||||||
echo "(or, where is your existing git clone)?"
|
echo "(please use a full path, not '~' or '.')"
|
||||||
read -e -p "-> " D_GIT_CLONE_PATH
|
read -e -p "-> " D_GIT_CLONE_PATH
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
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 [ $? -gt 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
mkdir "$D_GIT_CLONE_PATH" # only if it doesn't exist
|
|
||||||
# not a git repo, create it?
|
# 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... "
|
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
|
else
|
||||||
git checkout master
|
run_or_error "git checkout master"
|
||||||
git pull
|
run_or_error "git pull"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
@ -175,8 +186,8 @@ database_question() {
|
||||||
PgSQL )
|
PgSQL )
|
||||||
D_DB="postgres"
|
D_DB="postgres"
|
||||||
# replace default with postgres
|
# replace default with postgres
|
||||||
sed -i'' -r 's/(<<: \*mysql)/#\1/g' $D_DB_CONFIG_FILE
|
run_or_error "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/(#(<<: \*postgres))/\2/g' \"$D_DB_CONFIG_FILE\""
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -189,16 +200,16 @@ database_credentials() {
|
||||||
read -e -p "username: " D_DB_USER
|
read -e -p "username: " D_DB_USER
|
||||||
read -e -p "password: " D_DB_PASS
|
read -e -p "password: " D_DB_PASS
|
||||||
|
|
||||||
sed -i'' -r "s/(host:)[^\n]*/\1 $D_DB_HOST/g" $D_DB_CONFIG_FILE
|
run_or_error "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
|
run_or_error "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/(password:)[^\n]*/\1 $D_DB_PASS/g\" \"$D_DB_CONFIG_FILE\""
|
||||||
}
|
}
|
||||||
|
|
||||||
# setup database
|
# setup database
|
||||||
# (assume we are in the Diaspora directory)
|
# (assume we are in the Diaspora directory)
|
||||||
database_setup() {
|
database_setup() {
|
||||||
echo "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_question
|
||||||
database_credentials
|
database_credentials
|
||||||
echo ""
|
echo ""
|
||||||
|
|
@ -238,7 +249,7 @@ git_stuff_check
|
||||||
|
|
||||||
|
|
||||||
# goto working directory
|
# goto working directory
|
||||||
cd "$D_GIT_CLONE_PATH"
|
run_or_error "cd \"$D_GIT_CLONE_PATH\""
|
||||||
|
|
||||||
|
|
||||||
# configure database setup
|
# configure database setup
|
||||||
|
|
@ -246,15 +257,16 @@ database_setup
|
||||||
|
|
||||||
|
|
||||||
echo "copying application.yml.example to application.yml"
|
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 ""
|
||||||
|
|
||||||
echo "bundling..."
|
echo "bundling..."
|
||||||
bundle install
|
run_or_error "bundle install"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo "creating and migrating default database in config/database.yml. please wait..."
|
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 ""
|
echo ""
|
||||||
|
|
||||||
define GOODBYE_MSG <<'EOT'
|
define GOODBYE_MSG <<'EOT'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue