forked from sormy/arch-ami-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharch-ami-sideload
More file actions
executable file
·72 lines (61 loc) · 2.67 KB
/
arch-ami-sideload
File metadata and controls
executable file
·72 lines (61 loc) · 2.67 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
#!/bin/bash
# sideload configuration
SIDELOAD_TARGET="$1"
SIDELOAD_EC2_PATH="${SIDELOAD_EC2_PATH:-/opt/arch-bootstrap}"
SIDELOAD_EC2_CLEAN="${SIDELOAD_EC2_CLEAN:-false}"
# bootstrap configuration
export AWS_REGION="${AWS_REGION:-${AWS_DEFAULT_REGION:-us-east-1}}"
export PHASE_PROMPT="${PHASE_PROMPT:-false}"
export ELIB_VERBOSE="${ELIB_VERBOSE:-true}"
export ELIB_COLORS="${ELIB_COLORS:-true}"
export SIDELOAD_EC2_PATH
# help screen
if [ -z "$SIDELOAD_TARGET" ]; then
>&2 echo "usage: $(basename "$0") <ec2-user@hostname>"
>&2 echo "environment variables:"
>&2 echo " SIDELOAD_EC2_PATH (sideload/bootstrap, default $SIDELOAD_EC2_PATH)"
>&2 echo " SIDELOAD_EC2_CLEAN (sideload only, default $SIDELOAD_EC2_CLEAN)"
>&2 echo " AWS_REGION (bootstrap only, default $AWS_REGION)"
>&2 echo " PHASE_PROMPT (bootstrap only, default $PHASE_PROMPT)"
>&2 echo " ELIB_VERBOSE (bootstrap only, default $ELIB_VERBOSE)"
>&2 echo " ELIB_COLORS (bootstrap only, default $ELIB_COLORS)"
>&2 echo " see more details in lib/bootstrap/params.sh"
exit 1
fi
echo "Sideloading files to $SIDELOAD_TARGET:$SIDELOAD_EC2_PATH ..."
echo
# cleaning if enabled
if [ "$SIDELOAD_EC2_CLEAN" = "true" ]; then
ssh "$SIDELOAD_TARGET" "sudo sh -c 'rm -rf $SIDELOAD_EC2_PATH'"
fi
# creating a directory and fixing permissions
ssh "$SIDELOAD_TARGET" "sudo sh -c 'mkdir -p $SIDELOAD_EC2_PATH; chmod -R a+rwX $SIDELOAD_EC2_PATH;'"
# copying bootstrap scripts
scp lib/bootstrap/* "$SIDELOAD_TARGET:$SIDELOAD_EC2_PATH"
# making bootstrap scripts executable
ssh "$SIDELOAD_TARGET" "sudo chmod +x $SIDELOAD_EC2_PATH/bootstrap.sh $SIDELOAD_EC2_PATH/phase-*.sh"
# copying params
TEMP_PARAM_FILE="$(mktemp)"
envsubst < lib/bootstrap/params.sh > "$TEMP_PARAM_FILE"
scp "$TEMP_PARAM_FILE" "$SIDELOAD_TARGET:$SIDELOAD_EC2_PATH/params.sh"
rm -f "$TEMP_PARAM_FILE"
# extract just host from target
SIDELOAD_HOST="${SIDELOAD_TARGET/*@/}"
echo
echo "Sideloading is completed."
echo
echo "Ensure:"
echo "1. Correct AWS_REGION environment variable is set."
echo "2. Instance security group allows incoming connections on 22 port"
echo "3. Instance security group allows outgoing connections to internet"
echo "4. Instance has key pair attached that you have access to locally"
echo "5. Instance is connected to public internet and has public IP address"
echo "6. Instance has attached IAM policy with these permissions:"
cat lib/config/ec2-policy.json
echo
echo "Invoke bootstrap before reboot (before phase 3):"
echo " ssh -t ec2-user@$SIDELOAD_HOST sudo $SIDELOAD_EC2_PATH/bootstrap.sh"
echo
echo "Invoke bootstrap after reboot (after phase 3):"
echo " ssh -t alarm@$SIDELOAD_HOST sudo $SIDELOAD_EC2_PATH/bootstrap.sh"
echo