-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_user.sh
executable file
·97 lines (80 loc) · 2.58 KB
/
setup_user.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
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
#!/bin/bash
# User-mode setup script.
# Do not call directly.
debug_mode="no" # set to yes to debug
if [[ $EUID -eq 0 ]]; then
echo "This script must not be run as root"
exit 1
fi
if [[ "$_SETUP_MAGIC" == "magic123456" ]]; then
echo "This script must not be run directly"
exit 1
fi
# Use bash strict mode.
set -eux
set -o pipefail
# Get semester tag
export SEMESTER_TAG=$(./scripts/read_tag.py $HOME/general.yaml)
# Pull in credentials.
source $HOME/credentials.sh
source $HOME/user_credentials.sh
# Remove user_credentials since they are sensitive
if [[ $debug_mode != "yes" ]]; then
rm $HOME/user_credentials.sh
fi
# Git config
git config --global user.name "ee16b-robot"
git config --global user.email "[email protected]"
# Import ssh key
mkdir -p ~/.ssh
cp $HOME/id_rsa ~/.ssh/
if [[ $debug_mode != "yes" ]]; then
rm $HOME/id_rsa
fi
chmod 600 ~/.ssh/id_rsa
# Disable ssh warnings for headless processing
cat <<EOF >> ~/.ssh/config
Host github.com
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Host cory.eecs.berkeley.edu
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOF
# Create source repo (xxxx-www-src.git)
./create_src_repo.py "$GITHUB_USER" "$GITHUB_PASSWORD" "$SEMESTER_TAG-www-src" "Website files for $SEMESTER_TAG"
# Clone source repo locally
git clone [email protected]:ee16b/www-src-template.git "$HOME/$SEMESTER_TAG-www-src"
pushd "$HOME/$SEMESTER_TAG-www-src"
rm -rf .git
cp $HOME/general.yaml .
if [[ $debug_mode != "yes" ]]; then
rm $HOME/general.yaml
fi
git init
git add -A
git commit -m "Initial commit"
git remote add origin [email protected]:ee16b/$SEMESTER_TAG-www-src.git
git push -u origin master
popd
# Clone directories
git clone [email protected]:ee16b/ee16b-lab.git ~/lab_repo
lab_dir=$(readlink -f ~/lab_repo)
git clone [email protected]:ee16b/ee16b-content.git ~/content_repo
content_dir=$(readlink -f ~/content_repo)
# Set up inst
ssh [email protected] "cd ~/public_html/ && git clone [email protected]:ee16b/www-framework.git $SEMESTER_TAG"
ssh [email protected] "cd ~/public_html/$SEMESTER_TAG/ && git clone [email protected]:ee16b/$SEMESTER_TAG-www-src.git src"
# Export environment variables
cat <<EOF > $HOME/env_vars.sh
source $HOME/credentials.sh
export RELEASE_LOC=$HOME/$SEMESTER_TAG-www-src
export GENERAL_YAML=$HOME/$SEMESTER_TAG-www-src/general.yaml
export MAKEFILE_LOC=$PWD
export HW_LOC=$content_dir/$SEMESTER_TAG/hws
export DISC_LOC=$content_dir/$SEMESTER_TAG/discussion
export CONTENT_REPOS=$lab_dir:$content_dir
export PATH=$PATH:$PWD/scripts
EOF
# Add to bashrc
echo "source $HOME/env_vars.sh" >> ~/.bashrc