Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update install_t1utils.sh #22

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion scripts/generate_requirements.txt_from_pyproject.toml.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
#!/usr/bin/env bash
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
# poetry claims to be able to do this but I've had some issues crossing platform with the
# generated requirements, so mileage may vary.

Expand Down
6 changes: 5 additions & 1 deletion scripts/install_didier_stevens_pdf_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
# Get Didier Stevens's pdf-parser.py and pdfid.py from github, place them in tools/ dir, and make executable

SCRIPT_PATH=$(dirname -- "$(readlink -f -- "$0";)";)
readonly SCRIPT_PATH
. "$SCRIPT_PATH/lib/project_paths.sh"

TOOL_EXECUTABLES=(pdfid.py pdf-parser.py xorsearch.py)
readonly TOOL_EXECUTABLES

DIDIER_STEVENS_RAW_GITHUB_URL='https://raw.githubusercontent.com/DidierStevens/DidierStevensSuite/master/'
readonly DIDIER_STEVENS_RAW_GITHUB_URL

mkdir -p "$PDFALYZER_TOOLS_DIR"
mkdir -p -v "$PDFALYZER_TOOLS_DIR"
pushd "$PDFALYZER_TOOLS_DIR"

for tool_executable in "${TOOL_EXECUTABLES[@]}"; do
Expand Down
53 changes: 30 additions & 23 deletions scripts/install_t1utils.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail

# Installs the T1Utils suite for working with Adobe Type1 fonts.
# Requires autoconf and automake on macOS.

if cat /etc/*release | grep ^NAME | egrep 'CentOS|Red|Fedora'; then
echo "Installing t1utils with yum..."
if cat /etc/*release | grep ^NAME | grep -E 'CentOS|Red|Fedora'; then
printf "Info: Installing t1utils with yum...\n"
sudo yum install -y t1utils
exit 0
elif cat /etc/*release | grep ^NAME | egrep 'Ubuntu|Debian|Mint|Knoppix'; then
echo "Installing t1utils with apt-get..."
elif cat /etc/*release | grep ^NAME | grep -E 'Ubuntu|Debian|Mint|Knoppix'; then
printf "Info: Installing t1utils with apt-get...\n"
sudo apt-get install -y t1utils
exit 0
elif ! echo `uname -a` | grep Darwin 2>&1 >/dev/null; then
echo "OS NOT DETECTED, couldn't install t1utils"
exit 1;
elif ! "$(uname -a)" | grep Darwin >/dev/null 2>&1; then
printf "Error: OS NOT DETECTED, couldn't install t1utils\n"
exit 1
fi

echo "macOS detected, building t1utils from source..."

printf "Info: macOS detected, building t1utils from source...\n"

for required_build_tool in automake autoconf make; do
if ! which $required_build_tool >/dev/null; then
echo "Missing $required_build_tool. You may need to run something like 'brew install $required_build_tool'."
if ! command -v "${required_build_tool}" >/dev/null; then
printf "Warning: Missing %s. You may need to run something like 'brew install %s'.\n" "${required_build_tool}" "${required_build_tool}"
fi
done

SCRIPT_PATH=$(dirname -- "$(readlink -f -- "$0";)";)
source "$SCRIPT_PATH/lib/project_paths.sh"
TMP_DIR="$PDFALYZER_PROJECT_PATH/tmp"
SCRIPT_PATH="$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")"
# shellcheck source=./lib/project_paths.sh
source "${SCRIPT_PATH}/lib/project_paths.sh"

mkdir -p "$TMP_DIR"
pushd "$TMP_DIR" >/dev/null
TMP_DIR="$(mktemp -d -p "${PDFALYZER_PROJECT_PATH}" -t "tmp.XXXXXXXXXX")" || {
printf "Error: Failed to create temporary directory.\n" >&2
exit 1
}
pushd "${TMP_DIR}" >/dev/null || exit 1
git clone https://github.com/kohler/t1utils.git

cd t1utils
cd t1utils || exit 1
command autoreconf -i
./configure

echo "Successfully configured, building with 'make'..."
printf "Info: Successfully configured, building with 'make'...\n"
make

echo "About to run 'make install' as sudo which will place binaries in /usr/local/bin. You will be asked for your password."
echo "For a different install location you'll need to manually intervene here."
sudo mkdir -p /usr/local/bin
printf "Info: About to run 'make install' as sudo which will place binaries in /usr/local/bin. You will be asked for your password.\n"
printf "Info: For a different install location you'll need to manually intervene here.\n"
sudo mkdir -p -v /usr/local/bin
sudo make install

popd >/dev/null
popd >/dev/null || exit 1
37 changes: 28 additions & 9 deletions scripts/svg_to_png.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
#!/bin/bash
# Use inkscape to render a png for each svg file in doc/svgs/
#!/usr/bin/env bash
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail

SCRIPT_DIR=$(dirname -- "$(readlink -f -- "$0";)";)
SVG_DIR="$SCRIPT_DIR/../doc/svgs/"
PNG_DIR="$SVG_DIR/rendered_images/"
# Use Inkscape to render a PNG for each SVG file in doc/svgs/

SCRIPT_DIR="$(dirname -- "$(readlink -f -- "$0")")"
readonly SCRIPT_DIR

for svg in `find "$SVG_DIR" -iname "*.svg"`; do
rendered_png="$PNG_DIR/`basename $svg`.png"
echo -e "Rendering $svg\n to $rendered_png..."
inkscape --export-filename="$rendered_png" "$svg"
SVG_DIR="${SCRIPT_DIR}/../doc/svgs/"
readonly SVG_DIR

PNG_DIR="${SVG_DIR}/rendered_images/"
readonly PNG_DIR

# Create PNG_DIR if it doesn't exist
mkdir -p -v "${PNG_DIR}"

# Find and render each SVG file
find "${SVG_DIR}" -iname "*.svg" -print0 | while IFS= read -r -d '' svg; do
rendered_png="${PNG_DIR}/$(basename "${svg}").png"
printf "Info: Rendering %s\n to %s...\n" "${svg}" "${rendered_png}"

if inkscape --export-filename="${rendered_png}" "${svg}"; then
printf "Info: Successfully rendered %s to %s\n" "${svg}" "${rendered_png}"
else
printf "Error: Failed to render %s\n" "${svg}" >&2
exit 1
fi
done
44 changes: 26 additions & 18 deletions scripts/test_against_all_pdfs_in_Documents_folder.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
#!/bin/bash
SCRIPT_PATH=$(dirname -- "$(readlink -f -- "$0";)";)
source "$SCRIPT_PATH/lib/project_paths.sh"
SCRIPT_PATH="$(dirname -- "$(readlink -f -- "$0")")"
readonly SCRIPT_PATH

source "${SCRIPT_PATH}/lib/project_paths.sh"

# Exporting makes these available to the 'find -exec bash -c' invocation
export PDFALYZER_EXECUTABLE
export SUCCESS_LOG=log/successfully_parsed.txt
export FAILURE_LOG=log/failed_to_parse.txt

export SUCCESS_LOG="log/successfully_parsed.txt"
export FAILURE_LOG="log/failed_to_parse.txt"

pdfalyze_doc() {
pdf_full_path="$(readlink -f "$1")"
pdf_basename=`basename "$pdf_full_path"`

if [[ $pdf_basename =~ postgresql.* ]]; then
echo "Skipping '$pdf_basename'..." # Postgres PDF takes forever to process
local pdf_full_path
pdf_full_path="$(readlink -f "${1}")"
readonly pdf_full_path
local pdf_basename
pdf_basename="$(basename "${pdf_full_path}")"
readonly pdf_basename

if [[ "${pdf_basename}" =~ postgresql.* ]]; then
printf "Info: Skipping '%s'...\n" "${pdf_basename}" # Postgres PDF takes forever to process
return
fi

cmd="$PDFALYZER_EXECUTABLE -f -r -t \"$pdf_full_path\""
echo -e "\nCommand to run: $cmd"
local cmd
cmd="${PDFALYZER_EXECUTABLE} -f -r -t \"${pdf_full_path}\""
printf "\nInfo: Command to run: %s\n" "${cmd}"

eval $cmd
eval "${cmd}"

if [ $? -eq 0 ]; then
echo "$pdf_full_path" >> "$SUCCESS_LOG"
if [[ $? -eq 0 ]]; then
printf "%s\n" "${pdf_full_path}" >> "${SUCCESS_LOG}"
else
echo "$pdf_full_path" >> "$FAILURE_LOG"
printf "%s\n" "${pdf_full_path}" >> "${FAILURE_LOG}"
fi
}

export -f pdfalyze_doc

rm "$SUCCESS_LOG" 2>/dev/null
rm "$FAILURE_LOG" 2>/dev/null
# Remove log files if they exist, suppressing errors
rm -f -v "${SUCCESS_LOG}" 2>/dev/null
rm -f -v "${FAILURE_LOG}" 2>/dev/null

find ~/Documents/ -iname "*.pdf" -type f -exec bash -c 'pdfalyze_doc "{}"' \;