mirror of
https://github.com/openappsec/attachment.git
synced 2025-09-30 11:44:29 +03:00
Adding packaging option to attachemnt
This commit is contained in:
3
nodes/CMakeLists.txt
Normal file
3
nodes/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
include(packaging.cmake)
|
||||
|
||||
add_subdirectory(nginx_attachment)
|
8
nodes/nginx_attachment/CMakeLists.txt
Normal file
8
nodes/nginx_attachment/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
install(FILES install-nginx-attachment.sh DESTINATION nginx_attachment/ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ)
|
||||
|
||||
gen_package(
|
||||
install-cp-nano-nginx-attachment.sh
|
||||
nginx_attachment
|
||||
./install-nginx-attachment.sh
|
||||
Check Point Attachment Registration Manager Nano Service Version ${PACKAGE_VERSION} Install Package
|
||||
)
|
117
nodes/nginx_attachment/install-nginx-attachment.sh
Executable file
117
nodes/nginx_attachment/install-nginx-attachment.sh
Executable file
@@ -0,0 +1,117 @@
|
||||
#!/bin/sh
|
||||
|
||||
#Attachment Detials
|
||||
ATTACHMENT_NAME="NGINX Attachemnt"
|
||||
ATTACHMENT_BIN_NAME="cp-nano-nginx-attachment"
|
||||
|
||||
#Const variables
|
||||
FORCE_STDOUT=true
|
||||
INSTALLATION_TIME=$(date)
|
||||
CP_NANO_LOG_PATH="/var/log/nano_agent"
|
||||
INSTALLATION_LOG_FILE=${CP_NANO_LOG_PATH}/${ATTACHMENT_BIN_NAME}-install.log
|
||||
|
||||
mkdir -p ${CP_NANO_LOG_PATH}
|
||||
|
||||
cp_print()
|
||||
{
|
||||
var_text=$1
|
||||
var_std_out=$2
|
||||
touch $INSTALLATION_LOG_FILE
|
||||
if [ -n "$var_std_out" ]; then
|
||||
if [ "$var_std_out" = "true" ]; then
|
||||
printf "%b\n" "$var_text"
|
||||
fi
|
||||
fi
|
||||
printf "%b\n" "$var_text" >> $INSTALLATION_LOG_FILE
|
||||
}
|
||||
|
||||
cp_exec()
|
||||
{
|
||||
var_cmd=$1
|
||||
var_std_out=$2
|
||||
# Send exec output to RES
|
||||
RES=$($var_cmd 2>&1)
|
||||
if [ -n "$RES" ]; then
|
||||
cp_print "$RES" "$var_std_out"
|
||||
fi
|
||||
}
|
||||
|
||||
run_installation()
|
||||
{
|
||||
cp_print "Starting installation of Check Point ${NANO_SERVICE_NAME} Nano service [$INSTALLATION_TIME]\n" $FORCE_STDOUT
|
||||
|
||||
cp_exec "cp lib/libosrc_compression_utils.so /usr/lib/libosrc_compression_utils.so"
|
||||
cp_exec "cp lib/libosrc_compression_utils.so /usr/lib64/libosrc_compression_utils.so"
|
||||
cp_exec "cp lib/libosrc_nginx_attachment_util.so /usr/lib/libosrc_nginx_attachment_util.so"
|
||||
cp_exec "cp lib/libosrc_nginx_attachment_util.so /usr/lib64/libosrc_nginx_attachment_util.so"
|
||||
cp_exec "cp lib/libosrc_shmem_ipc.so /usr/lib/libosrc_shmem_ipc.so"
|
||||
cp_exec "cp lib/libosrc_shmem_ipc.so /usr/lib64/libosrc_shmem_ipc.so"
|
||||
cp_exec "cp lib/libngx_module.so /usr/lib/nginx/modules/ngx_cp_attachment_module.so"
|
||||
cp_exec "cp lib/libngx_module.so /usr/lib64/nginx/modules/ngx_cp_attachment_module.so"
|
||||
|
||||
[ -f /etc/nginx/nginx.conf ] && sed -i 1i'load_module /usr/lib/nginx/modules/ngx_cp_attachment_module.so;' /etc/nginx/nginx.conf || echo
|
||||
[ -f /etc/nginx/template/nginx.tmpl ] && sed -i 1i'load_module /usr/lib/nginx/modules/ngx_cp_attachment_module.so;' /etc/nginx/template/nginx.tmpl || echo
|
||||
[ -f /usr/local/share/lua/5.1/kong/templates/nginx.lua ] && sed -i 's|return [[|return [[\\nload_module /usr/lib64/nginx/modules/ngx_cp_attachment_module.so;|g' /usr/local/share/lua/5.1/kong/templates/nginx.lua || echo
|
||||
[ -f /usr/local/share/lua/5.1/kong/templates/nginx.lua ] && sed -i 's|http {|http {\ncp_worker_processes ${{nginx_worker_processes}};|g' /usr/local/share/lua/5.1/kong/templates/nginx.lua || echo
|
||||
|
||||
cp_print "Installation completed successfully." $FORCE_STDOUT
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "Check Point: available flags are"
|
||||
echo "--install : install ${NANO_SERVICE_NAME} Nano Service"
|
||||
echo "--uninstall : remove ${NANO_SERVICE_NAME} Nano Service"
|
||||
echo "--pre_install_test : run Pre-installation test for ${NANO_SERVICE_NAME} Nano Service install package"
|
||||
echo "--post_install_test : run Post-installation test for ${NANO_SERVICE_NAME} Nano Service install package"
|
||||
exit 255
|
||||
}
|
||||
|
||||
run_uninstall()
|
||||
{
|
||||
cp_print "Starting uninstallation of Check Point ${NANO_SERVICE_NAME} Nano service [$INSTALLATION_TIME]\n" $FORCE_STDOUT
|
||||
|
||||
cp_print "Uninstallation completed successfully." $FORCE_STDOUT
|
||||
}
|
||||
|
||||
run_pre_install_test()
|
||||
{
|
||||
cp_print "Starting Pre-installation test of Check Point ${ATTACHMENT_NAME} installation package [$INSTALLATION_TIME]\n" $FORCE_STDOUT
|
||||
|
||||
cp_print "Successfully finished pre-installation test for Check Point ${ATTACHMENT_NAME} installation package [$INSTALLATION_TIME]\n" $FORCE_STDOUT
|
||||
exit 0
|
||||
}
|
||||
|
||||
run_post_install_test()
|
||||
{
|
||||
cp_print "Starting Post-installation test of Check Point ${ATTACHMENT_NAME} Nano service installation package [$INSTALLATION_TIME]\n" $FORCE_STDOUT
|
||||
|
||||
cp_print "Successfully finished post-installation test for Check Point ${ATTACHMENT_NAME} Nano service installation package [$INSTALLATION_TIME]\n" $FORCE_STDOUT
|
||||
exit 0
|
||||
}
|
||||
|
||||
run()
|
||||
{
|
||||
if [ '--install' = "$1" ]; then
|
||||
run_installation "${@}"
|
||||
elif [ '--uninstall' = "$1" ]; then
|
||||
run_uninstall
|
||||
elif [ '--pre_install_test' = "$1" ]; then
|
||||
run_pre_install_test
|
||||
elif [ '--post_install_test' = "$1" ]; then
|
||||
run_post_install_test
|
||||
else
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
echo "Administrative privileges required for this Package (use su or sudo)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift
|
||||
run "${@}"
|
||||
|
||||
exit 0
|
47
nodes/packaging.cmake
Normal file
47
nodes/packaging.cmake
Normal file
@@ -0,0 +1,47 @@
|
||||
execute_process(COMMAND python3 ${CMAKE_SOURCE_DIR}/core/version/build_version_vars_h.py print-version-only OUTPUT_VARIABLE PACKAGE_VERSION)
|
||||
string(STRIP ${PACKAGE_VERSION} PACKAGE_VERSION)
|
||||
|
||||
function(gen_help)
|
||||
math(EXPR lastIndex "${ARGC}-1")
|
||||
foreach(index RANGE 0 ${lastIndex} 2)
|
||||
set(ARG ${ARGV${index}})
|
||||
string(LENGTH ${ARG} ARG_LEN)
|
||||
while(${ARG_LEN} LESS 40)
|
||||
set(ARG "${ARG} ")
|
||||
math(EXPR ARG_LEN "${ARG_LEN}+1")
|
||||
endwhile()
|
||||
set(HELP "${HELP}ARGPACKINGMAGIC ${ARGV${index}}ARGSPACEMAGIC")
|
||||
math(EXPR index "${index}+1")
|
||||
set(HELP "${HELP} ${ARGV${index}}")
|
||||
endforeach()
|
||||
set(HELP ${HELP} PARENT_SCOPE)
|
||||
endfunction(gen_help)
|
||||
|
||||
function(set_package_params params)
|
||||
set(PKG_PARAM "${params}" PARENT_SCOPE)
|
||||
endfunction(set_package_params)
|
||||
|
||||
add_custom_target(package)
|
||||
|
||||
function(gen_package name dir script)
|
||||
math(EXPR lastIndex "${ARGC}-1")
|
||||
foreach(index RANGE 3 ${lastIndex})
|
||||
set(label ${label};${ARGV${index}})
|
||||
endforeach()
|
||||
set(ARTIFACT ${CMAKE_INSTALL_PREFIX}/${name})
|
||||
set(DIR ${CMAKE_INSTALL_PREFIX}/${dir})
|
||||
set(TARGET_NAME make_package_${dir})
|
||||
set(WRAPPER ${CMAKE_SOURCE_DIR}/build_system/tools/packaging/makeself_wrapper.sh)
|
||||
set(MAKESELF ${CMAKE_SOURCE_DIR}/external/makeself/makeself.sh)
|
||||
if ("${PKG_PARAM}" STREQUAL "")
|
||||
add_custom_command(OUTPUT ${ARTIFACT}
|
||||
COMMAND ${WRAPPER} ${MAKESELF} --needroot ${DIR} ${ARTIFACT} \"${label}\" \"${HELP}\" \"${PACKAGE_VERSION}\" \"${script}\"
|
||||
)
|
||||
else()
|
||||
add_custom_command(OUTPUT ${ARTIFACT}
|
||||
COMMAND ${WRAPPER} ${MAKESELF} --needroot\\ ${PKG_PARAM} ${DIR} ${ARTIFACT} \"${label}\" \"${HELP}\" \"${PACKAGE_VERSION}\" \"${script}\"
|
||||
)
|
||||
endif()
|
||||
add_custom_target(${TARGET_NAME} DEPENDS ${ARTIFACT})
|
||||
add_dependencies(package ${TARGET_NAME})
|
||||
endfunction(gen_package)
|
Reference in New Issue
Block a user