Skip to content

Commit 845c7ce

Browse files
Helper script
1 parent 932437b commit 845c7ce

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

scripts/setup.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
#====================================================================================
3+
# Author: Mohammad Zain Abbas
4+
# Date: 29th April, 2022
5+
#====================================================================================
6+
# This script is used to set up the enviorment & installations
7+
#====================================================================================
8+
9+
# Enable exit on error
10+
set -e -u -o pipefail
11+
12+
log () {
13+
echo "[[ log ]] $1"
14+
}
15+
16+
error () {
17+
echo "[[ error ]] $1"
18+
}
19+
20+
#Function that shows usage for this script
21+
function usage()
22+
{
23+
cat << HEREDOC
24+
Setup for SDM Lab 2 @ UPC
25+
Usage:
26+
27+
$progname [OPTION] [Value]
28+
Options:
29+
-h, --help Show usage
30+
Examples:
31+
$ $progname
32+
⚐ → Installs all dependencies for your SDM Lab 2
33+
HEREDOC
34+
}
35+
36+
progname=$(basename $0)
37+
env_name='pyspark_env'
38+
39+
#Get all the arguments and update accordingly
40+
while [[ "$#" -gt 0 ]]; do
41+
case $1 in
42+
-h|--help)
43+
usage
44+
exit 1
45+
;;
46+
*) printf "\n$progname: invalid option → '$1'\n\n⚐ Try '$progname -h' for more information\n\n"; exit 1 ;;
47+
esac
48+
shift
49+
done
50+
51+
install_brew() {
52+
if [ ! $(type -p brew) ]; then
53+
error "'brew' not found. Installing it now ..."
54+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
55+
else
56+
log "'brew' found ..."
57+
fi
58+
}
59+
60+
install_apache_spark() {
61+
if [ ! $(type -p spark-submit) ]; then
62+
error "'apache-spark' not found. Installing it now ..."
63+
brew install apache-spark
64+
else
65+
log "'apache-spark' found ..."
66+
fi
67+
}
68+
69+
conda_init() {
70+
conda init --all || error "Unable to conda init ..."
71+
if [[ $SHELL == *"zsh"* ]]; then
72+
. ~/.zshrc
73+
elif [[ $SHELL == *"bash"* ]]; then
74+
. ~/.bashrc
75+
else
76+
error "Please restart your shell to see effects"
77+
fi
78+
}
79+
80+
install_conda() {
81+
if [ ! $(type -p conda) ]; then
82+
error "'anaconda' not found. Installing it now ..."
83+
brew install --cask anaconda && conda_init
84+
else
85+
log "'anaconda' found ..."
86+
fi
87+
}
88+
89+
create_conda_env() {
90+
conda create -n $env_name python=3.8 pandas -y || error "Unable to create new env '$env_name' ..."
91+
conda activate $env_name &> /dev/null || echo "" > /dev/null
92+
pip install pyspark > /dev/null
93+
}
94+
95+
log "Starting Setup Service"
96+
97+
install_brew
98+
install_apache_spark
99+
install_conda
100+
create_conda_env
101+
102+
log "All done !!"

0 commit comments

Comments
 (0)