summaryrefslogtreecommitdiff
path: root/examples/file-server/browse-files.sh
blob: c93716df1ede4e23a3a7dd340b3d37f7ff6d3717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh
# Serves files and directory listings.

ROOT="/srv/tlsd/files"

while read -r LINE
do
    echo "${SHA256}: ${LINE}" 1>&2
    FILEPATH="${ROOT}/$(echo "${LINE}" | sed -e 's/\.\.//g')"
    if   [ -d "${FILEPATH}" ]
    then ls -l "${FILEPATH}"
    elif [ -f "${FILEPATH}" ]
    then cat "${FILEPATH}"
    else echo "${FILEPATH} is neither a file nor a directory";
    fi
done