#! /bin/bash

apt install --yes python3 python3-pip
pip3 install jupyter

read -p "Do you want to start Jupyter at boot? [N/y]: " ANS

[[ -z $ANS ]] && ANS="n"
IP=$(ip a | grep 192.168 | sed 's/\/.*//g' | sed 's/.*\ //g')

if [[ $ANS = "y" ]] || [[ $ANS == "Y" ]]; then
	cat > /etc/systemd/system/jupyter.service <<-EOF
	[Unit]
	Description=Jupyter server

	[Service]
	ExecStart=/usr/local/bin/jupyter notebook --allow-root --ip='0.0.0.0'
	WorkingDirectory=/root
	type=simple

	[Install]
	WantedBy=multi-user.target
	EOF

	systemctl enable --now jupyter

	echo To get your authentication token run \"systemctl status jupyter\"
	echo To get a new authentication token run \"systemctl restart jupyter\" and then the previous command
	echo To stop starting jupyter at boot, run \"systemctl disable --now jupyter\". You can then start it with \"jupyter notebook --ip='0.0.0.0' --allow-root\"
	echo You can now access jupyter at $IP:8888
else
	echo To start jypter run \"jupyter notebook --ip='0.0.0.0' --allow-root\"
	echo After starting jupyter you can access it at $IP:8888
fi
