forked from slimm609/checksec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·38 lines (29 loc) · 1.25 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
# generate the checksec file from the src directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
generated_file="${SCRIPT_DIR}/checksec"
# add shebang line and edit line
cat << 'EOF' > "${generated_file}"
#!/usr/bin/env bash
# Do not edit this file directly, this file is generated from the files
# in the src directory. Any updates to this file will be overwritten when generated
# sanitize the environment before run
[ "$(env | /bin/sed -r -e '/^(PWD|SHLVL|_)=/d')" ] && exec -c "$0" "$@"
EOF
# add the header
sed -e '1,3d' "${SCRIPT_DIR}"/src/header.sh >> "${generated_file}"
# add the license
echo -ne "\n" >> "${generated_file}"
sed 's/^/# /' "${SCRIPT_DIR}"/LICENSE.txt >> "${generated_file}"
# add the core file
sed -e '1,3d' "${SCRIPT_DIR}"/src/core.sh >> "${generated_file}"
# join all function files together in the middle
while read -r file; do
# remove the first 3 lines of each source file
# shebang line is included to properly shellcheck and format
sed -e '1,3d' "${file}" >> "${generated_file}"
done < <(find "${SCRIPT_DIR}"/src/functions -type f -iname "*.sh" | sort)
# add the footer
sed -e '1,3d' "${SCRIPT_DIR}"/src/footer.sh >> "${generated_file}"
# make it executable
chmod 755 "${generated_file}"