-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathstartup_user_creation.sh
55 lines (45 loc) · 1.72 KB
/
startup_user_creation.sh
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
#!/bin/bash
# slight dodgy hack to make sure everything has started up
sleep 120
# defaults
INSTALL_EMAIL="[email protected]"
INSTALL_ORG="testOrg"
CRED_FILE=/home/ubuntu/ll_credentials.txt
LOCAL_PATH=/usr/local/learninglocker/current
INSTALL_PATH_FILE=/etc/learninglocker/install_path
INSTALL_LOG=/var/log/learninglocker/user_setup.log
if [[ ! -d /home/ubuntu ]]; then
CRED_FILE=/usr/local/learninglocker/ll_credentials.txt
fi
# get the local path from the config
if [[ -f $INSTALL_PATH_FILE ]]; then
LOCAL_PATH=$(cat $INSTALL_PATH_FILE)
fi
# generate password
if [[ `command -v pwgen` ]]; then
INSTALL_PASSWD=`pwgen 12 1`
elif [[ `command -v pwmake` ]]; then
INSTALL_PASSWD=`pwmake 64`
else
INSTALL_PASSWD="ChangeMeN0w"
fi
CHK=$(cd $LOCAL_PATH/webapp; node cli/dist/server createSiteAdmin "$INSTALL_EMAIL" "$INSTALL_ORG" "$INSTALL_PASSWD" 2>>$INSTALL_LOG | grep "User not found")
if [[ $CHK != "" ]]; then
echo "[UC] $CHK" >> $INSTALL_LOG
echo "[UC] creating user $INSTALL_EMAIL" >> $INSTALL_LOG
if [[ ! -f $CRED_FILE ]]; then
echo "[UC] creating credential file $CRED_FILE" >> $INSTALL_LOG
touch $CRED_FILE 2>>$INSTALL_LOG
fi
echo "Created user. Writing details to $CRED_FILE"
echo "email : $INSTALL_EMAIL" > $CRED_FILE
echo "org : $INSTALL_ORG" >> $CRED_FILE
echo "password : $INSTALL_PASSWD" >> $CRED_FILE
# get metadata
aws_region="`wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone`"
aws_ami="`wget -q -O - http://169.254.169.254/latest/meta-data/ami-id`"
# adding call to install checker
chk="`curl lrnloc.kr/AMIinstall`"
else
echo "[UC] User $INSTALL_EMAIL already exists, not creating" >> $INSTALL_LOG
fi