#! /bin/bash # # Sandstorm - Personal Cloud Sandbox # Copyright (c) 2014 Sandstorm Development Group, Inc. and contributors # All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This script attempts to find Meteor's "dev bundle", which contains the node # and mongo binaries and headers, so that we can borrow them rather than making # users install them separately. # # Currently this script is not quite right. It tries to find the most-recent # bundle, but we should probably take the bundle matching the Meteor version # that Sandstorm is currently using. Moreover, it appears that this script's # technique sometimes ends up with an *older* bundle than the most-recent, I # guess because Meteor is sometimes lazy about updating the main `meteor` # command's symlink. I have not yet deciphered enough about the Meteor # warehouse's layout to figure out how to map directly from a version to a # dev bundle. set -euo pipefail global SCRIPT_DIR := $[cd $[dirname $(BASH_SOURCE[0])] && pwd] global METEOR_WAREHOUSE_DIR := $(METEOR_WAREHOUSE_DIR:-$HOME/.meteor) echo -n "Finding meteor-tool installation (can take a few seconds)..." > !2 # If we run the meteor tool outside of `shell`, it might try to update itself. Inside `shell`, it # sees the meteor version we're using and sticks to that. cd "$SCRIPT_DIR/shell" global METEOR_RELEASE := $[<.meteor/release] if test $METEOR_RELEASE = "METEOR@1.0.2" { # Some time after 1.0.2, the output format of `meteor show` changed and the --ejson flag was # added. But as of this writing we're still at 1.0.2, so parse the old output format. global TOOL_VERSION := $[meteor show $METEOR_RELEASE | grep -o 'meteor-tool@[0-9a-zA-Z_.-]*] } else { # TODO(cleanup): It would be nice to use a real JSON parser here, but I don't particularly want # to depend on one, nor do I want to depend on Node being installed. global TOOL_VERSION := $[meteor show --ejson $METEOR_RELEASE | grep '^ *"tool":' | sed -re 's/^.*"(meteor-tool@[^"]*)".*$/\1/g] } global TOOLDIR := $[echo $TOOL_VERSION | tr @ /] echo " $TOOL_VERSION" > !2 readlink -f $METEOR_WAREHOUSE_DIR/packages/$TOOLDIR/mt-os.linux.x86_64/dev_bundle (CommandList children: [ (C {(set)} {(-euo)} {(pipefail)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SCRIPT_DIR) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(dirname)} { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{(Lit_Digits 0)}) ) spids: [106 111] ) ) } ) ] ) left_token: spids: [102 113] ) ) } ) (C {(pwd)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [98 119] ) ) } spids: [96] ) ] spids: [96] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:METEOR_WAREHOUSE_DIR) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {($ VSub_Name "$HOME") (Lit_Slash /) (.meteor)} ) spids: [125 131] ) ) } spids: [123] ) ] spids: [123] ) (SimpleCommand words: [{(echo)} {(-n)} {(DQ ("Finding meteor-tool installation (can take a few seconds)..."))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[143])] ) (C {(cd)} {(DQ ($ VSub_Name "$SCRIPT_DIR") (/shell))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:METEOR_RELEASE) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(.meteor/release)} spids: [163] ) ] ) ] ) left_token: spids: [162 165] ) } spids: [161] ) ] spids: [161] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$METEOR_RELEASE"))} {(Lit_Other "=")} {(DQ ("METEOR@1.0.2"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TOOL_VERSION) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(meteor)} {(show)} {(DQ ($ VSub_Name "$METEOR_RELEASE"))}) (C {(grep)} {(-o)} {(SQ <"meteor-tool@[0-9a-zA-Z_.-]*">)}) ] negated: False ) ] ) left_token: spids: [197 215] ) } spids: [196] ) ] spids: [196] ) ] spids: [-1 185] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TOOL_VERSION) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(meteor)} {(show)} {(--ejson)} {($ VSub_Name "$METEOR_RELEASE")}) (C {(grep)} {(SQ <"^ *\"tool\":">)}) (C {(sed)} {(-re)} {(SQ <"s/^.*\"(meteor-tool@[^\"]*)\".*$/\\1/g">)}) ] negated: False ) ] ) left_token: spids: [229 256] ) } spids: [228] ) ] spids: [228] ) ] spids: [217 258] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TOOLDIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$TOOL_VERSION")}) (C {(tr)} {(Lit_Other "@")} {(/)}) ] negated: False ) ] ) left_token: spids: [262 274] ) } spids: [261] ) ] spids: [261] ) (SimpleCommand words: [{(echo)} {(DQ (" ") ($ VSub_Name "$TOOL_VERSION"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[284])] ) (C {(readlink)} {(-f)} {($ VSub_Name "$METEOR_WAREHOUSE_DIR") (/packages/) ($ VSub_Name "$TOOLDIR") (/mt-os.linux.x86_64/dev_bundle) } ) ] )