Last active
March 5, 2019 13:17
-
-
Save mlgrm/abf93779a3e8202d2b7b23ea8071f7a3 to your computer and use it in GitHub Desktop.
replace chrome os's default penguin lxc container with ubuntu 18.06 running docker.io and a few extras.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# usage: curl -sL bit.ly/mlgrm-penguin | [ KEY=value [...] ] bash | |
# keys: | |
# USER_NAME google user name. | |
# RCLONE_TOKEN (optional) valid token generated by rclone on the user's drive | |
# if provided, the home directory will be recovered from penguin/home/$USER_NAME | |
# and backups scheduled hourly | |
# the username must be the same as the google account name (i.e. the part before the @) | |
USER_NAME=${USER_NAME:-mlgrm} | |
[[ -z $RCLONE_TOKEN ]] && echo "RCLONE_TOKEN not set, so backups and recovery are disabled" | |
trap clean_up ERR SIGTERM SIGINT | |
clean_up () { | |
lxc rm penguin | |
lxc rename google penguin | |
lxc start penguin | |
} | |
# backup original google image if not already | |
lxc stop --force penguin | |
if lxc info google > /dev/null; then | |
lxc rm penguin | |
else lxc rename penguin google | |
fi | |
# create an ubuntu 18.04 docker host named penguin | |
curl -sL bit.ly/mlgrm-docker | HOST_NAME=penguin bash | |
# install chromium guest packages | |
curl -sL bit.ly/mlgrm-cros-guest | lxc exec penguin -- bash | |
# update the user and hostname (must be the same user name as the google account) | |
lxc exec penguin -- bash <<EOF | |
echo 'penguin' > /etc/hostname | |
killall -u ubuntu | |
groupmod -n $USER_NAME ubuntu | |
usermod -md /home/$USER_NAME -l $USER_NAME ubuntu | |
usermod -aG users $USER_NAME | |
loginctl enable-linger $USER_NAME | |
sed -i "s/ubuntu/$USER_NAME/" /etc/sudoers.d/90-cloud-init-users | |
reboot | |
EOF | |
# run rstudio (tidyverse) as a docker image | |
curl -sL bit.ly/mlgrm-rstudio | DOCKER_HOST=penguin USER=$USER_NAME bash | |
# install rclone | |
curl https://rclone.org/install.sh | lxc exec penguin -- bash | |
if [[ -n $RCLONE_TOKEN ]]; then | |
lxc exec penguin -- mkdir -p /home/$USER_NAME/.config/rclone | |
lxc exec penguin -- dd of=/home/$USER_NAME/.config/rclone/rclone.conf conv=notrunc <<EOF | |
[home] | |
type = drive | |
scope = drive.file | |
token = $RCLONE_TOKEN | |
EOF | |
# restore home from google drive, in the background | |
lxc exec penguin -- su -c "rclone sync -q home:penguin/home/$USER_NAME /home/$USER_NAME &" - $USER_NAME | |
# backup home cronjob | |
lxc exec penguin -- dd of=/etc/cron.d/rclone conv=notrunc <<EOF | |
# cron.d/rclone keep home directory synched with google drive | |
31 * * * * $USER_NAME /usr/bin/rclone sync /home/$USER_NAME home:penguin/home/$USER_NAME | |
EOF | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment