diff --git a/home/.chezmoiscripts/universal/run_onchange_after_07-docker-plugins.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_07-docker-plugins.tmpl index ad90f70f..da06e60f 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_07-docker-plugins.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_07-docker-plugins.tmpl @@ -6,30 +6,8 @@ {{ includeTemplate "universal/profile" }} {{ includeTemplate "universal/logg" }} -### Docker Clip -if [ -f "${XDG_CONFIG_HOME:-$HOME/.docker}/cli-plugins/docker-clip" ]; then - logg info 'Adding Docker clip commands. For more details check out https://github.com/lukaszlach/clip/' - docker clip add || EXIT_CODE=$? - if [ -n "$EXIT_CODE" ]; then - logg error 'Failed to run `docker clip add`' - fi -fi - -### Docker Convoy -if [ ! -f /etc/docker/plugins/convoy.spec ]; then - logg info 'Adding the Docker Convoy plugin' - sudo mkdir -p /etc/docker/plugins - sudo bash -c 'echo "unix:///var/run/convoy/convoy.sock" > /etc/docker/plugins/convoy.spec' - cd "$HOME/.local/src" - tar xvzf convoy.tar.gz - sudo cp convoy/convoy convoy/convoy-pdata_tools /usr/local/bin/ - rm -rf convoy -else - logg info 'Docker Convoy already added at /etc/docker/plugins/convoy.spec' -fi - ### Docker push-rm -if [ ! -f "${XDG_CONFIG_HOME:-$HOME/.docker}/cli-plugins/docker-pushrm" ]; then +if [ ! -f "${XDG_CONFIG_HOME:-$HOME/.config}/docker/cli-plugins/docker-pushrm" ]; then logg info 'Acquiring release information for Docker push-rm' RELEASE_TAG="$(curl -sSL https://api.github.com/repos/christian-korneck/docker-pushrm/releases/latest | jq -r '.tag_name')" mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/docker/cli-plugins" @@ -41,15 +19,20 @@ else logg info 'Docker push-rm already added' fi -{{- if and (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "key-digitalocean-pat")) -}} -### Docker DigitalOcean Block Storage -docker plugin install --grant-all-permissions rexray/dobs DOBS_TOKEN={{ includeTemplate "secrets/key-digitalocean-pat" | decrypt -}} DOBS_REGION={{ .host.docker.doRegion }} LINUX_VOLUME_FILEMODE=0775 -{{ end -}} +### Docker Rclone plugin +# Source: https://rclone.org/docker/ +if [ ! -d /var/lib/docker-plugins/rclone/config ]; then + logg info 'Creating directory /var/lib/docker-plugins/rclone/config' + sudo mkdir -p /var/lib/docker-plugins/rclone/config +fi +if [ ! -d /var/lib/docker-plugins/rclone/cache ]; then + logg info 'Creating directory /var/lib/docker-plugins/rclone/cache' + sudo mkdir -p /var/lib/docker-plugins/rclone/cache +fi +sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/docker-rclone.conf /var/lib/docker-plugins/rclone/config/rclone.conf +if ! docker plugin ls | grep 'rclone:latest' > /dev/null; then + docker plugin install rclone/docker-volume-rclone:amd64 args="-v" --alias rclone --grant-all-permissions +fi -### Docker plugins (defined in ~/.config/docker/plugins.json) -jq -r '.plugins[]' "${XDG_CONFIG_HOME:-$HOME/.config}/docker/plugins.json" | while read PLUGIN; do - logg info 'Installing the `'"$PLUGIN"'` Docker plugin' - docker plugin install --grant-all-permissions "$PLUGIN" -done {{ end -}} diff --git a/home/.chezmoiscripts/universal/run_onchange_after_50-rclone.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_50-rclone.tmpl index ee0caf5d..8bfb5ea1 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_50-rclone.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_50-rclone.tmpl @@ -4,18 +4,16 @@ {{ includeTemplate "universal/profile" }} {{ includeTemplate "universal/logg" }} -if rclone -v rclone > /dev/null; then +if command -v rclone > /dev/null; then logg info 'Ensuring /var/cache/rclone exists' sudo mkdir -p /var/cache/rclone sudo chmod 700 /var/cache/rclone + sudo chown -Rf rclone:rclone /var/cache/rclone logg info 'Ensuring /var/log/rclone exists' sudo mkdir -p /var/log/rclone sudo chmod 700 /var/log/rclone - - logg info 'Ensuring /mnt/s3-docker exists' - sudo mkdir -p /mnt/s3-docker - sudo chmod 700 /mnt/s3-docker + sudo chown -Rf rclone:rclone /var/log/rclone logg info 'Adding ~/.local/bin/rclone-mount to /usr/local/bin' sudo cp -f "$HOME/.local/bin/rclone-mount" /usr/local/bin/rclone-mount @@ -25,13 +23,31 @@ if rclone -v rclone > /dev/null; then sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/rcloneignore" /etc/rcloneignore sudo chmod 644 /etc/rcloneignore - if [ -d /etc/systemd/system ]; then - logg info 'Adding Docker S3 rclone mount (available at /mnt/docker-s3)' - sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/s3-docker.service" /etc/systemd/system/docker-s3.service - logg info 'Enabling / restarting the S3 Docker mount' - sudo systemctl enable docker-s3 - sudo systemctl restart docker-s3 + logg info 'Adding ~/.config/rclone/system-rclone.conf to /etc/rclone.conf' + sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/system-rclone.conf /etc/rclone.conf + ### Add / configure service files + if [ -d /etc/systemd/system ]; then + find "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/system" -mindepth 1 -maxdepth 1 -type f | while read RCLONE_SERVICE; do + ### Add systemd service file + logg info "Adding S3 system mount service defined at $RCLONE_SERVICE" + FILENAME="$(basename "$RCLONE_SERVICE")" + SERVICE_ID="$(echo "$FILENAME" | sed 's/.service//')" + sudo cp -f "$RCLONE_SERVICE" "/etc/systemd/system/$(basename "$RCLONE_SERVICE")" + + ### Ensure mount folder is created + logg info "Ensuring /mnt/$SERVICE_ID is created with proper permissions" + sudo mkdir -p "/mnt/$SERVICE_ID" + sudo chmod 770 "/mnt/$SERVICE_ID" + sudo chown -Rf rclone:rclone "/mnt/$SERVICE_ID" + + ### Enable / restart the service + logg info "Enabling / restarting the $ S3 service" + sudo systemctl enable "$SERVICE_ID" + sudo systemctl restart "$SERVICE_ID" + done + + ### Add user Rclone mount logg info 'Adding user S3 rclone mount (available at ~/.local/mnt/s3)' sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/s3-user.service" "/etc/systemd/system/${USER}-s3.service" logg info 'Enabling / restarting the S3 user mount' diff --git a/home/Cloud/Private/remove_dot_gitkeep b/home/Cloud/Private/remove_dot_gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/home/Cloud/Public/remove_dot_gitkeep b/home/Cloud/Public/remove_dot_gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/home/Cloud/symlink_Private b/home/Cloud/symlink_Private new file mode 100644 index 00000000..7dea09f1 --- /dev/null +++ b/home/Cloud/symlink_Private @@ -0,0 +1,3 @@ +{{- if and (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "key-cloudflare-r2-id")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "key-cloudflare-r2-secret")) (ne .user.cloudflare.r2 "") -}} +/mnt/s3-private +{{- end -}} \ No newline at end of file diff --git a/home/Cloud/symlink_Public b/home/Cloud/symlink_Public new file mode 100644 index 00000000..8cca6475 --- /dev/null +++ b/home/Cloud/symlink_Public @@ -0,0 +1,3 @@ +{{- if and (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "key-cloudflare-r2-id")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "key-cloudflare-r2-secret")) (ne .user.cloudflare.r2 "") -}} +/mnt/s3-public +{{- end -}} \ No newline at end of file diff --git a/home/Cloud/symlink_User b/home/Cloud/symlink_User new file mode 100644 index 00000000..d71155b1 --- /dev/null +++ b/home/Cloud/symlink_User @@ -0,0 +1,3 @@ +{{- if and (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "key-cloudflare-r2-id")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "key-cloudflare-r2-secret")) (ne .user.cloudflare.r2 "") -}} +{{ .host.home }}/.local/mnt/s3 +{{- end -}} \ No newline at end of file diff --git a/home/dot_config/docker/plugins.json b/home/dot_config/docker/plugins.json deleted file mode 100644 index 28fff243..00000000 --- a/home/dot_config/docker/plugins.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugins" [ - "sapk/plugin-rclone", - "vieux/sshfs" - ] -} \ No newline at end of file diff --git a/home/dot_config/rclone/merge_private_rclone.conf b/home/dot_config/rclone/merge_private_rclone.conf new file mode 100644 index 00000000..68eeb860 --- /dev/null +++ b/home/dot_config/rclone/merge_private_rclone.conf @@ -0,0 +1,28 @@ +{{- if and (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "key-cloudflare-r2-id")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "key-cloudflare-r2-secret")) (ne .user.cloudflare.r2 "") -}} +#!/usr/bin/env bash + +CONFIG_FILE="$HOME/.config/rclone/rclone.conf" +if cat "$CONFIG_FILE" | grep '# MEGABYTE LABS MANAGED S3'; then + # TODO: Remove old block + START_LINE="$(echo `grep -n -m 1 "# MEGABYTE LABS MANAGED S3" .zshrc | cut -f1 -d ":"`)" + END_LINE="$(echo `grep -n -m 1 "# MEGABYTE LABS MANAGED S3" .zshrc | cut -f1 -d ":"`)" + if command -v gsed > /dev/null; then + gsed -i "$START_LINE,$END_LINEd" "$CONFIG_FILE" + else + sed -i "$START_LINE,$END_LINEd" "$CONFIG_FILE" + fi +fi + +tee -a "$CONFIG_FILE" > /dev/null < /dev/null; then - gsed -i "$START_LINE,$END_LINEd" "$CONFIG_FILE" - else - sed -i "$START_LINE,$END_LINEd" "$CONFIG_FILE" - fi -fi - -tee -a "$CONFIG_FILE" > /dev/null <