Skip to content

Instantly share code, notes, and snippets.

@fauxneticien
Last active October 25, 2017 12:45
Show Gist options
  • Save fauxneticien/334075f940ef8f97bc3c39e167e0bdb2 to your computer and use it in GitHub Desktop.
Save fauxneticien/334075f940ef8f97bc3c39e167e0bdb2 to your computer and use it in GitHub Desktop.
Generate shell script to add 50 users into rocker/verse
# Generates a script ~/init_users.sh, which when run
# adds 50 users who can log into the Docker image running rocker/verse
# https://hub.docker.com/r/rocker/verse/
library(purrr)
library(stringr)
install.packages("glue")
library(glue)
1:50 %>% # Generate numbers 1, 2, 3, ..., 50, then
map_chr( # for each number (e.g. 1), map
~ str_pad(string = ., pad = "0", width = 2, side = "left") %>% # 1 => "01"
paste0("ruser", .) %>% # "01" => "ruser01"
glue(username = ., # "ruser01" => "useradd ... rstudio-server ruser01"
'useradd -m -c "{username}" {username} -s /bin/bash',
"; echo '{username}:{username}' | chpasswd",
"; usermod -a -G rstudio-server {username}"
)
) %>%
writeLines("~/init_users.sh") # 'useradd -m -c "ruser01" ... rstudio-server ruser50'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment