File: build.sh

package info (click to toggle)
checksec 2.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 10,936 kB
  • sloc: sh: 1,882; makefile: 2
file content (43 lines) | stat: -rwxr-xr-x 1,420 bytes parent folder | download
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
39
40
41
42
43
#!/usr/bin/env bash
# generate the checksec file from the src directory

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}" && git rev-parse --show-toplevel)"
cd "${REPO_ROOT}" || {
  echo "error: directory does not exist"
  exit 1
}
generated_file="${REPO_ROOT}/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' "${REPO_ROOT}"/src/header.sh >> "${generated_file}"

# add the license
echo -ne "\n" >> "${generated_file}"
sed 's/^/# /' "${REPO_ROOT}"/LICENSE.txt >> "${generated_file}"

# add the core file
sed -e '1,3d' "${REPO_ROOT}"/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 "${REPO_ROOT}"/src/functions -type f -iname "*.sh" | sort)

# add the footer
sed -e '1,3d' "${REPO_ROOT}"/src/footer.sh >> "${generated_file}"

# make it executable
chmod 755 "${generated_file}"