2023-01-26 00:06:52 -08:00
|
|
|
{{- if ne .host.distro.family "windows" -}}
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
{{ includeTemplate "universal/profile" }}
|
|
|
|
{{ includeTemplate "universal/logg" }}
|
|
|
|
|
|
|
|
### Ensure Chrome policies directory is present
|
2023-02-01 09:57:24 -08:00
|
|
|
for POLICY_DIR in "/opt/google/chrome/policies" "/etc/chromium/policies" "/etc/brave/policies"; do
|
|
|
|
### Managed policies
|
|
|
|
if [ ! -f "$POLICY_DIR/managed/policies.json" ]; then
|
|
|
|
logg info "Ensuring directory $POLICY_DIR/managed exists"
|
|
|
|
sudo mkdir -p "$POLICY_DIR/managed"
|
|
|
|
logg info "Copying ${XDG_CONFIG_HOME:-$HOME/.config}/chrome/managed.json to $POLICY_DIR/managed/policies.json"
|
|
|
|
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/chrome/managed.json" "$POLICY_DIR/managed/policies.json"
|
|
|
|
fi
|
2023-01-26 00:06:52 -08:00
|
|
|
|
2023-02-01 09:57:24 -08:00
|
|
|
### Recommended policies
|
|
|
|
if [ ! -f "$POLICY_DIR/recommended/policies.json" ]; then
|
|
|
|
logg info "Ensuring directory $POLICY_DIR/recommended exists"
|
|
|
|
sudo mkdir -p "$POLICY_DIR/recommended"
|
|
|
|
logg info "Copying ${XDG_CONFIG_HOME:-$HOME/.config}/chrome/recommended.json to $POLICY_DIR/recommended/policies.json"
|
|
|
|
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/chrome/recommended.json" "$POLICY_DIR/recommended/policies.json"
|
|
|
|
fi
|
|
|
|
done
|
2023-01-26 00:06:52 -08:00
|
|
|
|
|
|
|
### Add Chrome extension JSON
|
2023-02-01 09:58:58 -08:00
|
|
|
for EXTENSION_DIR in "/opt/google/chrome/extensions" "/etc/chromium/extensions" "/etc/brave/extensions" "$HOME/Library/Application Support/Google/Chrome/External Extensions" "$HOME/Library/Application Support/Microsoft/Edge/External Extensions" "$HOME/Library/Application Support/BraveSoftware/Brave-Browser/External Extensions" ; do
|
2023-02-01 09:57:24 -08:00
|
|
|
### Ensure program-type is installed
|
|
|
|
if [ -d "$(dirname "$EXTENSION_DIR")" ]; then
|
|
|
|
### Ensure extension directory exists
|
2023-02-01 12:24:05 -08:00
|
|
|
if [[ "$EXTENSION_DIR" == '/opt/'* ]] || [[ "$EXTENSION_DIR" == '/etc/'* ]]; then
|
2023-02-01 09:57:24 -08:00
|
|
|
if [ ! -d "$EXTENSION_DIR" ]; then
|
|
|
|
logg info "Creating directory $EXTENSION_DIR"
|
|
|
|
sudo mkdir -p "$EXTENSION_DIR"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ ! -d "$EXTENSION_DIR" ]; then
|
|
|
|
logg info "Creating directory $EXTENSION_DIR"
|
|
|
|
mkdir -p "$EXTENSION_DIR"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
### Add extension JSON
|
2023-01-26 00:06:52 -08:00
|
|
|
logg info "Adding Chrome extensions to $EXTENSION_DIR"
|
|
|
|
for EXTENSION in {{ list (.chromeExtensions | toString | replace "[" "" | replace "]" "") | uniq | join " " }}; do
|
2023-02-01 12:39:10 -08:00
|
|
|
logg info "Adding Chrome extension manifest ($EXTENSION)"
|
2023-01-26 00:06:52 -08:00
|
|
|
EXTENSION_ID="$(echo "$EXTENSION" | sed 's/^.*\/\([^\/]*\)$/\1/')"
|
2023-02-01 12:24:05 -08:00
|
|
|
if [[ "$EXTENSION_DIR" == '/opt/'* ]] || [[ "$EXTENSION_DIR" == '/etc/'* ]]; then
|
2023-02-01 09:57:24 -08:00
|
|
|
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/chrome/extension.json" "$EXTENSION_DIR/${EXTENSION_ID}.json"
|
|
|
|
else
|
|
|
|
cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/chrome/extension.json" "$EXTENSION_DIR/${EXTENSION_ID}.json"
|
|
|
|
fi
|
2023-01-26 00:06:52 -08:00
|
|
|
done
|
|
|
|
else
|
|
|
|
logg info "$EXTENSION_DIR does not exist"
|
|
|
|
fi
|
2023-01-30 00:18:39 -08:00
|
|
|
done
|
2023-01-26 00:06:52 -08:00
|
|
|
|
|
|
|
{{ end -}}
|