11#! /bin/bash
2- set +u -e
2+ set +u
33
44if [ -z " $1 " ]; then
55 echo " When running this script, please supply the name of the user account for which to set up unstructured dependencies."
66 echo " Ex: ${0} abertl"
77 exit 1
88fi
99
10- set -ux
11-
12- # Set user account for which we're configuring the tools
13- USER_ACCOUNT=$1
14- USER_ACCOUNT_HOME=$( bash -c " cd ~$( printf %q " $USER_ACCOUNT " ) && pwd" )
10+ set -eux
1511
1612# Set package manager command for this distribution
1713pac=" apt"
@@ -25,6 +21,9 @@ if [[ $(whoami) == 'root' ]]; then
2521 sudo=' sudo'
2622fi
2723
24+ # Set user account for which we're configuring the tools
25+ USER_ACCOUNT=$1
26+
2827# Update existing packages
2928# Reconfigure the service that detects the need for service restarts from interactive mode (user
3029# needs to manually confirm which services to restart) to automatic. If we don't do this we'll
@@ -36,42 +35,45 @@ if [[ -d /etc/needrestart/conf.d ]]; then
3635fi
3736$sudo $pac upgrade -y
3837
38+ # ### Utils
39+ # Prerequisites
40+ $sudo env DEBIAN_FRONTEND=" noninteractive" $pac install -y gcc wget tar curl make xz-utils build-essential tzdata
41+
3942# ### Git
4043# Install git
4144$sudo $pac install -y git
4245
4346# ### Python
4447# Install tools needed to build python
45- $sudo env DEBIAN_FRONTEND= " noninteractive " $pac install -y curl gcc bzip2 sqlite zlib1g-dev libreadline-dev libsqlite3-dev libssl-dev tk-dev libffi-dev xz-utils make build-essential libbz2-dev wget llvm libncursesw5-dev libxml2-dev libxmlsec1-dev liblzma-dev
48+ $sudo $pac install -y bzip2 sqlite zlib1g-dev libreadline-dev libsqlite3-dev libssl-dev tk-dev libffi-dev libbz2-dev llvm libncursesw5-dev libxml2-dev libxmlsec1-dev liblzma-dev
4649# Install pyenv
47- if [[ ! -d $USER_ACCOUNT_HOME /.pyenv ]]; then
48- sudo -u " $USER_ACCOUNT " -i << 'EOF '
49- cd $HOME
50- curl https://pyenv.run | bash
50+ sudo -u " $USER_ACCOUNT " -i << 'EOF '
51+ if [[ ! -d "$HOME"/.pyenv ]]; then
52+ cd $HOME
53+ curl https://pyenv.run | bash
54+ touch "$HOME"/.bashrc
55+ # Remove initialization lines from .bashrc if they are already there, so we don't duplicate them
56+ # shellcheck disable=SC2016
57+ sed -i '/export PYENV_ROOT="$HOME\/.pyenv"/d' "$HOME"/.bashrc
58+ # shellcheck disable=SC2016
59+ sed -i '/command -v pyenv >\/dev\/null || export PATH="$PYENV_ROOT\/bin:$PATH"/d' "$HOME"/.bashrc
60+ # shellcheck disable=SC2016
61+ sed -i '/eval "$(pyenv init -)"/d' "$HOME"/.bashrc
62+ # shellcheck disable=SC2016
63+ sed -i '/eval "$(pyenv virtualenv-init -)"/d' "$HOME"/.bashrc
64+ # Add initialization lines to .bashrc
65+ # shellcheck disable=SC2016
66+ cat <<'EOT' | cat - "$HOME"/.bashrc > temp && mv temp "$HOME"/.bashrc
67+ export PYENV_ROOT="$HOME/.pyenv"
68+ command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
69+ eval "$(pyenv init -)"
70+ eval "$(pyenv virtualenv-init -)"
71+ EOT
72+ # install python
73+ source "$HOME"/.bashrc
74+ pyenv install 3.8.15
75+ fi
5176EOF
52- # Remove initialization lines from .bashrc if they are already there, so we don't duplicate them
53- # shellcheck disable=SC2016
54- sed -i ' /export PYENV_ROOT="$HOME\/.pyenv"/d' " $USER_ACCOUNT_HOME " /.bashrc
55- # shellcheck disable=SC2016
56- sed -i ' /command -v pyenv >\/dev\/null || export PATH="$PYENV_ROOT\/bin:$PATH"/d' " $USER_ACCOUNT_HOME " /.bashrc
57- # shellcheck disable=SC2016
58- sed -i ' /eval "$(pyenv init -)"/d' " $USER_ACCOUNT_HOME " /.bashrc
59- # shellcheck disable=SC2016
60- sed -i ' /eval "$(pyenv virtualenv-init -)"/d' " $USER_ACCOUNT_HOME " /.bashrc
61- # Add initialization lines to .bashrc
62- # shellcheck disable=SC2016
63- sed -i ' 1ieval "$(pyenv virtualenv-init -)"' " $USER_ACCOUNT_HOME " /.bashrc
64- # shellcheck disable=SC2016
65- sed -i ' 1ieval "$(pyenv init -)"' " $USER_ACCOUNT_HOME " /.bashrc
66- # shellcheck disable=SC2016
67- sed -i ' 1icommand -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' " $USER_ACCOUNT_HOME " /.bashrc
68- # shellcheck disable=SC2016
69- sed -i ' 1iexport PYENV_ROOT="$HOME/.pyenv"' " $USER_ACCOUNT_HOME " /.bashrc
70- # install python
71- sudo -u " $USER_ACCOUNT " -i << 'EOF '
72- pyenv install 3.8.15
73- EOF
74- fi
7577
7678# ### OpenCV dependencies
7779$sudo $pac install -y libgl1
0 commit comments