Skip to content

Commit

Permalink
adding lacework cli
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmordasiewicz committed Feb 17, 2025
1 parent ff6d79b commit 5d6f7c4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lacework-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
48 changes: 48 additions & 0 deletions src/lacework-cli/oncreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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)

Expand Down

0 comments on commit 5d6f7c4

Please sign in to comment.