diff options
author | Jonne Haß <me@jhass.eu> | 2015-05-02 16:14:25 +0300 |
---|---|---|
committer | Jonne Haß <me@jhass.eu> | 2015-05-02 16:14:51 +0300 |
commit | 5371c3876f20f184faec7da3b31a6e28888feda8 (patch) | |
tree | a7b82211a91d3085c51dcb20ba3a6bb126751fe8 /script | |
parent | 2382f9eb24e5ce7ea5d703331688c7d272c64e40 (diff) | |
parent | a4210cd501be7f29392566d3e0920edeca4541ac (diff) |
Merge pull request #5907 from pravi/add-x-permissions-to-scripts
add execution permission to scripts
Diffstat (limited to 'script')
-rwxr-xr-x | script/install.sh | 123 | ||||
-rw-r--r-- | script/install/defaults | 51 | ||||
-rw-r--r-- | script/install/functions | 272 | ||||
-rw-r--r-- | script/install/path_sanitizer | 40 | ||||
-rw-r--r-- | script/install/remote_var_reader | 13 | ||||
-rw-r--r-- | script/install/setup | 177 |
6 files changed, 0 insertions, 676 deletions
diff --git a/script/install.sh b/script/install.sh deleted file mode 100755 index d44d6dec1..000000000 --- a/script/install.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env bash - -#### #### -# # -# minimal required functions to load the rest... # -# # -#### #### - - -# ... let's hope nobody hijacks githubs DNS while this runs :P -D_REMOTE_BASE_URL="https://raw.github.com/diaspora/diaspora/develop/" - -# ruby environment -D_REMOTE_ENV_PATH="script/env/ruby_env" - -# installer files -D_INSTALL_SCRIPT="script/install.sh" -D_INSTALL_DEFAULTS_PATH="script/install/defaults" -D_INSTALL_REMOTE_VAR_READER_PATH="script/install/remote_var_reader" -D_INSTALL_PATH_SANITIZER_PATH="script/install/path_sanitizer" -D_INSTALL_FUNCTIONS_PATH="script/install/functions" -D_INSTALL_SETUP_PATH="script/install/setup" - -# fetch a remote script containing functions and eval them into the local env -include_remote() { - _remote_include=$1 - __TMP=$(curl -L $_remote_include) - eval "$__TMP" -} - - -include_remote "$D_REMOTE_BASE_URL$D_INSTALL_DEFAULTS_PATH" -include_remote "$D_REMOTE_BASE_URL$D_INSTALL_REMOTE_VAR_READER_PATH" -include_remote "$D_REMOTE_BASE_URL$D_INSTALL_PATH_SANITIZER_PATH" -include_remote "$D_REMOTE_BASE_URL$D_INSTALL_FUNCTIONS_PATH" -include_remote "$D_REMOTE_BASE_URL$D_INSTALL_SETUP_PATH" - -read_var_remote "ruby_version" "D_RUBY_VERSION" - - -#### #### -# # -# define some overly long message strings here... # -# # -#### #### - -define RVM_MSG <<'EOT' -RVM was not found on your system (or it isn't working properly). -It is higly recommended to use it, since it's making it extremely easy -to install, manage and work with multiple ruby environments. - -For more details check out https://rvm.io// -EOT - - -define JS_RT_MSG <<'EOT' -This script was unable to find a JavaScript runtime compatible to ExecJS on -your system. We recommend you install either Node.js or TheRubyRacer, since -those have been proven to work. - -Node.js -- http://nodejs.org/ -TheRubyRacer -- https://github.com/cowboyd/therubyracer - -For more information on ExecJS, visit --- https://github.com/sstephenson/execjs -EOT - -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. - -Please make sure the database server is started and the credentials you -specified are working. This script will populate the database in a later step. - -EOT - -define WELCOME_MSG <<'EOT' -##################################################################### - -DIASPORA* INSTALL SCRIPT - ----- - -This script will guide you through the basic steps -to get a DEVELOPMENT setup of Diaspora* up and running - -For a PRODUCTION installation, please do *not* use this script! -Follow the guide in our wiki, instead: --- http://wiki.diasporafoundation.org/Installation_guides - -##################################################################### - -EOT - -define GOODBYE_MSG <<EOT -##################################################################### - -It worked! :) - -Now, you should have a look at - - - config/database.yml and - - config/diaspora.yml - -and change them to your liking. Then you should be able to -start Diaspora* in development mode with: - - \`rails s\` - - -For further information read the wiki at $D_WIKI_URL -or join us on IRC $D_IRC_URL - -EOT - - -#### #### -# # -# do it! # -# # -#### #### - -diaspora_setup diff --git a/script/install/defaults b/script/install/defaults deleted file mode 100644 index e00ec7cac..000000000 --- a/script/install/defaults +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env bash -# to be included by install.sh - - -#### #### -# # -# DEFAULT VARS # -# # -#### #### - -# list of required programs -declare -A BINARIES -BINARIES["git"]="git" -BINARIES["ruby"]="ruby" -BINARIES["rubygems"]="gem" -BINARIES["bundler"]="bundle" -BINARIES["sed"]="sed" -BINARIES["mktemp"]="mktemp" -BINARIES["dirname"]="dirname" -BINARIES["basename"]="basename" -BINARIES["realpath"]="realpath" - -# local path for git clone, can be changed by the user interactively -D_GIT_CLONE_PATH="/srv/diaspora" -D_GIT_BRANCH="develop" - -# a few important web addresses -D_REMOTE_REPO_URL="https://github.com/diaspora/diaspora.git" -D_WIKI_URL="http://wiki.diasporafoundation.org" - -# irc url -D_IRC_URL="irc://freenode.net/diaspora" - -# database config, can be changed by the user interactively -D_DB_CONFIG_FILE="config/database.yml" -D_DB="mysql" -D_DB_HOST="localhost" -D_DB_USER="diaspora" -D_DB_PASS="diaspora" - - -#### #### -# # -# INTERNAL VARS # -# # -#### #### - -D_INSTALL_SCRIPT_URL="$D_REMOTE_BASE_URL$D_INSTALL_SCRIPT" -RVM_DETECTED=false -JS_RUNTIME_DETECTED=false -ONE_UP="\e[1A" diff --git a/script/install/functions b/script/install/functions deleted file mode 100644 index 2b0ba7987..000000000 --- a/script/install/functions +++ /dev/null @@ -1,272 +0,0 @@ -#!/usr/bin/env bash -# to be included by install.sh - - -#### #### -# # -# FUNCTIONS, etc. # -# # -#### #### - - -# heredoc for variables - very readable, http://stackoverflow.com/a/8088167 -# use like this: -# define VAR <<'EOF' -# somecontent -# EOF -define(){ IFS='\n' read -r -d '' ${1}; } - - -# add padding to the left of a given string to -# 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="" - - L_PAD=$(($LEN - ${#TXT})) - 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_or_error() { - eval "$1" - if [ $? -ne 0 ]; then - error "executing '$1' failed." - fi -} - -# nicely output error messages and quit -error() { - log_err "$1" - logf "have a look at our wiki: $D_WIKI_URL" - logf "or join us on IRC: $D_IRC_URL" - exit 1 -} - - -# check for functions -fn_exists() { - type -t $1 | grep -q 'function' -} - - -# shell interactive or not -interactive_check() { - fd=0 #stdin - if [[ -t "$fd" || -p /dev/stdin ]]; then - # all is well - printf "\n" - 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 this script is run as root -root_check() { - if [ `id -u` -eq 0 ] ; then - error "don't run this script as root!" - fi -} - - -# check if all necessary binaries are available -binaries_check() { - for exe in "${!BINARIES[@]}"; do - LOG_MSG="checking for $exe... " - log_inf "$LOG_MSG" - - EXE_PATH=$(which "${BINARIES[$exe]}") - if [ $? -ne 0 ]; then - error "you are missing the '${BINARIES[$exe]}' command, please install '$exe'"; - else - printf "$ONE_UP" - log_inf "$LOG_MSG found" - fi - done - printf "\n" -} - - -# check for rvm -rvm_check() { - LOG_MSG="checking for rvm... " - log_inf "$LOG_MSG" - - fn_exists rvm - if [ $? -eq 0 ] ; then - RVM_DETECTED=true - - # seems we don't have it loaded, try to do so - elif [ -s "$HOME/.rvm/scripts/rvm" ] ; then - source "$HOME/.rvm/scripts/rvm" >/dev/null 2>&1 - RVM_DETECTED=true - elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then - source "/usr/local/rvm/scripts/rvm" >/dev/null 2>&1 - RVM_DETECTED=true - fi - - if $RVM_DETECTED ; then - printf "$ONE_UP" - log_inf "$LOG_MSG found" - else - log_wrn "not found" - logf "$RVM_MSG" - read -p "Press [Enter] to continue without RVM or abort this script and install RVM..." - fi - printf "\n" -} - - -# prepare ruby with rvm -install_or_use_ruby() { - if ! $RVM_DETECTED ; then - return - fi - - # make sure we have the correct ruby version available - LOG_MSG="checking your ruby version... " - log_inf "$LOG_MSG" - - rvm use $D_RUBY_VERSION >/dev/null 2>&1 - if [ $? -ne 0 ] ; then - log_wrn "not ok" - rvm --force install $D_RUBY_VERSION - else - printf "$ONE_UP" - log_inf "$LOG_MSG ok" - fi - - printf "\n" -} - - -# trust and load rvmrc -# do this in a directory that has a .rvmrc, only :) -load_rvmrc() { - if ! $RVM_DETECTED || [[ ! -s ".rvmrc" ]] ; then - return - fi - - # trust rvmrc - rvm rvmrc is_trusted - if [ $? -ne 0 ] ; then - rvm rvmrc trust - fi - - # load .rvmrc - LOG_MSG="loading .rvmrc ... " - log_inf "$LOG_MSG" - - . ".rvmrc" - #rvm rvmrc load - if [ $? -eq 0 ] ; then - printf "$ONE_UP" - log_inf "$LOG_MSG ok" - else - log_wrn "not ok" - fi - printf "\n" -} - - -# rvm doesn't need sudo, otherwise we do have to use it :( -rvm_or_sudo() { - if $RVM_DETECTED ; then - run_or_error "$1" - else - eval "$1" - if [ $? -ne 0 ] ; then - log_wrn "running '$1' didn't succeed, trying again with sudo..." - run_or_error "sudo $1" - fi - fi -} - - -# we need a valid js runtime... -js_runtime_check() { - LOG_MSG="checking for a JavaScript runtime... " - log_inf "$LOG_MSG" - - # Node.js - which node >/dev/null 2>&1 - if [ $? -eq 0 ] ; then - JS_RUNTIME_DETECTED=true - fi - - # TheRubyRacer - (printf "require 'v8'" | ruby) >/dev/null 2>&1 - if [ $? -eq 0 ] ; then - JS_RUNTIME_DETECTED=true - fi - - ## - # add a check for your favourite js runtime here... - ## - - if $JS_RUNTIME_DETECTED ; then - printf "$ONE_UP" - log_inf "$LOG_MSG found" - else - log_err "not ok" - printf "$JS_RT_MSG" - error "can't continue without a JS runtime" - fi - printf "\n" -} diff --git a/script/install/path_sanitizer b/script/install/path_sanitizer deleted file mode 100644 index e847b1680..000000000 --- a/script/install/path_sanitizer +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -# to be included by install.sh - -# Deconstruct a given path string, applies bash expansion and remove all -# remaining relative fragments (e.g. "." or ".."). -# Writes the result in the two given variable names, first is the portion -# with the existing path and the second contains the structure relative to the -# existing path, that'd have to be created. -# usage: -# sanitize_path "~/some/path/string" "EXISTING_VAR_NAME" "REL_NEW_PATH_NAME" -sanitize_path() { - # apply bash expansion - eval _path=$1 - - _existing_path_var=$2 - _rel_new_segment_var=$3 - - _new_segment="" - _chk=1 - _test_cmd='test -d "$_path" -a -n "$_path"' - - $(eval $_test_cmd) && _chk=0 - - while [ $_chk -ne 0 ] ; do - # path doesn't exist, split it up - _segment="$(basename $_path)/$_segment" - _path="$(dirname $_path)" - - $(eval $_test_cmd) && _chk=0 - done - - # remove relative fragments - _path="$(realpath $_path)/" - - log_dbg "pt1 - existing path: $_path" - log_dbg "pt2 - new path: $_segment" - - eval "$_existing_path_var=\"$_path\"" - eval "$_rel_new_segment_var=\"$_segment\"" -} diff --git a/script/install/remote_var_reader b/script/install/remote_var_reader deleted file mode 100644 index 76e1226a9..000000000 --- a/script/install/remote_var_reader +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# to be included by install.sh - -# read a variable defined in the remote repository -# usage: -# read_remote_var "name_in_remote_script" "name_we_want_locally" -read_var_remote() { - _remote_name=$1 - _local_name=$2 - _remote_source="$D_REMOTE_BASE_URL$D_REMOTE_ENV_PATH" - - eval "$_local_name=\"$(include_remote $_remote_source; echo ${!_remote_name})\"" -} diff --git a/script/install/setup b/script/install/setup deleted file mode 100644 index 586e7a0f0..000000000 --- a/script/install/setup +++ /dev/null @@ -1,177 +0,0 @@ -#!/usr/bin/env bash -# to be included by install.sh - - -#### #### -# # -# DIASPORA* development setup # -# # -#### #### - - -# make ourselves comfy -prepare_install_env() { - install_or_use_ruby - load_rvmrc - js_runtime_check - - log_inf "making sure the 'bundler' gem is installed" - rvm_or_sudo "gem install bundler" -} - - -# do some sanity checking -sane_environment_check() { - binaries_check - rvm_check -} - - -# find or set up a working git environment -git_stuff_check() { - printf "Where would you like to put the git clone, or, where is your existing git clone?\n" - #printf "(please use a full path, not '~' or '.')\n" - read -e -p "-> " D_GIT_CLONE_PATH - printf "\n" - - sanitize_path "$D_GIT_CLONE_PATH" "_D_GCLONE_PATH_EXISTING" "_D_GCLONE_PATH_NEW" - D_GIT_CLONE_PATH="$_D_GCLONE_PATH_EXISTING$_D_GCLONE_PATH_NEW" - - if [ -n "$_D_GCLONE_PATH_NEW" ] ; then - # the path obviously doesn't exist yet - printf "the folder you specified does not exist.\n" - printf "create '$D_GIT_CLONE_PATH'?\n" - read -p "Press [Enter] to create it and continue... " - - log_inf "creating '$D_GIT_CLONE_PATH' and cloning the git repo..." - run_or_error "mkdir -p -v \"$D_GIT_CLONE_PATH\"" - _git_clone_diaspora_repo - - elif ! (cd "$D_GIT_CLONE_PATH" && git status) ; then - # the path doesn't appear to contain a git clone - printf "the folder you specified does not contain a git repo\n" - read -p "Press [Enter] to create it and continue... " - - log_inf "cloning the git repo..." - _git_clone_diaspora_repo - - else - cd "$D_GIT_CLONE_PATH" - - log_inf "setting your git clone to '$D_GIT_BRANCH' branch..." - run_or_error "git stash" - run_or_error "git checkout \"$D_GIT_BRANCH\"" - run_or_error "git pull" - fi - printf "\n" -} - -_git_clone_diaspora_repo() { - run_or_error "git clone \"$D_REMOTE_REPO_URL\" -b \"$D_GIT_BRANCH\" \"$D_GIT_CLONE_PATH\"" -} - - -# handle database decision -database_question() { - printf "Which database type are you using? [1|2]\n" - select choice in "MySQL" "PgSQL"; do - case $choice in - MySQL ) - D_DB="mysql" - # we're done, mysql is default - break - ;; - PgSQL ) - D_DB="postgres" - # replace default with postgres - run_or_error "sed -i'' -e 's/\(<<: \*mysql\)/#\1/g' \"$D_DB_CONFIG_FILE\"" - run_or_error "sed -i'' -e 's/\(#\(<<: \*postgres\)\)/\2/g' \"$D_DB_CONFIG_FILE\"" - break - ;; - esac - done - - printf "\n" -} - - -# ask for database credentials -database_credentials() { - printf "Please specify the database credentials\n(the user must be existent and allowed to create new databases)\n" - read -e -p "hostname: " D_DB_HOST - read -e -p "username: " D_DB_USER - read -e -p "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/\(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\"" - - printf "\n" -} - - -# setup database -# (assume we are in the Diaspora directory) -database_setup() { - log_inf "Database setup" - run_or_error "cp config/database.yml.example \"$D_DB_CONFIG_FILE\"" - printf "\n" - - database_question - database_credentials - - printf "$DATABASE_CHK_MSG" - read -p "Press [Enter] to continue... " - - printf "\n" -} - - -# install all the gems with bundler -# (assume we are in the Diaspora directory) -prepare_gem_bundle() { - log_inf "installing all required gems..." - rvm_or_sudo "bundle install" - printf "\n" -} - - -# main setup function, entry point -# all other functions will be called from here -diaspora_setup() { - #interactive_check - root_check - - # display a nice welcome message - printf "$WELCOME_MSG" - read -p "Press [Enter] to continue... " - - # check if we have everything we need - sane_environment_check - - # check git stuff and pull if necessary - git_stuff_check - - # goto working directory - run_or_error "cd \"$D_GIT_CLONE_PATH\"" - prepare_install_env - - # configure database setup - database_setup - - # diaspora config - log_inf "copying diaspora.yml.example to diaspora.yml" - run_or_error "cp config/diaspora.yml.example config/diaspora.yml" - printf "\n" - - # bundle gems - prepare_gem_bundle - - log_inf "creating the default database specified in config/database.yml. please wait..." - run_or_error "bin/rake db:schema:load_if_ruby --trace" - printf "\n" - - printf "$GOODBYE_MSG" - - exit 0 -} |