diff --git a/karakeep/Dockerfile b/karakeep/Dockerfile index 4e1945b10..0b428be46 100644 --- a/karakeep/Dockerfile +++ b/karakeep/Dockerfile @@ -57,6 +57,7 @@ RUN \ ttf-freefont \ font-noto-emoji \ font-wqy-zenhei \ + unzip \ && mkdir -p /usr/src/chrome \ && adduser -D chrome \ && chown -R chrome:chrome /usr/src/chrome @@ -109,6 +110,23 @@ RUN chmod 777 /.bashio-standalone.sh RUN sed -i "s|/usr/bin/env|/usr/bin/with-contenv|g" /etc/cont-init.d/* +RUN set -e; \ + extensions_dir="/usr/src/chrome/extensions"; \ + mkdir -p "${extensions_dir}"; \ + for entry in \ + "i-dont-care-about-cookies:fllaojicojecljbmefodhfapmkghcbnh" \ + "ublock-origin:cjpalhdlnbpafiamejdnhcphjbkeiagm"; do \ + name="${entry%%:*}"; \ + ext_id="${entry##*:}"; \ + curl -fsSL "https://clients2.google.com/service/update2/crx?response=redirect&prodversion=120.0&acceptformat=crx2,crx3&x=id%3D${ext_id}%26installsource%3Dondemand%26uc" \ + -o "/tmp/${name}.crx"; \ + rm -rf "${extensions_dir:?}/${name}"; \ + mkdir -p "${extensions_dir}/${name}"; \ + unzip -q "/tmp/${name}.crx" -d "${extensions_dir}/${name}"; \ + rm "/tmp/${name}.crx"; \ + done; \ + chown -R chrome:chrome "${extensions_dir}" + ############ # 5 Labels # ############ diff --git a/karakeep/README.md b/karakeep/README.md index 8145f7d77..f0d51f284 100644 --- a/karakeep/README.md +++ b/karakeep/README.md @@ -63,7 +63,7 @@ Webui can be found at `:3000`. | `CRAWLER_VIDEO_DOWNLOAD_MAX_SIZE` | int | | Max video size (MB). | | `CRAWLER_VIDEO_DOWNLOAD_TIMEOUT_SEC` | int | | Video download timeout. | | `CRAWLER_ENABLE_ADBLOCKER` | bool | `true` | Enable ad blocking in the crawler. | -| `CHROME_EXTENSIONS_DIR` | str | `/share/karakeep/extensions` | Host-mounted extensions directory for headless Chromium. | +| `CHROME_EXTENSIONS_DIR` | str | `/usr/src/chrome/extensions` | Extensions directory for headless Chromium. | | `MEILI_MASTER_KEY` | password | | Meilisearch master key (auto-generated if left blank). | | `MEILI_ADDR` | str | | Meilisearch URL. | | `BROWSER_WEB_URL` | str | | Chromium remote debugging URL. | @@ -72,15 +72,9 @@ Webui can be found at `:3000`. ### Extensions for headless Chromium -This add-on loads extensions in headless Chromium with the `--headless=new` flag. To use the included defaults: +This add-on loads extensions in headless Chromium with the `--headless=new` flag. The defaults are downloaded automatically during the image build and refreshed each time the add-on starts into `/usr/src/chrome/extensions` (non-persistent). -1. Create these folders on the host (via the `/share` mount): - - `/share/karakeep/extensions/i-dont-care-about-cookies` - - `/share/karakeep/extensions/ublock-origin` -2. Unzip each extension into its corresponding folder. -3. Restart the add-on. - -You can override the base folder with the `CHROME_EXTENSIONS_DIR` option. Any missing extension folder is skipped at runtime. +You can override the base folder with the `CHROME_EXTENSIONS_DIR` option to point to a host-mounted directory if you prefer to manage extensions manually. Any missing extension folder is skipped at runtime. ### Custom Scripts and Environment Variables diff --git a/karakeep/config.yaml b/karakeep/config.yaml index 0a5f7bb85..aef1a683b 100644 --- a/karakeep/config.yaml +++ b/karakeep/config.yaml @@ -4,7 +4,7 @@ arch: description: bookmark-everything app with a touch of AI for the data hoarders out there environment: BROWSER_WEB_URL: http://127.0.0.1:9222 - CHROME_EXTENSIONS_DIR: /share/karakeep/extensions + CHROME_EXTENSIONS_DIR: /usr/src/chrome/extensions DATA_DIR: /data DISABLE_NEW_RELEASE_CHECK: "true" MEILI_ADDR: http://127.0.0.1:7700 @@ -19,7 +19,7 @@ map: name: Karakeep options: env_vars: [] - CHROME_EXTENSIONS_DIR: /share/karakeep/extensions + CHROME_EXTENSIONS_DIR: /usr/src/chrome/extensions CRAWLER_DOWNLOAD_BANNER_IMAGE: true CRAWLER_ENABLE_ADBLOCKER: true CRAWLER_FULL_PAGE_ARCHIVE: false diff --git a/karakeep/rootfs/etc/cont-init.d/90-folders.sh b/karakeep/rootfs/etc/cont-init.d/90-folders.sh index 023d5e3f4..864dd25ea 100755 --- a/karakeep/rootfs/etc/cont-init.d/90-folders.sh +++ b/karakeep/rootfs/etc/cont-init.d/90-folders.sh @@ -7,9 +7,9 @@ bashio::log.info "Creating folders" mkdir -p \ /data/cache \ /data/chrome \ - /share/karakeep/extensions \ - /config/meili + /config/meili \ + /usr/src/chrome/extensions if id chrome &>/dev/null; then - chown -R chrome:chrome /data/cache /data/chrome + chown -R chrome:chrome /data/cache /data/chrome /usr/src/chrome/extensions fi diff --git a/karakeep/rootfs/etc/cont-init.d/92-chrome-extensions.sh b/karakeep/rootfs/etc/cont-init.d/92-chrome-extensions.sh new file mode 100755 index 000000000..87f99badc --- /dev/null +++ b/karakeep/rootfs/etc/cont-init.d/92-chrome-extensions.sh @@ -0,0 +1,30 @@ +#!/command/with-contenv bashio +# shellcheck shell=bash +set -e + +EXTENSIONS_DIR="${CHROME_EXTENSIONS_DIR:-/usr/src/chrome/extensions}" + +bashio::log.info "Refreshing Chromium extensions in ${EXTENSIONS_DIR}" + +mkdir -p "${EXTENSIONS_DIR}" + +download_extension() { + local name="$1" + local extension_id="$2" + local crx_path + + crx_path="$(mktemp)" + curl -fsSL "https://clients2.google.com/service/update2/crx?response=redirect&prodversion=120.0&acceptformat=crx2,crx3&x=id%3D${extension_id}%26installsource%3Dondemand%26uc" \ + -o "${crx_path}" + rm -rf "${EXTENSIONS_DIR:?}/${name}" + mkdir -p "${EXTENSIONS_DIR}/${name}" + unzip -q "${crx_path}" -d "${EXTENSIONS_DIR}/${name}" + rm -f "${crx_path}" +} + +download_extension "i-dont-care-about-cookies" "fllaojicojecljbmefodhfapmkghcbnh" +download_extension "ublock-origin" "cjpalhdlnbpafiamejdnhcphjbkeiagm" + +if id chrome &>/dev/null; then + chown -R chrome:chrome "${EXTENSIONS_DIR}" +fi diff --git a/karakeep/rootfs/etc/s6-overlay/s6-rc.d/svc-chrome/run b/karakeep/rootfs/etc/s6-overlay/s6-rc.d/svc-chrome/run index cd89b6ab8..e13702a2e 100644 --- a/karakeep/rootfs/etc/s6-overlay/s6-rc.d/svc-chrome/run +++ b/karakeep/rootfs/etc/s6-overlay/s6-rc.d/svc-chrome/run @@ -2,7 +2,7 @@ # shellcheck shell=bash set -e -EXTENSIONS_DIR="${CHROME_EXTENSIONS_DIR:-/share/karakeep/extensions}" +EXTENSIONS_DIR="${CHROME_EXTENSIONS_DIR:-/usr/src/chrome/extensions}" extensions=() for extension in "${EXTENSIONS_DIR}/i-dont-care-about-cookies" "${EXTENSIONS_DIR}/ublock-origin"; do