Skip to content

Commit

Permalink
Update rstudio
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalan authored Jul 5, 2024
1 parent bab53ba commit 91c0bcb
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions opt/cs50/bin/rstudio
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function spin() {
local spinner='|/-\'
while [ -d /proc/$pid ]; do
for i in $(seq 0 3); do
printf "\rHit CTRL-C to stop the server [%c]\n" "${spinner:$i:1}"
sleep 0.1
printf "\rHit CTRL-C to stop the server [%c] " "${spinner:$i:1}"
sleep 0.5
done
done
printf "\r \r"
printf "\n"
}

# Check for $1
Expand All @@ -33,14 +33,17 @@ if [[ $# -eq 1 ]]; then
fi

# Check for running image
id=$(docker ps --filter "name=rstudio" --quiet)
id=$(docker ps --all --filter "name=rstudio" --quiet)
if [[ -n "$id" ]]; then

# Stop current container (so as to restart port forwarding)
docker stop "$id"
docker stop "$id" > /dev/null

# Try to remove in case created but somehow not started
docker rm "$id" &> /dev/null
fi

# Pull image
# Pull latest image
docker pull "$IMAGE"

# Create container
Expand All @@ -51,24 +54,24 @@ docker create \
--publish 8787:8787 \
--rm \
--volume "$LOCAL_WORKSPACE_FOLDER":"/workspaces/$RepositoryName" \
rocker/tidyverse
rocker/tidyverse > /dev/null

# Customize rstudio-prefs.json
jq ".initial_working_directory = \"/workspaces/$RepositoryName\"" /opt/cs50/lib/rstudio/rstudio-prefs.json > /tmp/rstudio-prefs.json

# Copy files into container
docker cp /opt/cs50/lib/rstudio/_icons.css rstudio:/tmp
docker cp /opt/cs50/lib/rstudio/rstudio-server.json rstudio:/etc/rstudio/
docker cp /tmp/rstudio-prefs.json rstudio:/etc/rstudio/
docker cp --quiet /opt/cs50/lib/rstudio/_icons.css rstudio:/tmp
docker cp --quiet /opt/cs50/lib/rstudio/rstudio-server.json rstudio:/etc/rstudio/
docker cp --quiet /tmp/rstudio-prefs.json rstudio:/etc/rstudio/

# Start container
docker start rstudio
docker start rstudio > /dev/null

# Inject CSS
docker exec rstudio sh -c "cat /tmp/_icons.css >> /usr/lib/rstudio-server/www/css/icons.css"

# Attach to container
docker attach rstudio &
docker attach rstudio &> /dev/null &
pid=$!

# Spin until container stops
Expand Down

0 comments on commit 91c0bcb

Please sign in to comment.