forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script test files exist and owner
- Loading branch information
1 parent
bd4fe7a
commit 6ac9c23
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM ubuntu:latest | ||
ARG PACKAGE | ||
RUN mkdir -p /tmp | ||
RUN apt-get update --fix-missing | ||
RUN apt-get install -y curl libcap2-bin | ||
COPY ${PACKAGE} /tmp/wazuh.deb | ||
RUN dpkg -i /tmp/wazuh.deb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM centos:latest | ||
|
||
RUN mkdir -p /tmp | ||
FROM centos | ||
ARG PACKAGE | ||
RUN cd /etc/yum.repos.d/ | ||
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* | ||
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* | ||
RUN yum update -y | ||
COPY ${PACKAGE} /tmp/wazuh.rpm | ||
RUN yum install /tmp/wazuh.rpm -y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/bin/sh | ||
|
||
# Definir el nombre del contenedor y los archivos que se van a verificar | ||
PACKAGE="" | ||
CONTAINER_NAME="wazuh-dashboard" | ||
FILES="/etc/wazuh-dashboard/opensearch_dashboards.yml /usr/share/wazuh-dashboard" | ||
FILE_OWNER="wazuh-dashboard" | ||
|
||
clean() { | ||
docker stop $CONTAINER_NAME | ||
docker rmi $CONTAINER_NAME | ||
} | ||
|
||
files_exist() { | ||
for FILE in $FILES; do | ||
if docker exec $CONTAINER_NAME ls $FILE >/dev/null 2>&1; then | ||
file_owner=$(docker exec $CONTAINER_NAME stat -c '%U' $FILE) | ||
if [ "$file_owner" != "$FILE_OWNER" ]; then | ||
echo "ERROR: $FILE is owned by $file_owner instead of $FILE_OWNER" | ||
clean | ||
exit 1 | ||
fi | ||
echo "$FILE exist and is owned by $FILE_OWNER" | ||
else | ||
echo "ERROR: $FILE does not exist" | ||
clean | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
|
||
test() { | ||
|
||
if [[ $PACKAGE == *".deb" ]]; then | ||
docker build --build-arg PACKAGE=$PACKAGE -t $CONTAINER_NAME ./deb/ | ||
docker run -it --rm -d --name $CONTAINER_NAME $CONTAINER_NAME | ||
elif [[ $PACKAGE == *".rpm" ]]; then | ||
docker build --build-arg PACKAGE=$PACKAGE -t $CONTAINER_NAME ./rpm/ | ||
docker run -it --rm -d --name $CONTAINER_NAME $CONTAINER_NAME | ||
else | ||
echo "ERROR: $PACKAGE is not a valid package (valid packages are .deb and .rpm ))" | ||
exit 1 | ||
fi | ||
|
||
files_exist | ||
} | ||
|
||
|
||
help() { | ||
echo | ||
echo "Usage: $0 [OPTIONS]" | ||
echo | ||
echo " -p, --package <path> Set Wazuh Dashboard rpm package name,which has to be in the <repository>/dev-tools/test-packages/<DISTRIBUTION>/ folder." | ||
echo | ||
exit $1 | ||
} | ||
|
||
main() { | ||
while [ -n "${1}" ]; do | ||
case "${1}" in | ||
"-h" | "--help") | ||
help 0 | ||
;; | ||
"-p" | "--package") | ||
if [ -n "${2}" ]; then | ||
PACKAGE="${2}" | ||
shift 2 | ||
else | ||
help 1 | ||
fi | ||
;; | ||
*) | ||
help 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z "$PACKAGE" ] ; then | ||
help 1 | ||
fi | ||
|
||
test | ||
|
||
clean | ||
} | ||
|
||
main "$@" |