-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scripts/install/auto-install.sh #824
Changes from all commits
9917cf4
d4ebdf8
8f17431
b5a9f2d
7cdc970
52dd23a
41cdf85
c16558b
d11f8fe
4031a81
9795b1e
9efc869
ef1cd69
3f60c0d
9627824
13c2c91
452d8bc
de5a509
ec2d089
1abd4e1
e1ed9cf
32f3095
c4188fa
8523041
c5431c6
35e8bdb
e8cdc37
c84fdda
f452e32
42c290d
1b14b96
db22f84
a0e2ad2
e2753a1
02c3d1e
8118344
96350bd
7d7b52d
3955798
433471f
732a2ca
0f77dc6
f742e52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,3 +78,6 @@ coreutils | |
# includes this file). | ||
git | ||
|
||
# Installing some POCS dependencies (esp. astroscrappy) require a C compiler, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Not terrible to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acknowledged. |
||
# for which we install gcc via the build-essentials package. | ||
build-essential |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,316 @@ | ||
#!/bin/bash | ||
# auto-install.sh installs git if it isn't installed, then clones POCS and | ||
# installs its dependencies. | ||
# | ||
# To fetch this script from github and execute it immediately, | ||
# run these commands: | ||
# | ||
# export POCS_GITHUB_USER="panoptes" | ||
# export POCS_BRANCH="develop" | ||
# BASE_RAW_POCS_URL="https://raw.githubusercontent.com/${POCS_GITHUB_USER}/POCS/${POCS_BRANCH}" | ||
# export AUTO_INSTALL_RAW_URL="${BASE_RAW_POCS_URL}/scripts/install/auto-install.sh" | ||
# wget -q -O - "${AUTO_INSTALL_RAW_URL}" | bash | ||
|
||
################################################################################ | ||
# Functions COPIED from install-helper-functions.sh | ||
# Print the disk location of the first arg. | ||
function safe_which() { | ||
type -p "${1}" || /bin/true | ||
} | ||
|
||
# Print a separator bar of # characters. | ||
function echo_bar() { | ||
local terminal_width="${COLUMNS}" | ||
if [ -z "${terminal_width}" ] && [ -n "${TERM}" ] | ||
then | ||
if [[ -n "$(safe_which tput)" ]] | ||
then | ||
terminal_width="$(tput cols)" | ||
elif [[ -n "$(safe_which resize)" ]] | ||
then | ||
terminal_width="$(resize 2>/dev/null | grep COLUMNS= | cut -d= -f2)" | ||
elif [[ -n "$(safe_which stty)" ]] | ||
then | ||
terminal_width="$(stty size 2>/dev/null | cut '-d ' -f2)" | ||
fi | ||
fi | ||
printf "%${terminal_width:-80}s\n" | tr ' ' '#' | ||
} | ||
|
||
################################################################################ | ||
|
||
function do_sudo() { | ||
if [ "$(id -u -n)" == "root" ] ; then | ||
echo "Running ${*}" | ||
"$@" | ||
else | ||
echo <<ENDOFMESSAGE | ||
Running: | ||
sudo ${*} | ||
You may be prompted for your password. | ||
ENDOFMESSAGE | ||
(set -x ; sudo "$@") | ||
fi | ||
} | ||
|
||
function clone_or_update() { | ||
local -r REPO_DIR="${1}" | ||
local -r REPO_URL="${2}" | ||
local -r ORIGIN_NAME="${3}" | ||
local -r BRANCH="${4}" | ||
|
||
echo_bar | ||
|
||
if [ ! -d "${REPO_DIR}/.git" ] | ||
then | ||
if [ -d "${REPO_DIR}" ] | ||
then | ||
echo 2> " | ||
The directory (${REPO_DIR}) already exists, but doesn't appear | ||
to be a valid git repository. Please remove it (or move it out | ||
of the way) and re-run this script. | ||
" | ||
exit 1 | ||
fi | ||
echo " | ||
Cloning ${REPO_URL} into ${REPO_DIR} | ||
" | ||
(set -x ; git clone --origin "${ORIGIN_NAME}" "${REPO_URL}" "${REPO_DIR}") | ||
cd "${REPO_DIR}" | ||
git checkout "${BRANCH}" | ||
jamessynge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else | ||
echo " | ||
Pulling the latest software into the worktree at ${REPO_DIR}. | ||
" | ||
cd "${REPO_DIR}" | ||
git fetch --all | ||
git checkout "${BRANCH}" | ||
git pull | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If they have already set up the repo they might have I think if the dir is there and a repo we just do nothing other than maybe print a message reminding them to update. Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, clearly if there are already files staged then we need to avoid messing with the repo. I'll adjust the script to stop if there is a POCS or PAWS repo. |
||
fi | ||
} | ||
|
||
function maybe_print_example() { | ||
if [[ -n "${AUTO_INSTALL_RAW_URL}" ]] | ||
then | ||
>&2 cat <<ENDOFMESSAGE | ||
For example: | ||
|
||
wget -q -O - "${AUTO_INSTALL_RAW_URL}" | bash | ||
|
||
ENDOFMESSAGE | ||
fi | ||
} | ||
|
||
function ensure_ownership() { | ||
local -r path="${1}" | ||
local -r user="${2}" | ||
local -r group="${3}" | ||
echo_bar | ||
echo " | ||
Ensuring that ${path} is owned by user ${user}, and by group ${group}. | ||
" | ||
time do_sudo chown --recursive "${user}:${group}" "${path}" | ||
echo | ||
} | ||
|
||
function ensure_directory_ownership() { | ||
local -r path="${1}" | ||
local -r user="${2}" | ||
local -r group="${3}" | ||
|
||
echo_bar | ||
echo " | ||
Ensuring that directory ${path} exists. | ||
" | ||
if [ ! -d "${path}" ] | ||
then | ||
do_sudo mkdir -p "${path}" | ||
echo | ||
fi | ||
|
||
ensure_ownership "${path}" "${user}" "${group}" | ||
} | ||
|
||
function already_have_a_repo() { | ||
>&2 cat <<ENDOFMESSAGE | ||
|
||
The purpose of this script is to make sure git is installed, then to clone the | ||
POCS and PAWS git repositories (which contain the PANOPTES software for a | ||
PANOPTES telescope), install software that POCS and PAWS depend upon, and to | ||
run tests. However, there is already a $1 repository located at: | ||
|
||
$2 | ||
|
||
You may be able to install those dependencies by running this command: | ||
|
||
${POCS}/scripts/install/install-dependencies.sh | ||
|
||
ENDOFMESSAGE | ||
} | ||
|
||
|
||
|
||
# End of functions. | ||
################################################################################ | ||
|
||
# Exit immediately if a command fails: | ||
set -e | ||
|
||
# COPIED from default-env-vars.sh | ||
[[ -z "${PANUSER}" ]] && export PANUSER="panoptes" # Default user | ||
[[ -z "${PANDIR}" ]] && export PANDIR="/var/panoptes" # Main Dir | ||
[[ -z "${PANLOG}" ]] && export PANLOG="${PANDIR}/logs" # Log files | ||
[[ -z "${POCS}" ]] && export POCS="${PANDIR}/POCS" # Main Observatory Control | ||
[[ -z "${PAWS}" ]] && export PAWS="${PANDIR}/PAWS" # Web Interface | ||
|
||
|
||
# Do we need to create the user PANUSER? | ||
|
||
if ! id -u "${PANUSER}" 2>/dev/null 1>/dev/null | ||
then | ||
>&2 cat <<ENDOFMESSAGE | ||
The user ${PANUSER} doesn't exist yet. Please create it by running: | ||
|
||
sudo adduser --shell /bin/bash --add_extra_groups ${PANUSER} | ||
|
||
You will be prompted to enter a password for this new user. You may also be | ||
prompted to provide contact info as if this were a user on a shared computer | ||
(e.g. Full Name and Home Phone). Press Enter to leave these unset. | ||
|
||
After the command completes, we need to ensure that the user is a | ||
member of some key groups: | ||
|
||
sudo usermod --append --groups adm,dialout,plugdev,sudo ${PANUSER} | ||
|
||
Next, login as ${PANUSER} and re-execute the command you used to | ||
run this script. | ||
ENDOFMESSAGE | ||
|
||
maybe_print_example | ||
exit 1 | ||
fi | ||
|
||
# Do we need to login as the user PANUSER? | ||
|
||
if [[ "$(whoami)" != "${PANUSER}" ]] | ||
then | ||
echo >&2 " | ||
This script should be executed by the user ${PANUSER}, not as $(whoami). | ||
Please login as ${PANUSER} and re-execute the command you used to | ||
run this script. | ||
" | ||
|
||
maybe_print_example | ||
exit 1 | ||
fi | ||
|
||
# I (James Synge) have noticed that if $HOME/.cache/ doesn't exist, then at some | ||
# point during the install it gets created, but is owned by root:root, which | ||
# then messes up later steps that attempt to use it. So, we make sure here that | ||
# it exists with the correct ownership. | ||
|
||
PANGROUP="$(id -gn "${PANUSER}")" | ||
ensure_directory_ownership "${HOME}/.cache" "${PANUSER}" "${PANGROUP}" | ||
|
||
# Do the same with PANDIR (usually /var/panoptes). | ||
ensure_directory_ownership "${PANDIR}" "${PANUSER}" "${PANGROUP}" | ||
|
||
################################################################################ | ||
# Is there already a POCS or PAWS repository? If so, the user should not need | ||
# this script. | ||
if [[ -d "${POCS}/.git" ]] | ||
then | ||
already_have_a_repo POCS "${POCS}" | ||
exit 1 | ||
fi | ||
|
||
if [[ -d "${PAWS}/.git" ]] | ||
then | ||
already_have_a_repo PAWS "${PAWS}" | ||
exit 1 | ||
fi | ||
|
||
# Install git if necessary. | ||
|
||
if [ ! -x "$(safe_which git)" ] | ||
then | ||
echo_bar | ||
echo " | ||
git is not installed. Updating package cache, then installing git. | ||
" | ||
do_sudo apt-get update | ||
echo | ||
echo | ||
do_sudo apt-get install -y git | ||
echo | ||
fi | ||
|
||
# Clone the POCS repo from github. | ||
|
||
clone_or_update "${POCS}" https://github.com/panoptes/POCS.git upstream develop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. This is used as the origin name when cloning, so that |
||
|
||
# If the user specified another repo via POCS_GITHUB_USER, use that as | ||
# the origin, and checkout the branch POCS_BRANCH. | ||
|
||
if [[ -n "${POCS_GITHUB_USER}" && "${POCS_GITHUB_USER}" != "panoptes" ]] | ||
then | ||
cd "${POCS}" | ||
git remote add -f origin "https://github.com/${POCS_GITHUB_USER}/POCS.git" || true | ||
git checkout "origin/${POCS_BRANCH:-develop}" | ||
fi | ||
|
||
# Clone PAWS too, but only from the upstream. | ||
clone_or_update \ | ||
"${PAWS}" "https://github.com/panoptes/PAWS.git" upstream develop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, that is intended. |
||
|
||
################################################################################ | ||
echo | ||
echo_bar | ||
echo_bar | ||
echo " | ||
Executing ${POCS}/scripts/install/install-dependencies.sh, which will | ||
install the tools needed to run POCS. | ||
" | ||
|
||
${POCS}/scripts/install/install-dependencies.sh | ||
|
||
echo | ||
echo | ||
echo_bar | ||
echo_bar | ||
echo " | ||
|
||
Testing the installation of POCS. This can easily take 5 minutes on an Intel NUC | ||
or longer on a Raspberry Pi. | ||
|
||
" | ||
|
||
if [[ ! -e "${POCS}/conf_files/pocs_local.yaml" ]] | ||
then | ||
# TODO Consider allowing the *_local.yaml files to be located outside of the | ||
# /var/panoptes tree so that it is feasible to wipe out /var/panoptes and | ||
# reinstall without losing local customizations. | ||
cp "${POCS}/conf_files/pocs.yaml" "${POCS}/conf_files/pocs_local.yaml" | ||
echo " | ||
|
||
You will need to modify the file ${POCS}/conf_files/pocs_local.yaml | ||
to suit your needs (e.g. set the unit name, location, etc.). | ||
" | ||
fi | ||
|
||
# shellcheck source=/var/panoptes/set-panoptes-env.sh | ||
source $PANDIR/set-panoptes-env.sh | ||
cd $POCS | ||
python setup.py install | ||
pytest --test-databases=all --solve | ||
|
||
if cmp "${POCS}/conf_files/pocs.yaml" "${POCS}/conf_files/pocs_local.yaml" | ||
then | ||
echo " | ||
|
||
Don't forget to modify the file ${POCS}/conf_files/pocs_local.yaml | ||
to suit your needs (e.g. set the unit name, location, etc.). | ||
" | ||
fi | ||
|
||
exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we could somehow put a timer on this. urllib3 1.25.x is only about two weeks old, so I expect this will resolve itself shortly.
Of course, there are not really any features in 1.25 that we require so should be okay.