Skip to content

Instantly share code, notes, and snippets.

@totherik
Last active August 29, 2015 13:56
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save totherik/9158942 to your computer and use it in GitHub Desktop.
Save totherik/9158942 to your computer and use it in GitHub Desktop.
npmjs.org registry install script
; CouchDB Config
; Drop in PREFIX/local.d/npmjs.ini
[couch_httpd_auth]
public_fields = appdotnet, avatar, avatarMedium, avatarLarge, date, email, fields, freenode, fullname, github, homepage, name, roles, twitter, type, _id, _rev
users_db_public = true
[httpd]
secure_rewrites = false
[couchdb]
delayed_commits = false
#!/bin/bash
RELEASE=v2.0.3
BASEDIR=`basename $0`
SCRIPTPATH=`cd $(dirname $0) ; pwd -P`
CREATED=201
CONFLICT=409
PRECONDITION_FAILED=412
function assert
{
if [ "$?" != "0" ]; then
fail "${1:-"An unknown error occurred."}";
fi
}
function fail
{
clean
echo "$BASEDIR: $1" 1>&2
exit 1
}
function clean
{
npm set _npmjs.org:couch=
# Only try to clean up files if we made it past cloning
if [ "$SCRIPTPATH" != `pwd` ]; then
cd ../;
rm -rf npmjs.org;
fi
}
# Read hostname
echo -n "Hostname [localhost:5984]: "
read hostname
if [ -z $hostname ]; then hostname="localhost:5984"; fi
# Read DB name
echo -n "Database Name [registry]: "
read database
if [ -z $database ]; then database="registry"; fi
# Read Username
echo -n "CouchDB Username [admin]: "
read username
if [ -z $username ]; then username="admin"; fi
# Read Password
echo -n "CouchDB Password: "
read -s password
echo
echo
# Per: https://github.com/npm/npmjs.org
# Get the npm app from github
git clone git@github.com:npm/npmjs.org.git
assert "$LINENO: Unable to clone npmjs.org."
cd npmjs.org
# Get the latest release (don't use master)
git checkout tags/$RELEASE
assert "$LINENO: Unable to get release $RELEASE."
npm install
assert "$LINENO: npm install failed."
# Set the registry for use by the upcoming scripts
registry=http://$username:$password@$hostname/$database
npm set _npmjs.org:couch=$registry
# Create the database
res=`curl -s -w "%{http_code}" -X PUT $registry -o /dev/null`
assert "$LINENO: Unable to connect to $host."
if [ "$res" != "$CREATED" ] && [ "$res" != "$PRECONDITION_FAILED" ]; then fail "$LINENO: Unable to create database \"$database\". Server responded with status code $res"; fi
# XXX
# Patch env per https://github.com/npm/npmjs.org/commit/2f9dbb9d2f75c96183f9b0cbdbafaa790d380d29
export DEPLOY_VERSION=`git describe --tags`
# XXX
# Sync the ddoc
npm start
assert "$LINENO: npm start failed."
# Load views
npm run load
assert "$LINENO: Unable to load views."
# Ensure _design/app exists
res=`curl -s -w "%{http_code}" -X PUT -H 'Content-Type: application/json' -d '{}' $registry/_design/app -o /dev/null`
assert "$LINENO: Unable to connect to $host."
if [ "$res" != "$CREATED" ] && [ "$res" != "$CONFLICT" ]; then fail "$LINENO: Unable to create _design/app document. Server responded with status code $res"; fi
# Install app
npm run copy
assert "$LINENO: Unable to install couch app."
res=`curl -s -w "%{http_code}" -X PUT -H 'Content-Type: application/json' $registry/error%3A%20forbidden -d '{ "_id": "error: forbidden", "forbidden":"must supply latest _rev to update existing package" }' -o /dev/null`
assert "$LINENO: Unable to connect to $host"
if [ "$res" != "$CREATED" ] && [ "$res" != "$CONFLICT" ]; then fail "$LINENO: Unable to create error document. Server responded with status code $res"; fi
clean
#!/bin/bash
RELEASE=v2.6.2
BASEDIR=`basename $0`
SCRIPTPATH=`cd $(dirname $0) ; pwd -P`
CREATED=201
CONFLICT=409
PRECONDITION_FAILED=412
function assert
{
if [ "$?" != "0" ]; then
fail "${1:-"An unknown error occurred."}";
fi
}
function fail
{
clean
echo "$BASEDIR: $1" 1>&2
exit 1
}
function clean
{
npm set npm-registry-couchapp:couch=
# Only try to clean up files if we made it past cloning
if [ "$SCRIPTPATH" != `pwd` ]; then
cd ../;
rm -rf npmjs.org;
fi
}
# Read hostname
echo -n "Hostname [localhost:5984]: "
read hostname
if [ -z $hostname ]; then hostname="localhost:5984"; fi
# Read DB name
echo -n "Database Name [registry]: "
read database
if [ -z $database ]; then database="registry"; fi
# Read Username
echo -n "CouchDB Username [admin]: "
read username
if [ -z $username ]; then username="admin"; fi
# Read Password
echo -n "CouchDB Password: "
read -s password
echo
echo
# Per: https://github.com/npm/npmjs.org
# Get the npm app from github
git clone git@github.com:npm/npmjs.org.git
assert "$LINENO: Unable to clone npmjs.org."
cd npmjs.org
# Get the latest release (don't use master)
git checkout tags/$RELEASE
assert "$LINENO: Unable to get release $RELEASE."
npm install
assert "$LINENO: npm install failed."
# Set the registry for use by the upcoming scripts
registry=http://$username:$password@$hostname/$database
npm set npm-registry-couchapp:couch=$registry
# Create the database
res=`curl -s -w "%{http_code}" -X PUT $registry -o /dev/null`
assert "$LINENO: Unable to connect to $hostname."
if [ "$res" != "$CREATED" ] && [ "$res" != "$PRECONDITION_FAILED" ]; then fail "$LINENO: Unable to create database \"$database\". Server responded with status code $res"; fi
# XXX
# Patch env per https://github.com/npm/npmjs.org/commit/2f9dbb9d2f75c96183f9b0cbdbafaa790d380d29
export DEPLOY_VERSION=`git describe --tags`
# XXX
# Sync the ddoc
npm start
assert "$LINENO: npm start failed."
# Load views
npm run load
assert "$LINENO: Unable to load views."
# Ensure _design/app exists
res=`curl -s -w "%{http_code}" -X PUT -H 'Content-Type: application/json' -d '{}' $registry/_design/app -o /dev/null`
assert "$LINENO: Unable to connect to $host."
if [ "$res" != "$CREATED" ] && [ "$res" != "$CONFLICT" ]; then fail "$LINENO: Unable to create _design/app document. Server responded with status code $res"; fi
# Install app
npm run copy
assert "$LINENO: Unable to install couch app."
#res=`curl -s -w "%{http_code}" -X PUT -H 'Content-Type: application/json' $registry/error%3A%20forbidden -d '{ "_id": "error: forbidden", "forbidden":"must supply latest _rev to update existing package" }' -o /dev/null`
#echo "curl -s -X PUT -H 'Content-Type: application/json' $registry/error%3A%20forbidden -d '{ \"_id\": \"error: forbidden\", \"forbidden\":\"must supply latest _rev to update existing package\" }'"
#assert "$LINENO: Unable to connect to $host"
#if [ "$res" != "$CREATED" ] && [ "$res" != "$CONFLICT" ]; then fail "$LINENO: Unable to create error document. Server responded with status code $res"; fi
clean
#!/bin/bash
RELEASE=v2.6.6
BASEDIR=`basename $0`
SCRIPTPATH=`cd $(dirname $0) ; pwd -P`
CREATED=201
CONFLICT=409
PRECONDITION_FAILED=412
function assert
{
if [ "$?" != "0" ]; then
fail "${1:-"An unknown error occurred."}";
fi
}
function fail
{
clean
echo "$BASEDIR: $1" 1>&2
exit 1
}
function clean
{
npm set npm-registry-couchapp:couch=
# Only try to clean up files if we made it past cloning
if [ "$SCRIPTPATH" != `pwd` ]; then
cd ../;
rm -rf npmjs.org;
fi
}
# Read hostname
echo -n "Hostname [localhost:5984]: "
read hostname
if [ -z $hostname ]; then hostname="localhost:5984"; fi
# Read DB name
echo -n "Database Name [registry]: "
read database
if [ -z $database ]; then database="registry"; fi
# Read Username
echo -n "CouchDB Username [admin]: "
read username
if [ -z $username ]; then username="admin"; fi
# Read Password
echo -n "CouchDB Password: "
read -s password
echo
echo
# Per: https://github.com/npm/npmjs.org
# Get the npm app from github
git clone git@github.com:npm/npm-registry-couchapp.git
assert "$LINENO: Unable to clone npmjs.org."
cd npm-registry-couchapp
# Get the latest release (don't use master)
git checkout tags/$RELEASE
assert "$LINENO: Unable to get release $RELEASE."
npm install
assert "$LINENO: npm install failed."
# Set the registry for use by the upcoming scripts
registry=http://$username:$password@$hostname/$database
npm set npm-registry-couchapp:couch=$registry
# Create the database
res=`curl -s -w "%{http_code}" -X PUT $registry -o /dev/null`
assert "$LINENO: Unable to connect to $hostname."
if [ "$res" != "$CREATED" ] && [ "$res" != "$PRECONDITION_FAILED" ]; then fail "$LINENO: Unable to create database \"$database\". Server responded with status code $res"; fi
# XXX
# Patch env per https://github.com/npm/npmjs.org/commit/2f9dbb9d2f75c96183f9b0cbdbafaa790d380d29
export DEPLOY_VERSION=`git describe --tags`
# XXX
# Sync the ddoc
npm start
assert "$LINENO: npm start failed."
# Load views
npm run load
assert "$LINENO: Unable to load views."
# Ensure _design/app exists
res=`curl -s -w "%{http_code}" -X PUT -H 'Content-Type: application/json' -d '{}' $registry/_design/app -o /dev/null`
assert "$LINENO: Unable to connect to $host."
if [ "$res" != "$CREATED" ] && [ "$res" != "$CONFLICT" ]; then fail "$LINENO: Unable to create _design/app document. Server responded with status code $res"; fi
# Install app
npm run copy
assert "$LINENO: Unable to install couch app."
#res=`curl -s -w "%{http_code}" -X PUT -H 'Content-Type: application/json' $registry/error%3A%20forbidden -d '{ "_id": "error: forbidden", "forbidden":"must supply latest _rev to update existing package" }' -o /dev/null`
#echo "curl -s -X PUT -H 'Content-Type: application/json' $registry/error%3A%20forbidden -d '{ \"_id\": \"error: forbidden\", \"forbidden\":\"must supply latest _rev to update existing package\" }'"
#assert "$LINENO: Unable to connect to $host"
#if [ "$res" != "$CREATED" ] && [ "$res" != "$CONFLICT" ]; then fail "$LINENO: Unable to create error document. Server responded with status code $res"; fi
clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment