Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 498eeae5f2
Fetching contributors…

Cannot retrieve contributors at this time

executable file 389 lines (357 sloc) 14.119 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
#!/bin/bash
#
# --------------------------------------------------------------
# download and run this file with:
# curl -s https://raw.github.com/nodester/nodester-installer/master/nodester_auto.sh > nodester_auto.sh;
# chmod a+x nodester_auto.sh
# ./nodester_auto.sh
# --------------------------------------------------------------
#

whoami=`whoami`
system=`uname -s`
case $whoami in
  root)

    # color used for printing
    use_color=true
if ($use_color) ;
    then
      BLDYEL=$(tput bold ; tput setaf 3)
      BLDVIO=$(tput bold ; tput setaf 5)
      BLDCYA=$(tput bold ; tput setaf 6)
      BLDRED=$(tput bold ; tput setaf 1)
      BLDGRN=$(tput bold ; tput setaf 2)
      NOCOLR=$(tput sgr0)
    fi

    echo ${BLDCYA}
    echo " _ _"
    echo " | | | |"
    echo " _ __ ___ __| | ___ ___| |_ ___ _ __"
    echo " | '_ \ / _ \ / _' |/ _ \/ __| __/ _ \ '__|"
    echo " | | | | (_) | (_| | __/\__ \ || __/ |"
    echo " |_| |_|\___/ \__,_|\___||___/\__\___|_|"
    echo ${NOCOLR}

    echo "###########################################################";
    echo "# -- STARTING NODESTER AUTO-INSTALL PROCESS -- #";
    echo "# ${BLDYEL}>> This should be run on a fresh install. <<${NOCOLR} #";
    echo "# ${BLDYEL}>> It may destroy things you care about <<${NOCOLR} #";
    echo "# ${BLDYEL}>> so proceed only if everything id safe! <<${NOCOLR} #";
    echo "###########################################################";
    echo "Type '${BLDGRN}yes${NOCOLR}' if you want to install Nodester (or just press enter to exit)!";
    read keep_going
    if [ "$keep_going" != 'yes' ] ;
    then
      echo "----------------------------------------------------------";
      echo " ok. no worries, then. rock out! \m/ ";
      echo "----------------------------------------------------------";
      exit;
    fi

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Make directories and fetch nodester installers |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    mkdir ~/build
    mkdir ~/build/nodester-installer
    mkdir /node
    mkdir /node/logs
    mkdir /app
    mkdir /git

    cd ~/build/nodester-installer
    wget -q https://raw.github.com/nodester/nodester-installer/master/dependencies_verify.sh
    wget -q https://raw.github.com/nodester/nodester-installer/master/env_creation.sh
    wget -q https://raw.github.com/nodester/nodester-installer/master/package.json
    wget -q https://raw.github.com/nodester/nodester-installer/master/nodester_official_install_guide.txt
    chmod a+x *.sh

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Updating Apt-Get |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    apt-get update
    
    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Updgrading outstanding apt-get updates |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    apt-get upgrade

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Removing Apache (it may be installed by default) |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    apt-get remove apache2
    update-rc.d -f apache2 remove

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Installing apt-get packages |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    apt-get install git-core curl build-essential openssl libssl-dev psmisc couchdb htop redis-server

    #echo ${BLDCYA};
    #echo ".----------------------------------------------------------.";
    #echo "| Generating RSA Key for local machine |";
    #echo "'----------------------------------------------------------'";
    #echo ${NOCOLR}
    #ssh-keygen -t rsa

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Nodester: Create CouchDB Nodester account |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    #couchdb -k;
    /etc/init.d/couchdb start
    sleep 2;
    if [ `grep -Fc "nodester" /etc/couchdb/local.ini` != "0" ]
    then
        # code if found
      echo "No need to update /etc/couchdb/local.ini, Looks like nodester change was already made."
      echo "";
    else
      # code if not found
      /etc/init.d/couchdb stop;
      # FORCE KILL COUCHDB (this gets around the kill -1 issue reported)
      ps -U couchdb -o pid= | xargs kill -9
      sleep 2;
      echo "adding nodester admin account [nodester:password] to CouchDB";
      echo "nodester = password" >> /etc/couchdb/local.ini
      #nano /etc/couchdb/local.ini
      /etc/init.d/couchdb restart;
      sleep 2;
    fi
    /etc/init.d/couchdb status
    sleep 1;

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| VERIFY: Is there a nodester admin account for CouchDB? |";
    echo "'----------------------------------------------------------'";
    echo ${BLDVIO}
    curl http://nodester:password@127.0.0.1:5984
    sleep 1;
    echo ${NOCOLR}
    echo "Type '${BLDGRN}yes${NOCOLR}' if the response looks good. Otherwise, press ENTER to exit.";
    read keep_going
    if [ "$keep_going" != 'yes' ] ;
    then
      echo "${BLDYEL}----------------------------------------------------------";
      echo "ARG. sometimes the solution is to just restart the server.";
      echo "perhaps 'reboot', log back in, and try running this again.";
      echo "----------------------------------------------------------${NOCOLR}";
      echo " - stay strong, young Nodester! \m/ ";
      echo "";
      exit;
    fi

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Node: Installing n (the node.js version manager) |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd ~/build
    git clone https://github.com/alejandromg/n.git
    cd n && make install

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Node: Installing node-v0.4.12 and latest stable version |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    n 0.4.12
    n stable
    n 0.4.12

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Node: NPM fix for n (until patched) |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd /usr/local/bin
    rm npm
    ln -s /usr/local/n/current/bin/npm npm

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| INSTALL NODEJS & DEPENDENCIES... |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd ~/build/nodester-installer
    ./dependencies_verify.sh

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| INSTALLING NODESTER -- :] |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    echo ${BLDGRN}"Press any key to edit the env_creation.sh file (set the ${BLDYEL}password for nodester${BLDGRN}))"${NOCOLR};
    echo "When you're done, just save the file and exit the editor to contiue.";
    read
nano ./env_creation.sh
    sudo ./env_creation.sh

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| ENSURE ALL NPM DEPENDENCIES ARE MET |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd /node/nodester/nodester
    npm update
    npm update
    npm update

    clear;
    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| NodesterHelper: Setup Nodester! |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd /node/nodester/nodester
    echo ${BLDGRN}"Press any key to edit the config.js file. This is important! :)"${NOCOLR};
    echo "When you're done, just save the file and exit the editor to contiue.";
    read
cp ./example_config.js ./config.js
    nano ./config.js
    clear;
    cp ./scripts/example_gitrepoclone.sh ./scripts/gitrepoclone.sh
    #Update scripts/gitrepoclone.sh with the key you specified in config.js
    #nano ./scripts/gitrepoclone.sh
    chown nodester -R ./var/proxy_table.json

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| NodesterHelper: Setup CouchDB Tables |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd /node/nodester/nodester
    ./scripts/couchdb/create_all_couchdb_tables.js
    ./scripts/couchdb/setup_default_views.js

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| NodesterHelper: Copy over Upstart scripts |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd /node/nodester/nodester
    cp ./upstart/* /etc/init/

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| NodesterHelper: Set permissions for /node/nodester/.ssh |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd /node/nodester
    chown nodester -R .ssh
    chgrp nodester -R .ssh
    cd /
    chown nodester app
    chgrp nodester app
    chown nodester git
    chgrp nodester git

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| NodesterHelper: Setup CHRoot |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd /opt
    wget http://nodester.com/sandbox.tar.gz
    tar -zxvf sandbox.tar.gz
    rm sandbox.tar.gz

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| NodesterHelper: Starting up Proxy and Main API |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    cd ~/
    start proxy && start app

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| All done :) Test web frontent on port 80! |";
    echo "'----------------------------------------------------------'";
    echo ${NOCOLR}
    sleep 1;
    echo " >> SERVER RESPONSE IS BELOW :)";
    echo " Note: it may look like a 404 because no apps are running yet.";
    echo ${BLDVIO}
    curl http://127.0.0.1:80
    echo ${NOCOLR}

    echo ${BLDCYA};
    echo ".----------------------------------------------------------.";
    echo "| Nodester Auto-Installation is Complete! \m/ |";
    echo "'----------------------------------------------------------'";
    echo " \ ${BLDYEL}Here are some next steps you should take...${BLDCYA} / ";
    echo " | 1. get familiar with /node |";
    echo " | 2. point a domain name at your server. |";
    echo " | 3. update paths in /node/nodester/nodester/config.js |";
    echo " | 4. view logs in /node/logs |";
    echo " | 5. change the password for user 'nodester' |";
    echo " | 6. set password for database (and update config.js) |";
    echo " | 7. run as needed >> ${BLDGRN}start${NOCOLR}|${BLDRED}stop${NOCOLR} ${BLDVIO}proxy${NOCOLR}|${BLDVIO}app${BLDCYA} |";
    echo " | 8. run: tail -n 50 ./nodester_auto.sh for examples |";
    echo " '------------------------------------------------------'";
    echo ${NOCOLR}

  ;;
  *)
    echo "Dude, You ain't root :("
  ;;
esac
    
exit 0


# ------------------------------------------------------------------------
# EXAMPLES (last 50 lines of this file)
# ------------------------------------------------------------------------

#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
# curl -X POST -d "coupon=CouponCode&user=testuser&password=123&email=you@email.com&rsakey=ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQ..." http://<yourdomain>/user
#
# curl -u "testuser:123" http://api.<yourdomain>/status
# -> {"status":"up","appshosted":0,"appsrunning":0}
#
# curl -u "testuser:123" http://api.<yourdomain>/apps
# -> []
#
# curl -X POST -u "testuser:123" -d "appname=testapp&start=hello.js" http://api.<yourdomain>/app
# -> {"status":"success","port":10007,"gitrepo":"nodester@git.<yourdomain>:/git/testuser/1-e0637cb80f0e660fe133a308f86eb9ad.git","start":"hello.js","running":false,"pid":"unknown"}
#
# The point of the RSA token is to allow for git clone/push without username and password.
# if it doesn't know your RSA token, you'll need the nodester user/pass ( nodester / YourUb3rSecretPassword! )
#
# git clone nodester@git.<yourdomain>:/git/testuser/1-e0637cb80f0e660fe133a308f86eb9ad.git testapp
# cd testapp
# ls
# echo "console.log('mooo');" > hello.js
# git add .
# git commit -m "first commit"
# git push origin master
#
Something went wrong with that request. Please try again.