#!/bin/sh

set -e

# Ensure that the manpages are installed and accessible
printf "=== Test: files from package \"manpages\" are installed\n"
for section in $(seq 8); do
    printf "Checking file intro.%s does exist -- " "$section"
    if ! man "$section" intro > /dev/null 2>&1; then
        printf "FAIL\n"
        exit 1
    fi
    printf "OK\n"
done

# Ensure that manpages-dev are installed,
# test two randomly picked examples.
printf "=== Test: files from package \"manpages-dev\" are installed\n"

file_to_check="/usr/share/man/man2/getuid.2.gz"
printf "Checking file %s does exist -- " "$file_to_check"
if [ ! -f "$file_to_check" ]; then
    printf "FAIL\n"
    exit 1
fi
printf "OK\n"

file_to_check="/usr/share/man/man3/dysize.3.gz"
printf "Checking file %s does exist -- " "$file_to_check"
if [ ! -f "$file_to_check" ]; then
    printf "FAIL\n"
    exit 1
fi
printf "OK\n"

# Test two randomly picked links to other manpages exist.
printf "=== Test: symlinks from package \"manpages-dev\" are installed\n"

link_to_check="/usr/share/man/man2/kexec_file_load.2.gz"
printf "Checking symlink %s does exist -- " "$link_to_check"
if [ ! -L "$link_to_check" ]; then
    printf "FAIL\n"
    exit 1
fi
printf "OK\n"

link_to_check="/usr/share/man/man3/tolower_l.3.gz"
printf "Checking symlink %s does exist -- " "$link_to_check"
if [ ! -L "$link_to_check" ]; then
    printf "FAIL\n"
    exit 1
fi
printf "OK\n"

exit 0
