From 5d6f7c4eabb541b8b7763a1c24601d2adbfe0c4d Mon Sep 17 00:00:00 2001 From: Robin Mordasiewicz Date: Mon, 17 Feb 2025 15:55:21 -0500 Subject: [PATCH] adding lacework cli --- src/lacework-cli/devcontainer-feature.json | 2 +- src/lacework-cli/oncreate.sh | 48 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/lacework-cli/devcontainer-feature.json b/src/lacework-cli/devcontainer-feature.json index a6362d3..24e8311 100644 --- a/src/lacework-cli/devcontainer-feature.json +++ b/src/lacework-cli/devcontainer-feature.json @@ -16,5 +16,5 @@ "onCreateCommand": { "lacework-cli-persistence-setup": "/usr/local/share/lacework-cli/scripts/oncreate.sh" }, - "version": "0.0.13" + "version": "0.0.15" } diff --git a/src/lacework-cli/oncreate.sh b/src/lacework-cli/oncreate.sh index c2663e3..a7086c0 100755 --- a/src/lacework-cli/oncreate.sh +++ b/src/lacework-cli/oncreate.sh @@ -2,6 +2,8 @@ set -e +TARGET="/dc/lacework-cli" + # if the user is not root, chown /dc/lacework-cli to the user if [ "$(id -u)" != "0" ]; then echo "Running oncreate.sh for user ${USER}" @@ -18,6 +20,52 @@ fi ln -sf /dc/lacework-cli/.lacework.toml ${HOME}/.lacework.toml +create_symlink() { + LINK="${1}" + + if [ ! -d "$(dirname "$LINK")" ]; then + mkdir -p "$(dirname "$LINK")" + fi + + if [ -e "$LINK" ]; then + if [ -L "$LINK" ]; then + current_target=$(readlink "$LINK") + if [ "$current_target" = "$TARGET" ]; then + echo "Symlink already exists and points to the correct target: $TARGET" + else + echo "Symlink exists but points to $current_target. Recreating symlink..." + rm "$LINK" + ln -sd "$TARGET" "$LINK" + fi + elif [ -d "$LINK" ]; then + echo "$LINK exists as a directory. Moving its contents to $TARGET and replacing it with a symlink..." + + if [ ! -d "$TARGET" ]; then + mkdir -p "$TARGET" + echo "Created target directory: $TARGET" + fi + + shopt -s dotglob + if [ "$(ls -A "$LINK")" ]; then + mv "$LINK"/* "$TARGET"/ 2>/dev/null + fi + shopt -u dotglob + + rm -rf "$LINK" + ln -sd "$TARGET" "$LINK" + else + echo "$LINK exists but is neither a symlink nor a directory. Please remove it manually and re-run the script." + exit 1 + fi + else + echo "$LINK does not exist. Creating symlink..." + ln -sd "$TARGET" "$LINK" + fi +} + +create_symlink "${HOME}/.config/lacework" +create_symlink "${HOME}/.config/sca" + # Run the "lacework account list" command and capture both stdout and stderr output=$(lacework account list 2>&1)