quick-start
3.68 KB
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
#!/bin/sh
set -e
say() {
  msg="$@"
  if [ -t 1 ]; then
    printf "\033[1;34;49m%s\033[m\n" "$msg"
  else
    echo "$msg"
  fi
}
complain() {
  msg="$@"
  if [ -t 1 ]; then
    printf "\033[1;31;49m%s\033[m\n" "$msg"
  else
    echo "$msg"
  fi
}
run() {
  say "\$ $@"
  local rc=0
  "$@" || rc=$?
  if [ $rc -ne 0 ]; then
    complain "E: The command \"$@\" failed with status code $status, we cannot proceed."
    complain "I: If you have no idea of what went wrong, please feel free to ask for help in the Noosfero community. Check the contact information in the project website (http://noosfero.org/)."
    exit 1
  fi
}
quiet() {
  local tmpfile=$(mktemp)
  local rc=0
  "$@" > "$tmpfile" 2>&1 || rc=$?
  if [ $rc -ne 0 ]; then
    cat "$tmpfile"
  fi
  rm -f "$tmpfile"
  return $rc
}
gem_install() {
  if [ -w "$(ruby -rubygems -e 'puts Gem.dir')" ]; then
    run gem install --no-ri --no-rdoc $@
  else
    run gem install --user-install --no-ri --no-rdoc $@
  fi
}
setup_rubygems_path() {
  local dir="$(ruby -rubygems -e 'puts Gem.dir')/bin"
  if [ -d "$dir" ]; then
    export PATH="$dir:$PATH"
  fi
  local dir="$(ruby -rubygems -e 'puts Gem.user_dir')/bin"
  if [ -d "$dir" ]; then
    export PATH="$dir:$PATH"
  fi
}
force_install=false
if test "$1" = '--force-install'; then
  force_install=true
fi
if gem which system_timer >/dev/null 2>&1 && which xvfb-run >/dev/null 2>&1 && test "$force_install" = 'false'; then
  say "Assuming dependencies are already installed. Pass --force-install to force their installation"
else
  if ! which lsb_release >/dev/null 2>&1; then
    # special case Debian-based systems; in others people will have to install
    # lsb-release by themselves
    if which apt-get >/dev/null 2>&1; then
      sudo apt-get update
      sudo apt-get -y install lsb-release
    else
      complain "E: lsb_release not available! (Try installing the lsb-release package)"
      exit 1
    fi
  fi
  system=$(echo $(lsb_release -sic) | awk '{print(tolower($1) "-" tolower($2))}')
  install_script="$(dirname $0)/install-dependencies/${system}.sh"
  if test -f "$install_script"; then
    . $install_script
  else
    # FIXME the Ruby stuff could be installed with Rubygems
    # FIXME but there is not generic way to install the non-Ruby stuff
    complain "E: $install_script not found, cannot install dependencies."
    exit 1
  fi
fi
if test -e config/database.yml && test "$force_install" = 'false'; then
  say 'Not updating existent database.yml.'
  say 'If you wish to automatic reconfigure your database connection and'
  say 'recreate the database, you can delete config/database.yml and run'
  say 'this script again.'
else
  # create the database with sample data
  say 'Configuring Noosfero to use PostgreSQL, with your user.'
  run cp config/database.yml.pgsql config/database.yml
  if [ -z "$USER" ]; then
    USER=$(stat -c %U $0)
  fi
  sed -ri "s/username: noosfero/username: $USER/" config/database.yml
  sudo su - postgres -c "createuser $USER --no-superuser --createdb --no-createrole" || true
  sudo su - postgres -c "createdb noosfero_development -O $USER" || true
  run rake db:schema:load
  run rake db:data:minimal
  run rake db:test:prepare
  rails runner 'Environment.default.enable("skip_new_user_email_confirmation")'
fi
if [ ! -d locale ]; then
  run quiet rake noosfero:translations:compile
fi
# create needed directory
mkdir -p tmp/pids
# use default gitignore rules
if [ ! -f .gitignore ]; then
  ln -s gitignore.example .gitignore
fi
# you can now start the server
say "I: Congratulations, you are ready to run Noosfero."
say "I: To execute Noosfero in development mode, run \`./script/development\` and browse to http://localhost:3000"
say "I: To execute Noosfero tests, run \`rake\`."