Skip to content

Instantly share code, notes, and snippets.

@jurihock
Last active February 23, 2022 23:27
Show Gist options
  • Save jurihock/824a9c3ac23e47a619aaa4b11b74e200 to your computer and use it in GitHub Desktop.
Save jurihock/824a9c3ac23e47a619aaa4b11b74e200 to your computer and use it in GitHub Desktop.
The Littlest JupyterHub: Share data with existing users
#!/bin/bash
# The official tutorial describes how to create shared folders for new users:
# https://tljh.jupyter.org/en/latest/howto/content/share-data.html
# But it still doesn't reflect how to propagate any new shared folders to existing users.
# This script features an example for the missing task.
if [[ $(id -u) -ne 0 ]]
then
echo "Please run me as root again..."
exit 1
fi
# Shared folder names:
INBOX=Inbox
OUTBOX=Outbox
# Shared folder permissions:
# INBOX -> teacher (w) students (r)
# OUTBOX -> teacher (r) students (w)
create() {
# Creates shared folders and sets desired permissions
mkdir -vp /srv/data/${INBOX}
mkdir -vp /srv/data/${OUTBOX}
chown -v root:jupyterhub-admins /srv/data/${INBOX}
chown -v root:jupyterhub-users /srv/data/${OUTBOX}
chmod -v u=rwx,g=rwxs,o=rx /srv/data/${INBOX}
chmod -v u=rwx,g=rwxs,o=rx /srv/data/${OUTBOX}
rm -vrf /etc/skel/${INBOX}
rm -vrf /etc/skel/${OUTBOX}
ln -vs /srv/data/${INBOX} /etc/skel/${INBOX}
ln -vs /srv/data/${OUTBOX} /etc/skel/${OUTBOX}
}
link() {
# Links shared folders in existing user account
USER=$(basename "${1}")
rm -vrf /home/${USER}/${INBOX}
rm -vrf /home/${USER}/${OUTBOX}
su - ${USER} -c "ln -vs /srv/data/${INBOX} /home/${USER}/${INBOX}"
su - ${USER} -c "ln -vs /srv/data/${OUTBOX} /home/${USER}/${OUTBOX}"
}
create
find /home -type d -name 'jupyter-*' -prune | while read USER
do
echo
link ${USER}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment