diff --git a/commands/host/1x-granite b/commands/host/1x-granite index 8f6515f..b7e101b 100755 --- a/commands/host/1x-granite +++ b/commands/host/1x-granite @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ## #ddev-generated ## Description: Build granite ## Usage: granite 1x-granite diff --git a/commands/host/1x-lib.sh b/commands/host/1x-lib.sh new file mode 100644 index 0000000..2714155 --- /dev/null +++ b/commands/host/1x-lib.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# +# Shared helper library for 1x DDEV host commands. +# Source this from any 1x-* command with: +# source "${BASH_SOURCE%/*}/1x-lib.sh" +# +# No ## Usage: header, so DDEV will not register this as a command. + +# Colors for printing messages. +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +BROWN='\033[0;33m' +NC='\033[0m' # No Color + +# Cross-platform "sed" +sed_compat() { + case "$OSTYPE" in + darwin*) + # BSD sed (macOS) needs '' after -i + local args=() + for arg in "$@"; do + if [[ "$arg" == "-i" ]]; then + args+=("-i" "") + else + args+=("$arg") + fi + done + sed "${args[@]}" + ;; + linux*) + sed "$@" + ;; + *) + echo "sed_compat: unsupported platform: $OSTYPE" >&2 + return 1 + ;; + esac +} + +# Cross-platform "date" +date_compat() { + case "$OSTYPE" in + darwin*) + # BSD date (macOS) lacks GNU extensions + if command -v gdate >/dev/null 2>&1; then + gdate "$@" + else + date "$@" + fi + ;; + linux*) + date "$@" + ;; + *) + echo "date_compat: unsupported platform: $OSTYPE" >&2 + return 1 + ;; + esac +} + +# Cross-platform "open" +open_compat() { + case "$OSTYPE" in + darwin*) + open "$@" + ;; + linux*) + xdg-open "$@" + ;; + *) + echo "open_compat: unsupported platform: $OSTYPE" >&2 + return 1 + ;; + esac +} diff --git a/commands/host/1x-playwright b/commands/host/1x-playwright index 319be88..59a349f 100755 --- a/commands/host/1x-playwright +++ b/commands/host/1x-playwright @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ## #ddev-generated ## Description: Run lullabot/ddev-playwright commands in a slightly more sane way :) @@ -6,14 +6,9 @@ ## Usage: 1x-playwright ## OSTypes: darwin,linux -start=`date +%s` +source "${BASH_SOURCE%/*}/1x-lib.sh" -# Colors for printing messages. -RED='\033[0;31m' -CYAN='\033[0;36m' -GREEN='\033[0;32m' -BROWN='\033[0;33m' -NC='\033[0m' # No Color +start=`date_compat +%s` if ! command -v jq 2>&1 >/dev/null then @@ -39,7 +34,7 @@ else host=$(ddev_hostname) playwright_report_url="https://${host}:9324" # Note: playwright "report server" hangs. - sleep 1 && open $playwright_report_url & jobs + sleep 1 && open_compat $playwright_report_url & jobs ddev playwright test "${@:2} --ui-host=0.0.0.0 --ui-port=9323" ;; @@ -47,7 +42,7 @@ else host=$(ddev_hostname) kasmvnc_url="https://${host}:8444" echo "Please note - if asked for authentication login is your username on the host (`whoami`) and the password is 'secret' (without the ')" - sleep 1 && open $kasmvnc_url & jobs + sleep 1 && open_compat $kasmvnc_url & jobs ddev playwright codegen "${@:2}" ;; @@ -62,7 +57,7 @@ else host=$(ddev_hostname) playwright_report_url="https://${host}:9324" # Note: playwright "report server" hangs. - sleep 1 && open $playwright_report_url & jobs + sleep 1 && open_compat $playwright_report_url & jobs ddev playwright show-report --host=0.0.0.0 ;; @@ -70,7 +65,7 @@ else host=$(ddev_hostname) kasmvnc_url="https://${host}:8444" # Note: playwright "ff|cr|wk" hangs. - sleep 1 && open $kasmvnc_url & jobs + sleep 1 && open_compat $kasmvnc_url & jobs echo "Please note - if asked for authentication login is your username on the host (`whoami`) and the password is 'secret' (without the ')" ddev playwright "$1" "${@:2}" ;; @@ -79,7 +74,7 @@ else host=$(ddev_hostname) kasmvnc_url="https://${host}:8444" # Note: playwright "ff|cr|wk" hangs. - sleep 1 && open $kasmvnc_url & jobs + sleep 1 && open_compat $kasmvnc_url & jobs echo "Please note - if asked for authentication login is your username on the host (`whoami`) and the password is 'secret' (without the ')" ddev playwright "$1" "${@:2}" ;; @@ -88,7 +83,7 @@ else host=$(ddev_hostname) kasmvnc_url="https://${host}:8444" # Note: playwright "ff|cr|wk" hangs. - sleep 1 && open $kasmvnc_url & jobs + sleep 1 && open_compat $kasmvnc_url & jobs echo "Please note - if asked for authentication login is your username on the host (`whoami`) and the password is 'secret' (without the ')" ddev playwright "$1" "${@:2}" ;; @@ -97,7 +92,7 @@ else host=$(ddev_hostname) kasmvnc_url="https://${host}:8444" echo "Please note - if asked for authentication login is your username on the host (`whoami`) and the password is 'secret' (without the ')" - open $kasmvnc_url + open_compat $kasmvnc_url ;; *) diff --git a/commands/host/1x-playwright-install b/commands/host/1x-playwright-install index 62368b4..01289d4 100755 --- a/commands/host/1x-playwright-install +++ b/commands/host/1x-playwright-install @@ -1,14 +1,12 @@ -#!/bin/bash +#!/usr/bin/env bash ## #ddev-generated ## Description: Install the lullabot/ddev-playwright addon and does some basic onex config. ## Usage: 1x-playwright-install -start=`date +%s` +source "${BASH_SOURCE%/*}/1x-lib.sh" -# Colors for printing messages. -GREEN='\033[0;32m' -NC='\033[0m' # No Color +start=`date_compat +%s` # Make sure the container is alive. ddev start diff --git a/commands/host/1x-start b/commands/host/1x-start index 3c15917..3570885 100755 --- a/commands/host/1x-start +++ b/commands/host/1x-start @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #ddev-generated ## Description: Starts the ddev project, runs auth and makes sure the .gitconfig is present. ## Usage: 1x-start diff --git a/commands/host/1x-theme-debug b/commands/host/1x-theme-debug index 3301231..38671e7 100755 --- a/commands/host/1x-theme-debug +++ b/commands/host/1x-theme-debug @@ -1,9 +1,11 @@ -#!/bin/bash +#!/usr/bin/env bash ## #ddev-generated ## Description: manage php config options ## Usage: 1x-theme-debug ## Example: "ddev 1x-theme-debug (enable|disable)" +source "${BASH_SOURCE%/*}/1x-lib.sh" + settings_dir="${DDEV_APPROOT}/${DDEV_DOCROOT}/sites/default" settings_local="settings.local.php" debug_services="services.theme_debug.yml" @@ -49,11 +51,7 @@ preflight() { fi # Delete the config always, so that enabling twice doesn't add it multiple times. - if [[ $OSTYPE == darwin* ]]; then - sed -i '' '/^#.*DO NOT WRITE ANYTHING BELOW THIS LINE/,$d' "${settings_dir}/${settings_local}" - else - sed -i '/^#.*DO NOT WRITE ANYTHING BELOW THIS LINE/,$d' "${settings_dir}/${settings_local}" - fi + sed_compat -i '/^#.*DO NOT WRITE ANYTHING BELOW THIS LINE/,$d' "${settings_dir}/${settings_local}" } enable_debug() { @@ -64,11 +62,7 @@ enable_debug() { echo "${debug_settings_php}" > "${settings_dir}/${debug_settings}" # Make sure the file ends with a new line - if [[ $OSTYPE == darwin* ]]; then - sed -i '' '$a\' "${settings_dir}/${settings_local}" - else - sed -i '$a\' "${settings_dir}/${settings_local}" - fi + sed_compat -i '$a\' "${settings_dir}/${settings_local}" echo -e "${debug_config_php}" >> "${settings_dir}/${settings_local}" } diff --git a/commands/host/1x-token-setup b/commands/host/1x-token-setup index 1bce68c..08f3337 100644 --- a/commands/host/1x-token-setup +++ b/commands/host/1x-token-setup @@ -1,10 +1,12 @@ -#!/bin/bash +#!/usr/bin/env bash ## #ddev-generated # Description: Setup GitLab tokens, composer gitlab tokens as well as npm gitlab tokens and npm scoped packages. # Usage: 1x-token-setup set -e +source "${BASH_SOURCE%/*}/1x-lib.sh" + # Stop the current DDEV project (if running). if ddev describe > /dev/null 2>&1; then ddev stop @@ -74,26 +76,19 @@ fi # Setup token for NPM # Remove old token if exists to replace with new one, or just append # A simple append might create duplicates, so let's try to be a bit smarter or just append as requested -# Make this work on MacOS and Linux >.< -if [[ $OSTYPE == darwin* ]]; then - # "in-place editing only works for regular files" thus change directly ~/.npmrc - sed -i '' '/\/\/git.1xinternet.de\/:_authToken=/d' ~/.npmrc -else - # "In-place editing" works also for symlinks on Linux, but for consistency's sake. - sed -i '/\/\/git.1xinternet.de\/:_authToken=/d' ~/.npmrc -fi -echo "//git.1xinternet.de/:_authToken=${PERSONAL_ACCESS_TOKEN}" >> ~/.ddev/homeadditions/.npmrc +sed_compat -i '/\/\/git.1xinternet.de\/.*:_authToken=/d' ~/.npmrc +echo "//git.1xinternet.de/:_authToken=${PERSONAL_ACCESS_TOKEN}" >> ~/.npmrc # Configure NPM in homeadditions so the container picks it up. # We append if not already present to avoid duplication -if ! grep -q "@dxp:registry=https://git.1xinternet.de/api/v4/groups/392/-/packages/npm/" ~/.ddev/homeadditions/.npmrc; then - echo "@dxp:registry=https://git.1xinternet.de/api/v4/groups/392/-/packages/npm/" >> ~/.ddev/homeadditions/.npmrc +if ! grep -q "@dxp:registry=https://git.1xinternet.de/api/v4/groups/392/-/packages/npm/" ~/.npmrc; then + echo "@dxp:registry=https://git.1xinternet.de/api/v4/groups/392/-/packages/npm/" >> ~/.npmrc fi # Configure NPM in homeadditions so the container picks it up. # We append if not already present to avoid duplication -if ! grep -q "@1xINTERNET:registry=https://git.1xinternet.de/api/v4/group/1121/-/packages/npm/" ~/.ddev/homeadditions/.npmrc; then - echo "@1xINTERNET:registry=https://git.1xinternet.de/api/v4/projects/1121/packages/npm/" >> ~/.ddev/homeadditions/.npmrc +if ! grep -q "@1xINTERNET:registry=https://git.1xinternet.de/api/v4/projects/1121/packages/npm/" ~/.npmrc; then + echo "@1xINTERNET:registry=https://git.1xinternet.de/api/v4/projects/1121/packages/npm/" >> ~/.npmrc fi # Start the DDEV project (so containers run). diff --git a/commands/host/1x-twig-debug b/commands/host/1x-twig-debug index 2933116..f4a2151 100755 --- a/commands/host/1x-twig-debug +++ b/commands/host/1x-twig-debug @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ## #ddev-generated ## Description: Enables or disables Twig debugging for Drupal 10 installations ## Usage: 1x-twig-debug diff --git a/commands/web/1x-phpcs b/commands/web/1x-phpcs index 538006b..dc4df36 100644 --- a/commands/web/1x-phpcs +++ b/commands/web/1x-phpcs @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ## #ddev-generated ## Description: Run phpcs within the web container ## Usage: 1x-phpcs