/ run_onchange_install-zen-chrome.sh.tmpl
run_onchange_install-zen-chrome.sh.tmpl
1 #!/bin/bash 2 # Install Zen Browser chrome files into the active profile. 3 # Hashes of source files (triggers re-run on change): 4 # userChrome.css: {{ include ".chezmoitemplates/zen-chrome/userChrome.css" | sha256sum }} 5 # userContent.css: {{ include ".chezmoitemplates/zen-chrome/userContent.css" | sha256sum }} 6 # zen-logo-mocha.svg: {{ include ".chezmoitemplates/zen-chrome/zen-logo-mocha.svg" | sha256sum }} 7 # user.js: {{ include ".chezmoitemplates/zen-chrome/user.js" | sha256sum }} 8 # policies.json: {{ include ".chezmoitemplates/zen-chrome/policies.json" | sha256sum }} 9 10 set -euo pipefail 11 12 {{ if eq .chezmoi.os "darwin" -}} 13 ZEN_DIR="$HOME/Library/Application Support/zen" 14 {{ else -}} 15 ZEN_DIR="$HOME/.zen" 16 {{ end -}} 17 18 PROFILES_INI="$ZEN_DIR/profiles.ini" 19 20 if [ ! -f "$PROFILES_INI" ]; then 21 echo "Zen Browser profiles.ini not found, skipping." 22 exit 0 23 fi 24 25 # Find the default profile path from the [Install*] section 26 PROFILE_REL=$(awk -F= '/^\[Install/ { in_install=1; next } /^\[/ { in_install=0 } in_install && /^Default=/ { print $2; exit }' "$PROFILES_INI") 27 28 if [ -z "$PROFILE_REL" ]; then 29 echo "Could not detect default Zen profile, skipping." 30 exit 0 31 fi 32 33 CHROME_DIR="$ZEN_DIR/$PROFILE_REL/chrome" 34 mkdir -p "$CHROME_DIR" 35 36 cat > "$CHROME_DIR/userChrome.css" << 'CHEZMOI_EOF' 37 {{ include ".chezmoitemplates/zen-chrome/userChrome.css" }} 38 CHEZMOI_EOF 39 40 cat > "$CHROME_DIR/userContent.css" << 'CHEZMOI_EOF' 41 {{ include ".chezmoitemplates/zen-chrome/userContent.css" }} 42 CHEZMOI_EOF 43 44 cat > "$CHROME_DIR/zen-logo-mocha.svg" << 'CHEZMOI_EOF' 45 {{ include ".chezmoitemplates/zen-chrome/zen-logo-mocha.svg" }} 46 CHEZMOI_EOF 47 48 PROFILE_DIR="$ZEN_DIR/$PROFILE_REL" 49 50 cat > "$PROFILE_DIR/user.js" << 'CHEZMOI_EOF' 51 {{ include ".chezmoitemplates/zen-chrome/user.js" }} 52 CHEZMOI_EOF 53 54 # Install policies.json for extension auto-install 55 {{ if eq .chezmoi.os "darwin" -}} 56 DIST_DIR="/Applications/Zen Browser.app/Contents/Resources/distribution" 57 {{ else -}} 58 # Try common Linux locations 59 if [ -d "/opt/zen-browser" ]; then 60 DIST_DIR="/opt/zen-browser/distribution" 61 elif [ -d "/usr/lib/zen-browser" ]; then 62 DIST_DIR="/usr/lib/zen-browser/distribution" 63 elif [ -d "/usr/lib/zen" ]; then 64 DIST_DIR="/usr/lib/zen/distribution" 65 else 66 DIST_DIR="" 67 fi 68 {{ end -}} 69 70 if [ -n "$DIST_DIR" ]; then 71 mkdir -p "$DIST_DIR" 72 cat > "$DIST_DIR/policies.json" << 'CHEZMOI_EOF' 73 {{ include ".chezmoitemplates/zen-chrome/policies.json" }} 74 CHEZMOI_EOF 75 echo "Zen policies.json installed to: $DIST_DIR/policies.json" 76 else 77 echo "Warning: Could not find Zen Browser installation directory for policies.json" 78 fi 79 80 echo "Zen chrome files installed to: $CHROME_DIR" 81 echo "Zen user.js installed to: $PROFILE_DIR/user.js"