diff --git a/google-chrome/files/google-chrome-incognito.sh b/google-chrome/files/google-chrome-incognito.sh new file mode 100755 index 0000000..39a71db --- /dev/null +++ b/google-chrome/files/google-chrome-incognito.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -eu + +URL="${2-}" + +CHROME="$(which google-chrome 2>/dev/null)" +if [ -n "$CHROME" ]; then + if [ -f "/Applications/Google Chrome.app" ]; then + CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" + else + echo "ERR: Failed to find Google Chrome installation" + exit 1 + fi +fi + +CHROMEDIR="$(mktemp -d)" +# shellcheck disable=SC2064 +trap "rm -rf ${CHROMEDIR}" EXIT + +"$CHROME" \ + --incognito \ + --no-default-browser-check \ + --no-first-run \ + --user-data-dir="$CHROMEDIR" \ + "$URL" diff --git a/google-chrome/files/google-chrome-socksproxy.sh b/google-chrome/files/google-chrome-socksproxy.sh new file mode 100755 index 0000000..1609d75 --- /dev/null +++ b/google-chrome/files/google-chrome-socksproxy.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +set -eu + +if [ $# -lt 1 ]; then + echo "Usage: $(basename "$0") [URL]" + exit 1 +fi + +SOCKSPORT="$1" +URL="${2-}" + +CHROME="$(which google-chrome 2>/dev/null)" +if [ -n "$CHROME" ]; then + if [ -f "/Applications/Google Chrome.app" ]; then + CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" + else + echo "ERR: Failed to find Google Chrome installation" + exit 1 + fi +fi + +CHROMEDIR="$(mktemp -d)" +# shellcheck disable=SC2064 +trap "rm -rf ${CHROMEDIR}" EXIT + +"$CHROME" \ + --incognito \ + --no-default-browser-check \ + --no-first-run \ + --user-data-dir="$CHROMEDIR" \ + --proxy-server="socks5://localhost:${SOCKSPORT}" \ + "$URL" diff --git a/google-chrome/tasks/main.yml b/google-chrome/tasks/main.yml index 542de45..d5f65af 100644 --- a/google-chrome/tasks/main.yml +++ b/google-chrome/tasks/main.yml @@ -39,3 +39,14 @@ mode: 0644 owner: root group: root + +- name: install custom chrome startup scripts + copy: + dest: "/usr/local/bin/{{ item }}" + src: "{{ item }}.sh" + mode: 0755 + owner: root + group: "{{ ansible_wheel }}" + with_items: + - google-chrome-incognito + - google-chrome-socksproxy