From 8aa293835d64d7d9bea1d25eaee08f58ef51558a Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Thu, 13 Apr 2023 22:20:38 +0000 Subject: [PATCH] Update 3 files - /home/dot_local/Taskfile-local.yml - /home/dot_config/task/Taskfile.yml - /home/.chezmoiscripts/universal/run_onchange_after_40-firefox.sh.tmpl --- .../run_onchange_after_40-firefox.sh.tmpl | 1 + home/dot_config/task/Taskfile.yml | 246 ++++++++++++++++++ home/dot_local/Taskfile-local.yml | 224 ---------------- 3 files changed, 247 insertions(+), 224 deletions(-) create mode 100644 home/dot_config/task/Taskfile.yml delete mode 100644 home/dot_local/Taskfile-local.yml diff --git a/home/.chezmoiscripts/universal/run_onchange_after_40-firefox.sh.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_40-firefox.sh.tmpl index 7165e483..29f53955 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_40-firefox.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_40-firefox.sh.tmpl @@ -37,6 +37,7 @@ # # * The Firefox Profile Switcher is only compatible with Firefox and not LibreWolf # * This script is only designed to properly provision profiles on a fresh installation (so it does not mess around with pre-existing / already configured profiles) +# * Additional profiles for LibreWolf are not added because the Firefox Profile Switcher is not compatible with LibreWolf # # ## Links # diff --git a/home/dot_config/task/Taskfile.yml b/home/dot_config/task/Taskfile.yml new file mode 100644 index 00000000..598f9bc1 --- /dev/null +++ b/home/dot_config/task/Taskfile.yml @@ -0,0 +1,246 @@ +--- +# @file System Taskfile Commands +# @brief Defines commands provided by the Install Doctor CLI system +# @description +# The tasks / commands defined in this `Taskfile.yml` are all accessible by using the `task-menu` command. +# `task-menu` is a custom fork created to make browsing through various post-provisioning commands easier +# after setting up a device with Install Doctor. For each of the command below, you can run `task-menu command-name` +# to directly invoke the task. Alternatively, you can simply run `task-menu` from anywhere on the device to open +# an interactive command menu. +# +# ## Documentation +# +# The documentation for each command is defined in this file under the `summary` key. If a command has a `summary` defined +# then, our documentation system will automatically integrate the documentation into our documentation portal. The +# Install Doctor CLI (which is defined in this file) is available for viewing [here](https://install.doctor/docs/cli). + +version: '3' + +tasks: + bitwarden: + cmds: + - | + ### Command to copy to clipboard + COPY="wl-copy" + ### Get list of all logins as json + logins="$(bw list items)" + ### Grab the name of every login and pip them into fzf + name="$(echo "$logins" | jq -r '.[].name' | fzf)" + ### Find the login with the selected name (as a json) + selected="$(echo "$logins" | jq -r ".[] | select(.name == \"$name\")")" + ### Print the name of the selected login + echo "Name: $(echo "$selected" | jq -r '.name')" + echo "> Copying Username" + ### Copy the username to the clipboard + printf '%s' "$(echo "$selected" | jq -r '.login.username')" | $COPY + echo "Press any key to copy password..." + ### Wait for user input before coping the password + read -r + echo "> Copying Password" + ### Copy the password to the clipboard + printf '%s' "$(echo "$selected" | jq -r '.login.password')" | $COPY + + brave:profile:backup: + cmds: + - task: profile:backup + vars: + AppName: Brave Browser + ProfileFolder: ~/Library/Application Support/BraveSoftware/Brave-Browser/Default + RcloneRepository: brave + + brave:profile:restore: + cmds: + - task: profile:restore + vars: + AppFolder: /Applications/Brave Browser.app + AppName: Brave Browser + ProfileFolder: ~/Library/Application Support/BraveSoftware/Brave-Browser/Default + RcloneRepository: brave + + chrome:profile:backup: + cmds: + - task: profile:backup + vars: + AppName: Chrome + ProfileFolder: ~/Library/Application Support/Google/Chrome/Default + RcloneRepository: chrome + + chrome:profile:restore: + cmds: + - task: profile:restore + vars: + AppFolder: /Applications/Google Chrome.app + AppName: Google Chrome + ProfileFolder: ~/Library/Application Support/Google/Chrome/Default + RcloneRepository: chrome + + edge:profile:backup: + cmds: + - task: profile:backup + vars: + AppName: Microsoft Edge + ProfileFolder: ~/Library/Application Support/Microsoft Edge/Default + RcloneRepository: edge + + edge:profile:restore: + cmds: + - task: profile:restore + vars: + AppFolder: /Applications/Microsoft Edge.app + AppName: Microsoft Edge + ProfileFolder: ~/Library/Application Support/Microsoft Edge/Default + RcloneRepository: edge + + ferdium:profile:backup: + desc: Imports the user's Ferdium profile from the CloudFlare R2 Restic repository for Ferdium + summary: | + # Ferdium Profile Backup + + This command backups the Ferdium profile to the S3-backed Restic repository, if the profile exists. If the repository + has not been initialized then it will initialize it. After you backup the profile, you can restore it with the + `ferdium:profile:restore` command. + + The Ferdium backup is encrypted with the same key that Chezmoi uses (stored in `~/.config/age/chezmoi.txt`, by default). + The backup uses Restic so all the functionality that Restic offers is available with backups made by this command. + cmds: + - task: profile:backup + vars: + AppName: Ferdium + ProfileFolder: ~/Library/Application Support/Ferdium + RcloneRepository: ferdium + + ferdium:profile:restore: + desc: Imports the user's Ferdium profile from the CloudFlare R2 Restic repository for Ferdium + summary: | + # Ferdium Profile Import + + This command imports the Ferdium profile from the Restic repository if it exists. In order to use this + command for the first time, you should initialize Ferdium by opening the application. Then, after making + any changes you wish to be saved, you should backup the Ferdium profile to the CloudFlare R2 user bucket + by running the `ferdium:profile:import` task first. + + The Ferdium backup is encrypted with the same key that Chezmoi uses (stored in `~/.config/age/chezmoi.txt`, by default). + The backup uses Restic so all the functionality that Restic offers is available with backups made by this command. + cmds: + - task: profile:restore + vars: + AppFolder: /Applications/Ferdium.app + AppName: Ferdium + ProfileFolder: ~/Library/Application Support/Ferdium + RcloneRepository: ferdium + + firefox:profile:backup: + cmds: + - task: profile:backup + vars: + AppName: Firefox + ProfileFolder: ~/Library/Application Support/Firefox/Profiles/profile.private + RcloneRepository: firefox + + firefox:profile:restore: + cmds: + - task: profile:restore + vars: + AppFolder: /Applications/Firefox.app + AppName: Firefox + ProfileFolder: ~/Library/Application Support/Firefox/Profiles/profile.private + RcloneRepository: firefox + + font-test: + cmds: + - | + echo -en "Regular" + echo -en "\e[3m Italic \e[0m" + echo -en "\e[1m Bold \e[0m" + echo -en "\e[3m\e[1m Bold-Italic \e[0m" + echo -en " \e[4mUnderline\e[0m " + echo -e " \e[9mStrikethrough\e[0m" + + librewolf:profile:backup: + cmds: + - task: profile:backup + vars: + AppName: LibreWolf + ProfileFolder: ~/Library/Application Support/LibreWolf/Profiles/profile.default + RcloneRepository: librewolf + + librewolf:profile:restore: + cmds: + - task: profile:restore + vars: + AppFolder: /Applications/LibreWolf.app + AppName: LibreWolf + ProfileFolder: ~/Library/Application Support/LibreWolf/Profiles/profile.default + RcloneRepository: librewolf + + profile:backup: + cmds: + - | + if [ -d "{{ .ProfileFolder }}" ]; then + if [ -d "$HOME/.local/mnt/s3" ]; then + if command -v rclone > /dev/null && command -v restic > /dev/null; then + logg info '{{ .AppName }} profile folder exists and user S3 mount exists. Backing the profile up to user S3 bucket via Restic.' + if ([ -z "$(restic -r "rclone:$USER-s3:user/{{ .RcloneRepository }}" --password-file "$HOME/.config/age/chezmoi.txt" cat config)" ]) 2>/dev/null; then + logg info 'Initializing {{ .AppName }} Restic repository' + restic -r "rclone:$USER-s3:user/{{ .RcloneRepository }}" --password-file "$HOME/.config/age/chezmoi.txt" init + fi + restic -r "rclone:$USER-s3:user/{{ .RcloneRepository }}" --password-file "$HOME/.config/age/chezmoi.txt" --verbose backup --tag "{{ .ProfileFolder }}" --tag {{ OS }} --tag "$HOST" "{{ .ProfileFolder }}" + else + logg error 'Both `rclone` and `restic` must be available' && exit 1 + fi + else + logg error 'User S3 bucket mount is unavailable. The presence of this folder is used to detect whether or not the user S3 Rclone configuration is in place.' && exit 1 + fi + else + logg warn 'The {{ .ProfileFolder }} folder does not exist. Skipping.' + fi + + profile:restore: + cmds: + - | + if [ -d '{{ .AppFolder }}' ]; then + if [ -d "$HOME/.local/mnt/s3" ]; then + if command -v rclone > /dev/null && command -v restic > /dev/null; then + if ([ -z "$(restic -r "rclone:$USER-s3:user/{{ .RcloneRepository }}" --password-file "$HOME/.config/age/chezmoi.txt" cat config)" ]) 2>/dev/null; then + logg warn 'The {{ .AppName }} Rclone repository has not been initialized. Skipping.' + else + restic -r "rclone:$USER-s3:user/{{ .RcloneRepository }}" --password-file "$HOME/.config/age/chezmoi.txt" restore latest --target '{{ .ProfileFolder }}' + fi + else + logg error 'Both `rclone` and `restic` must be available' && exit 1 + fi + else + logg error 'User S3 bucket mount is unavailable. The presence of this folder is used to detect whether or not the user S3 Rclone configuration is in place.' && exit 1 + fi + else + logg info 'The {{ .AppFolder }} folder that is used to detect the presence of {{ .AppName }} on the system is not present so the profile will not be restored for this type of {{ .AppName }} install.' + fi + + squash-symlink: + summary: | + This command, when used in conjunction with the `find` command, will scan through a directory + and convert any symlinks into regular files by copying their source over the initial symlink. + + **Example usage:** + + ``` + find . -type l -exec 'run squash-symlink --' {} + + ``` + cmds: + - | + set -e + for link; do + test -h "$link" || continue + dir=$(dirname "$link") + reltarget=$(readlink "$link") + case $reltarget in + /*) abstarget=$reltarget;; + *) abstarget=$dir/$reltarget;; + esac + rm -fv "$link" + cp -afv "$abstarget" "$link" || { + ### On failure, restore the symlink + rm -rfv "$link" + ln -sfv "$reltarget" "$link" + } + done diff --git a/home/dot_local/Taskfile-local.yml b/home/dot_local/Taskfile-local.yml deleted file mode 100644 index 06b7e62f..00000000 --- a/home/dot_local/Taskfile-local.yml +++ /dev/null @@ -1,224 +0,0 @@ ---- -version: '3' - -# This is your local Taskfile.yml file. You can define tasks and scripts while leveraging some of the nifty -# features of https://taskfile.dev. You can safely place your scripts here and they will be combined with -# a veteran stack of Taskfile.yml files. You can access the tasks defined here by running -# `task local:default` for example. You must keep all the tasks in this file without including other files -# because the main Taskfile.yml is a symlinked one. Anyway, try `task local:default`. -tasks: - bitwarden: - cmds: - - | - # Command to copy to clipboard - COPY="wl-copy" - # Get list of all logins as json - logins="$(bw list items)" - # Grab the name of every login and pip them into fzf - name="$(echo "$logins" | jq -r '.[].name' | fzf)" - # Find the login with the selected name (as a json) - selected="$(echo "$logins" | jq -r ".[] | select(.name == \"$name\")")" - # Print the name of the selected login - echo "Name: $(echo "$selected" | jq -r '.name')" - echo "> Copying Username" - # Copy the username to the clipboard - printf '%s' "$(echo "$selected" | jq -r '.login.username')" | $COPY - echo "Press any key to copy password..." - # Wait for user input before coping the password - read -r - echo "> Copying Password" - # Copy the password to the clipboard - printf '%s' "$(echo "$selected" | jq -r '.login.password')" | $COPY - - browser:profile:save:brave: - vars: - BrowserProfile: > - {{if eq OS "darwin"}}~/Library/Application\ Support/BraveSoftware/Brave-Browser/Default{{end}} - {{if eq OS "linux"}}{{end}} - {{if eq OS "windows"}}{{end}} - cmds: - - tar -czpf ~/brave-profile.tar.gz {{.BrowserProfile}} - - browser:profile:save:chrome: - vars: - BrowserProfile: > - {{if eq OS "darwin"}}~/Library/Application\ Support/BraveSoftware/Brave-Browser/Default{{end}} - {{if eq OS "linux"}}{{end}} - {{if eq OS "windows"}}{{end}} - cmds: - - tar -czpf ~/brave-profile.tar.gz {{.BrowserProfile}} - - browser:profile:save:edge: - vars: - BrowserProfile: > - {{if eq OS "darwin"}}~/Library/Application\ Support/BraveSoftware/Brave-Browser/Default{{end}} - {{if eq OS "linux"}}{{end}} - {{if eq OS "windows"}}{{end}} - cmds: - - tar -czpf ~/brave-profile.tar.gz {{.BrowserProfile}} - - browser:profile:save:firefox: - vars: - BrowserProfile: > - {{if eq OS "darwin"}}~/Library/Application\ Support/BraveSoftware/Brave-Browser/Default{{end}} - {{if eq OS "linux"}}{{end}} - {{if eq OS "windows"}}{{end}} - cmds: - - tar -czpf ~/brave-profile.tar.gz {{.BrowserProfile}} - - default: echo "Get started on https://taskfile.dev" - font-test: - cmds: - - | - echo -en "Regular" - echo -en "\e[3m Italic \e[0m" - echo -en "\e[1m Bold \e[0m" - echo -en "\e[3m\e[1m Bold-Italic \e[0m" - echo -en " \e[4mUnderline\e[0m " - echo -e " \e[9mStrikethrough\e[0m" - - ferdium:profile:backup: - desc: Imports the user's Ferdium profile from the CloudFlare R2 Restic repository for Ferdium - summary: | - # Ferdium Profile Backup - - This command backups the Ferdium profile to the S3-backed Restic repository, if the profile exists. If the repository - has not been initialized then it will initialize it. After you backup the profile, you can restore it with the - `ferdium:profile:restore` command. - - The Ferdium backup is encrypted with the same key that Chezmoi uses (stored in `~/.config/age/chezmoi.txt`, by default). - The backup uses Restic so all the functionality that Restic offers is available with backups made by this command. - cmds: - - | - for FERDIUM_PROFILE in "~/Library/Application Support/Ferdium"; do - if [ -d '{{ .FerdiumProfile }}' ]; then - if [ -d ~/.local/mnt/s3 ]; then - if command -v rclone > /dev/null && command -v restic > /dev/null; then - logg info 'Ferdium profile folder exists and user S3 mount exists. Backing the profile up to user S3 bucket.' - if ([ -z "$(restic -r "rclone:$USER-s3:user/ferdium" --password-file "$HOME/.config/age/chezmoi.txt" cat config)" ]) 2>/dev/null; then - logg info 'Initializing Ferdium Restic repository' - restic -r "rclone:$USER-s3:user/ferdium" --password-file "$HOME/.config/age/chezmoi.txt" init - fi - restic -r "rclone:$USER-s3:user/ferdium" --password-file "$HOME/.config/age/chezmoi.txt" --verbose backup --tag "$FERDIUM_PROFILE" --tag {{ OS }} --tag "$HOST" "$FERDIUM_PROFILE" - else - logg warn 'Both `rclone` and `restic` must be available' - fi - else - logg warn 'User S3 bucket mount is unavailable' - fi - else - logg warn 'The Ferdium profile folder does not exist yet. You must run the Ferdium app to generate an initialial profile.' - fi - done - - ferdium:profile:restore: - desc: Imports the user's Ferdium profile from the CloudFlare R2 Restic repository for Ferdium - summary: | - # Ferdium Profile Import - - This command imports the Ferdium profile from the Restic repository if it exists. In order to use this - command for the first time, you should initialize Ferdium by opening the application. Then, after making - any changes you wish to be saved, you should backup the Ferdium profile to the CloudFlare R2 user bucket - by running the `ferdium:profile:import` task first. - - The Ferdium backup is encrypted with the same key that Chezmoi uses (stored in `~/.config/age/chezmoi.txt`, by default). - The backup uses Restic so all the functionality that Restic offers is available with backups made by this command. - cmds: - - | - ### Detect Ferdium profile location - if [ -d "/Applications/Ferdium.app" ]; then - FERDIUM_PROFILE="$HOME/Library/Application Support/Ferdium" - fi - - ### Restore Ferdium profile - if [ -d ~/.local/mnt/s3 ]; then - if command -v rclone > /dev/null && command -v restic > /dev/null; then - logg info 'Ferdium profile folder exists and user S3 mount exists. Restoring the profile from the user S3 bucket.' - restic -r "rclone:$USER-s3:user/ferdium" --password-file "$HOME/.config/age/chezmoi.txt" restore latest --target "$FERDIUM_PROFILE" - else - logg warn 'Both `rclone` and `restic` must be available' - fi - else - logg warn 'User S3 bucket mount is unavailable' - fi - - provision: - desc: Provision the environment - summary: | - # Provision the Environment - - This task will provision the current environment using a variety of tools. - It will prompt you for details like what type of environment you are provisioning. - Optionally, you can skip the prompt by passing a CLI argument like so: - - **Example:** - `run localhost:provision -- terminal` - - The above example will run the `localhost:provision:terminal` task. - cmds: - - | - if [ "{{.CLI_ARGS}}" != "" ]; then - run localhost:provision:{{.CLI_ARGS}} - else - run localhost:provision:prompt - fi - - provision:dev: - deps: - - :install:software:bundle - - provision:terminal - cmds: - - brew bundle --file "$HOME/.local/Brewfile.dev" - - provision:full: - deps: - - :install:software:bundle - - provision:dev - cmds: - - brew bundle --file "$HOME/.local/Brewfile.full" - - provision:prompt: - deps: - - :install:software:gum - cmds: - - logg prompt 'Select the type of environment you would like to provision' - - logg prompt '`Terminal` - Installs standard CLI tools that augment the terminal experience' - - logg prompt '`Development` - Provisions Terminal and also installs useful tools for development' - - logg prompt '`Full` - Provisions with both Terminal and Development and then it installs all the Brewfile-supported software from the Gas Station project (e.g. https://gitlab.com/megabyte-labs/gas-station).' - - | - CHOICE="$(logg choose "Terminal" "Development" "Full")" - if [ "$CHOICE" = 'Development' ]; then - run localhost:provision:dev - elif [ "$CHOICE" = 'Terminal' ]; then - run localhost:provision:terminal - elif [ "$CHOICE" = 'Full' ]; then - run localhost:provision:full - fi - - provision:terminal: - deps: - - :install:software:bundle - cmds: - - brew bundle --file "$HOME/.local/Brewfile.terminal" - - squash-symlink: - summary: | - Example: find . -type l -exec /path/tos/script {} + - cmds: - - | - set -e - for link; do - test -h "$link" || continue - dir=$(dirname "$link") - reltarget=$(readlink "$link") - case $reltarget in - /*) abstarget=$reltarget;; - *) abstarget=$dir/$reltarget;; - esac - rm -fv "$link" - cp -afv "$abstarget" "$link" || { - # on failure, restore the symlink - rm -rfv "$link" - ln -sfv "$reltarget" "$link" - } - done