This repository was archived by the owner on Feb 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall-pocs.sh
More file actions
220 lines (189 loc) · 6.77 KB
/
install-pocs.sh
File metadata and controls
220 lines (189 loc) · 6.77 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env bash
usage() {
echo -n "##################################################
# Install POCS and friends.
#
# This script is designed to install the PANOPTES Observatory
# Control System (POCS) on a cleanly installed Ubuntu system.
#
# The script will insure that Docker is installed, download the
# latest Docker images (see list below) and clone a copy of the
# relevant PANOPTES repositories.
#
# Docker Images:
#
# gcr.io/panoptes-survey/pocs
# gcr.io/panoptes-survey/paws
#
# Github Repositories:
#
# The script will ask for a github user name in order to install
# forked versions of the repos if you are actively developing the
# software. otherwise the default user (panotpes) is okay for
# running the unit.
#
# github.com/panoptes/POCS
# github.com/panoptes/PAWS
# github.com/panoptes/panoptes-utils
#
# The script has been tested with a fresh install of Ubuntu 19.04
# but may work on other linux systems.
#############################################################
$ $(basename $0) [--user panoptes] [--pandir /var/panoptes]
Options:
USER The default user. This is saved as the PANUSER environment variable.
PANDIR Default install directory, defaults to /var/panoptes. Saved as PANDIR
environment variable.
"
}
if [ -z "${PANUSER}" ]; then
export PANUSER=$USER
echo "export PANUSER=${PANUSER}" >> ${HOME}/.zshrc
fi
if [ -z "${PANDIR}" ]; then
export PANDIR='/var/panoptes'
echo "export PANDIR=${PANDIR}" >> ${HOME}/.zshrc
fi
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-u|--user)
PANUSER="$2"
shift # past argument
shift # past value
;;
-d|--pandir)
PANDIR="$2"
shift # past argument
shift # past value
;;
-h|--help)
PANDIR="$2"
usage
exit 1
;;
esac
done
function command_exists {
# https://gist.github.com/gubatron/1eb077a1c5fcf510e8e5
# this should be a very portable way of checking if something is on the path
# usage: "if command_exists foo; then echo it exists; fi"
type "$1" &> /dev/null
}
do_install() {
clear
OS="$(uname -s)"
case "${OS}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
*) machine="UNKNOWN:${unameOut}"
esac
echo ${machine}
LOGFILE="${PANDIR}/logs/install-pocs.log"
echo "Installing PANOPTES software."
echo "USER: ${PANUSER}"
echo "OS: ${OS}"
echo "DIR: ${PANDIR}"
echo "Logfile: ${LOGFILE}"
# System time doesn't seem to be updating correctly for some reason.
# Perhaps just a VirtualBox issue but running on all linux.
if [[ "${OS}" = "Linux" ]]; then
sudo systemctl start systemd-timesyncd.service
fi
if [[ ! -d "${PANDIR}" ]]; then
echo "Creating directories"
# Make directories
sudo mkdir -p "${PANDIR}"
sudo chown -R "${PANUSER}":"${PANUSER}" "${PANDIR}"
mkdir -p "${PANDIR}/logs"
mkdir -p "${PANDIR}/images"
else
echo "WARNING ${PANDIR} already exists. You can exit and specify an alternate directory with --pandir or continue."
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Proceeding with existing directory"; break;;
No ) echo "Exiting"; exit 1;;
esac
done
fi
echo "Log files will be stored in ${PANDIR}/logs/install-pocs.log."
# apt: git, wget
echo "Installing system dependencies"
if [[ "${OS}" = "Linux" ]]; then
sudo apt-get update >> "${LOGFILE}" 2>&1
sudo apt-get --yes install wget curl git openssh-server ack jq httpie byobu vim-nox zsh >> "${LOGFILE}" 2>&1
elif [[ "${OS}" = "Darwin" ]]; then
sudo brew update | sudo tee -a "${LOGFILE}"
sudo brew install wget curl git jq httpie | sudo tee -a "${LOGFILE}"
fi
echo "Cloning PANOPTES source code."
echo "Github user for PANOPTES repos (POCS, PAWS, panoptes-utils)."
# Default user
read -p "Github User [press Enter for default]: " github_user
github_user=${github_user:-panoptes}
echo "Using repositories from user '${github_user}'."
if [[ "${github_user}" = "panoptes" ]]; then
echo "Using development files from user 'panoptes' for now."
fi
GIT_BRANCH="docker"
cd "${PANDIR}"
declare -a repos=("POCS" "PAWS" "panoptes-utils")
for repo in "${repos[@]}"; do
if [ ! -d "${PANDIR}/${repo}" ]; then
echo "Cloning ${repo}"
# Just redirect the errors because otherwise looks like it hangs.
git clone "https://github.com/${github_user}/${repo}.git" >> "${LOGFILE}" 2>&1
if [[ "${repo}" = "POCS" && "${github_user}" = "panoptes" ]]; then
echo "Getting docker branch '$GIT_BRANCH'"
cd "${repo}" && git checkout $GIT_BRANCH
cd "${PANDIR}"
fi
else
echo "Repo ${repo} already exists on system."
fi
done
# Link env_file from POCS
ln -sf "${PANDIR}/POCS/docker/env_file" "${PANDIR}"
echo "source ${PANDIR}/env_file" >> "${HOME}/.zshrc"
# Link conf_files dir from POCS
ln -sf "${PANDIR}/POCS/conf_files" "${PANDIR}"
# Get Docker
if ! command_exists docker; then
echo "Installing Docker"
if [[ "${OS}" = "Linux" ]]; then
/bin/bash -c "$(wget -qO- https://get.docker.com)" &>> ${PANDIR}/logs/install-pocs.log
if ! command_exists docker-compose; then
# Docker compose as container - https://docs.docker.com/compose/install/#install-compose
sudo wget -q https://github.com/docker/compose/releases/download/1.24.0/run.sh -O /usr/local/bin/docker-compose
sudo chmod a+x /usr/local/bin/docker-compose
sudo docker pull docker/compose
fi
echo "Adding ${PANUSER} to docker group"
sudo usermod -aG docker "${PANUSER}" >> "${LOGFILE}" 2>&1
elif [[ "${OS}" = "Darwin" ]]; then
brew cask install docker
echo "Adding ${PANUSER} to docker group"
sudo dscl -aG docker "${PANUSER}"
fi
echo "Pulling POCS docker images"
sudo docker pull gcr.io/panoptes-survey/panoptes-utils
sudo docker pull gcr.io/panoptes-survey/pocs
sudo docker pull gcr.io/panoptes-survey/paws
else
echo "WARNING: Docker images not installed/downloaded."
fi
# Add an SSH key if one doesn't exists
if [ ! -f "${HOME}/.ssh/id_rsa" ]; then
ssh-keygen -t rsa -N "" -f "${HOME}/.ssh/id_rsa";
fi
echo "Please reboot your machine before using POCS."
read -p "Reboot now? [y/N]: " -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
sudo reboot
fi
}
# wrapped up in a function so that we have some protection against only getting
# half the file during "curl | sh" - copied from get.docker.com
do_install