re add code

This commit is contained in:
rootzoll 2021-05-03 15:43:12 +02:00
parent 976b6ba244
commit fb1aeada9a

View file

@ -45,7 +45,93 @@ if [ "${action}" == "check-upload" ]; then
type=$2
echo "type='${type}'"
# testcut
# check if there to less or to many files in upload directory
countFiles=$(ls ${defaultUploadPath} | wc -l 2>/dev/null)
if [ ${countFiles} -lt 1 ]; then
sudo rm ${defaultUploadPath}/* 2>/dev/null
echo "error='not-found'"
exit 1
fi
if [ ${countFiles} -gt 1 ]; then
sudo rm ${defaultUploadPath}/* 2>/dev/null
echo "error='multiple'"
exit 1
fi
# get the file uploaded (full path)
filename=$(sudo ls ${defaultUploadPath}/*.*)
echo "# filename(${filename})"
# check of size >0
byteSize=$(ls -l ${filename} | awk '{print $5}')
echo "# byteSize(${byteSize})"
if [ "${byteSize}" == "" ] || [ "${byteSize}" == "0" ]; then
sudo rm ${defaultUploadPath}/* 2>/dev/null
echo "error='invalid'"
echo "errorDetail='invalid byte size: ${byteSize}'"
exit 1
fi
# SCB check if file looks valid
if [ "${type}" == "scb" ]; then
# general filename check
typeCount=$(sudo ls ${defaultUploadPath}/*.backup 2>/dev/null | grep -c '.backup')
if [ "${typeCount}" != "1" ]; then
sudo rm ${defaultUploadPath}/* 2>/dev/null
echo "error='invalid'"
echo "errorDetail='not *.backup'"
exit 1
fi
fi
# LND-RESCUE check if file looks valid
if [ "${type}" == "lnd-rescue" ]; then
# general filename check
typeCount=$(sudo ls ${defaultUploadPath}/lnd-rescue-*.tar.gz 2>/dev/null | grep -c 'lnd-rescue')
if [ "${typeCount}" != "1" ]; then
sudo rm ${defaultUploadPath}/* 2>/dev/null
echo "error='invalid'"
echo "errorDetail='not lnd-rescue-*.tar.gz'"
exit 1
fi
# checksum test
md5checksum=$(md5sum ${filename} | head -n1 | cut -d " " -f1)
echo "# filename(${md5checksum})"
isCorrect=$(echo ${filename} | grep -c ${md5checksum})
if [ "${isCorrect}" != "1" ]; then
sudo rm ${defaultUploadPath}/* 2>/dev/null
echo "error='invalid'"
echo "errorDetail='incorrect checksum'"
exit 1
fi
fi
# MIGRATION check if file looks valid
if [ "${type}" == "migration" ]; then
# general filename check
typeCount=$(sudo ls ${defaultUploadPath}/raspiblitz-*.tar.gz 2>/dev/null | grep -c 'raspiblitz')
if [ "${typeCount}" != "1" ]; then
sudo rm ${defaultUploadPath}/* 2>/dev/null
echo "error='invalid'"
echo "errorDetail='not raspiblitz-*.tar.gz'"
exit 1
fi
# checksum test
md5checksum=$(md5sum ${filename} | head -n1 | cut -d " " -f1)
echo "# filename(${md5checksum})"
isCorrect=$(echo ${filename} | grep -c ${md5checksum})
if [ "${isCorrect}" != "1" ]; then
sudo rm ${defaultUploadPath}/* 2>/dev/null
echo "error='invalid'"
echo "errorDetail='incorrect checksum'"
exit 1
fi
fi
# ok looks good - return filename & more info
echo "filename=${filename}"