2021-03-06 12:54:52 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-01-23 00:03:17 +01:00
|
|
|
#########################################################################
|
|
|
|
# ks-upv (ks-tools) - Upload videos file(s) to server with scp or rsync #
|
2023-02-10 13:20:13 +01:00
|
|
|
# Date: 10-02-2022 #
|
2022-01-23 00:03:17 +01:00
|
|
|
# Author: q3aql #
|
|
|
|
# Contact: q3aql@duck.com #
|
|
|
|
#########################################################################
|
2023-02-10 13:20:13 +01:00
|
|
|
VERSION="8.4-dev"
|
2022-02-04 17:07:26 +01:00
|
|
|
M_DATE="040222"
|
2021-03-06 12:54:52 +01:00
|
|
|
|
|
|
|
# Global parameters.
|
|
|
|
dirTemp="/tmp"
|
|
|
|
listCompTemp="ks-tools.list-full"
|
|
|
|
listCompTempTest="ks-tools.list-full.test"
|
|
|
|
listTemp="ks-tools.list"
|
2022-01-03 19:06:15 +01:00
|
|
|
dirConfig="${HOME}/.ks-tools"
|
2021-03-06 12:54:52 +01:00
|
|
|
ksToolsTempFolder="/tmp/ks-tools"
|
|
|
|
|
2021-03-26 18:19:27 +01:00
|
|
|
# Check cygwin alias (for Windows)
|
|
|
|
if [ -f "/usr/bin/cygwin-alias.sh" ] ; then
|
|
|
|
shopt -s expand_aliases
|
2021-03-29 18:08:57 +02:00
|
|
|
cygwin="yes"
|
2021-03-26 18:19:27 +01:00
|
|
|
source "/usr/bin/cygwin-alias.sh"
|
2021-03-29 18:08:57 +02:00
|
|
|
else
|
|
|
|
cygwin="no"
|
2021-03-26 18:19:27 +01:00
|
|
|
fi
|
|
|
|
|
2021-03-06 12:54:52 +01:00
|
|
|
# Function to remove spaces and symbols
|
2021-03-22 19:01:31 +01:00
|
|
|
# Syntax: convertText "<text>"
|
2021-03-06 12:54:52 +01:00
|
|
|
function convertText() {
|
2021-03-28 01:56:41 +01:00
|
|
|
wordToConvert=${1}
|
|
|
|
ksToolsSedFile="${ksToolsTempFolder}/ks-tools-${RANDOM}.txt"
|
|
|
|
mkdir -p ${ksToolsTempFolder} && chmod 777 -R ${ksToolsTempFolder} 2> /dev/null
|
|
|
|
echo "${wordToConvert}" > ${ksToolsSedFile}
|
|
|
|
# Borrar espacios
|
|
|
|
sed -i 's/ /_/g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
# Borrar simbolos
|
|
|
|
symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡"
|
|
|
|
for findSymbol in ${symbolsList} ; do
|
|
|
|
sed -i "s/${findSymbol}//g" "${ksToolsSedFile}" &> /dev/null
|
|
|
|
done
|
|
|
|
# Borrar el resto de simbolos
|
|
|
|
sed -i 's/*//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/"//g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i "s/^//g" "${ksToolsSedFile}" &> /dev/null
|
|
|
|
# Cambiar algunos simbolos
|
|
|
|
sed -i 's/+/_/g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/:/-/g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
sed -i 's/;/-/g' "${ksToolsSedFile}" &> /dev/null
|
|
|
|
# Mostrar texto convertido
|
|
|
|
wordToConvert=$(cat ${ksToolsSedFile})
|
|
|
|
echo ${wordToConvert}
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to list the files of a directory.
|
2021-03-22 19:01:31 +01:00
|
|
|
# Syntax: listArchives <directory>
|
2021-03-06 12:54:52 +01:00
|
|
|
function listArchives() {
|
2021-03-28 01:56:41 +01:00
|
|
|
fail=1
|
2022-01-22 12:13:28 +01:00
|
|
|
formatFilesMayus="MP4 AVI MPG MPEG MOV WMV MKV OGV WEBM RM FLV VOB TS"
|
|
|
|
formatFiles="${formatFilesMayus} mp4 avi mpg mpeg mov wmv mkv ogv webm rm flv vob ts"
|
2021-03-28 01:56:41 +01:00
|
|
|
# Rename files
|
|
|
|
cd "${1}"
|
|
|
|
mkdir -p ${ksToolsTempFolder}
|
|
|
|
ls -1 > ${ksToolsTempFolder}/rename-files.txt
|
|
|
|
count=1
|
|
|
|
sizeFile=$(cat ${ksToolsTempFolder}/rename-files.txt | wc -l)
|
|
|
|
while [ ${count} -le ${sizeFile} ] ; do
|
|
|
|
fileToRename=$(cat ${ksToolsTempFolder}/rename-files.txt | head -${count} | tail -1)
|
|
|
|
fileRenamed=$(convertText "${fileToRename}")
|
|
|
|
if [ "${fileRenamed}" == "${fileToRename}" ] ; then
|
|
|
|
echo "null" > /dev/null
|
|
|
|
else
|
|
|
|
mv "${fileToRename}" "${fileRenamed}"
|
|
|
|
fi
|
|
|
|
count=$(expr $count + 1)
|
|
|
|
done
|
|
|
|
# Scan video files
|
|
|
|
rm -rf ${dirTemp}/${listTemp}
|
|
|
|
rm -rf ${dirTemp}/${listCompTemp}
|
|
|
|
for format in ${formatFiles} ; do
|
|
|
|
find "${1}"/*.${format} &> ${dirTemp}/${listCompTempTest}
|
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
echo "null" > /dev/null
|
|
|
|
else
|
|
|
|
find "${1}"/*.${format} &>> ${dirTemp}/${listCompTemp}
|
|
|
|
echo "+ Video file(s) in .${format} found!"
|
|
|
|
cd "${1}" && ls -1 *.${format} &>> ${dirTemp}/${listTemp}
|
|
|
|
fail=0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ ${fail} -eq 1 ] ; then
|
|
|
|
echo "+ No video file(s) found!"
|
|
|
|
echo ""
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
fi
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to count the found files.
|
|
|
|
function countArchives() {
|
2021-03-28 01:56:41 +01:00
|
|
|
totalArchives=$(cat ${dirTemp}/${listCompTemp} | wc -l)
|
|
|
|
echo ${totalArchives}
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to show files with spaces.
|
2021-03-22 19:01:31 +01:00
|
|
|
# Syntax: showFileWithSpace <file number>
|
2021-03-06 12:54:52 +01:00
|
|
|
function showFileWithSpace() {
|
2021-03-28 01:56:41 +01:00
|
|
|
FileName=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
|
|
|
|
FileNoExtension=$(echo $FileName | cut -d "." -f 1)
|
|
|
|
echo $FileNoExtension > ${dirTemp}/name.tmp
|
|
|
|
sed -i 's/_/ /g' ${dirTemp}/name.tmp
|
|
|
|
DisplayName=$(cat ${dirTemp}/name.tmp)
|
|
|
|
rm -rf ${dirTemp}/name.tmp
|
|
|
|
echo ${DisplayName}
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to show the name of the file.
|
2021-03-22 19:01:31 +01:00
|
|
|
# Syntax: showFile <file number>
|
2021-03-06 12:54:52 +01:00
|
|
|
function showFile() {
|
2021-03-28 01:56:41 +01:00
|
|
|
archive=$(cat ${dirTemp}/${listTemp} | head -${1} | tail -1)
|
|
|
|
echo ${archive}
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to show full file path.
|
2021-03-22 19:01:31 +01:00
|
|
|
# Syntax: showPathFile <file number>
|
2021-03-06 12:54:52 +01:00
|
|
|
function showPathFile() {
|
2021-03-28 01:56:41 +01:00
|
|
|
pathFile=$(cat ${dirTemp}/${listCompTemp} | head -${1} | tail -1)
|
|
|
|
echo ${pathFile}
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to send file to server.
|
2021-03-22 19:01:31 +01:00
|
|
|
# Syntax: sendFile <password> <file path> <user> <server> <server path> [file name]
|
2021-03-06 12:54:52 +01:00
|
|
|
function sendFile() {
|
2021-03-28 01:56:41 +01:00
|
|
|
correct=0
|
|
|
|
countSend=0
|
2022-01-21 22:06:47 +01:00
|
|
|
toolSelected=$(cat ${dirConfig}/ks-upload-tool)
|
2022-01-25 20:11:59 +01:00
|
|
|
portSelected=$(cat ${dirConfig}/ks-upload-port)
|
2021-03-28 01:56:41 +01:00
|
|
|
while [ ${correct} -eq 0 ] ; do
|
2022-01-21 22:06:47 +01:00
|
|
|
# Run command for upload on Windows (Cygwin)
|
2021-03-29 18:08:57 +02:00
|
|
|
if [ "${cygwin}" == "yes" ] ; then
|
2022-01-21 22:06:47 +01:00
|
|
|
if [ "${toolSelected}" == "rsync" ] ; then
|
2023-02-10 13:11:36 +01:00
|
|
|
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null
|
|
|
|
/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
|
2022-01-21 22:06:47 +01:00
|
|
|
OUTPUT=$?
|
2022-01-23 00:03:17 +01:00
|
|
|
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
|
2023-02-10 13:11:36 +01:00
|
|
|
/usr/bin/rsync --progress -azL --rsh="/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null
|
|
|
|
/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
|
2022-01-23 00:03:17 +01:00
|
|
|
OUTPUT=$?
|
|
|
|
elif [ "${toolSelected}" == "scp-rsa" ] ; then
|
2023-02-10 13:11:36 +01:00
|
|
|
/usr/bin/sshpass -p ${1} /usr/bin/scp -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null
|
2022-01-23 00:03:17 +01:00
|
|
|
OUTPUT=$?
|
2022-01-21 22:06:47 +01:00
|
|
|
else
|
2023-02-10 13:11:36 +01:00
|
|
|
/usr/bin/sshpass -p ${1} /usr/bin/scp -o StrictHostKeyChecking=no -o CheckHostIP=no -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null
|
2022-01-21 22:06:47 +01:00
|
|
|
OUTPUT=$?
|
|
|
|
fi
|
|
|
|
# Run command for upload on Unix systems
|
2021-03-29 18:08:57 +02:00
|
|
|
else
|
2022-01-21 22:06:47 +01:00
|
|
|
if [ "${toolSelected}" == "rsync" ] ; then
|
2023-02-10 13:11:36 +01:00
|
|
|
rsync --progress -azL --rsh="sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null
|
|
|
|
sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
|
2022-01-21 22:06:47 +01:00
|
|
|
OUTPUT=$?
|
2022-01-23 00:03:17 +01:00
|
|
|
elif [ "${toolSelected}" == "rsync-rsa" ] ; then
|
2023-02-10 13:11:36 +01:00
|
|
|
rsync --progress -azL --rsh="sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} -l ${3}" ${2} ${4}:${5} 2> /dev/null
|
|
|
|
sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} rm -rf ${5}/.${6}.* &> /dev/null
|
2022-01-23 00:03:17 +01:00
|
|
|
OUTPUT=$?
|
|
|
|
elif [ "${toolSelected}" == "scp-rsa" ] ; then
|
2023-02-10 13:11:36 +01:00
|
|
|
sshpass -p ${1} scp -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null
|
2022-01-23 00:03:17 +01:00
|
|
|
OUTPUT=$?
|
2021-03-29 18:08:57 +02:00
|
|
|
else
|
2023-02-10 13:11:36 +01:00
|
|
|
sshpass -p ${1} scp -o StrictHostKeyChecking=no -o CheckHostIP=no -P ${portSelected} ${2} ${3}@${4}:${5} 2> /dev/null
|
2022-01-21 22:06:47 +01:00
|
|
|
OUTPUT=$?
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ ${OUTPUT} -ne 0 ] ; then
|
|
|
|
echo "Failure to send ${2}"
|
|
|
|
echo "Retrying..."
|
|
|
|
sleep 5
|
|
|
|
countSend=$(expr ${countSend} + 1)
|
|
|
|
if [ ${countSend} -eq 3 ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
correct=1
|
|
|
|
fi
|
2022-01-21 22:06:47 +01:00
|
|
|
else
|
|
|
|
correct=1
|
2021-03-28 01:56:41 +01:00
|
|
|
fi
|
|
|
|
done
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to check local and server checksum.
|
2021-03-22 19:01:31 +01:00
|
|
|
# Syntax: checkChecksum <password> <local file path> <user> <server> <server file path>
|
2021-03-06 12:54:52 +01:00
|
|
|
function checkChecksum() {
|
2021-03-28 01:56:41 +01:00
|
|
|
correct=0
|
|
|
|
countChecksum=0
|
|
|
|
echo -n "Checking checksum... " && sleep 4
|
|
|
|
echo ""
|
2022-01-23 00:03:17 +01:00
|
|
|
toolSelected=$(cat ${dirConfig}/ks-upload-tool | grep "rsa")
|
2022-01-25 20:11:59 +01:00
|
|
|
portSelected=$(cat ${dirConfig}/ks-upload-port)
|
2022-01-21 22:06:47 +01:00
|
|
|
while [ ${correct} -eq 0 ] ; do
|
|
|
|
if [ "${cygwin}" == "yes" ] ; then
|
2022-01-23 00:03:17 +01:00
|
|
|
if [ -z "${toolSelected}" ] ; then
|
|
|
|
checksumLocal=$(/usr/bin/md5sum ${2})
|
2023-02-10 13:11:36 +01:00
|
|
|
checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null)
|
2022-01-23 00:03:17 +01:00
|
|
|
OUTPUT=$?
|
|
|
|
else
|
|
|
|
checksumLocal=$(/usr/bin/md5sum ${2})
|
2023-02-10 13:11:36 +01:00
|
|
|
checksumServer=$(/usr/bin/sshpass -p ${1} /usr/bin/ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null)
|
2022-01-23 00:03:17 +01:00
|
|
|
OUTPUT=$?
|
|
|
|
fi
|
2022-01-21 22:06:47 +01:00
|
|
|
else
|
2022-01-23 00:03:17 +01:00
|
|
|
if [ -z "${toolSelected}" ] ; then
|
|
|
|
checksumLocal=$(md5sum ${2})
|
2023-02-10 13:11:36 +01:00
|
|
|
checksumServer=$(sshpass -p ${1} ssh -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null)
|
2022-01-23 00:03:17 +01:00
|
|
|
OUTPUT=$?
|
|
|
|
else
|
|
|
|
checksumLocal=$(md5sum ${2})
|
2023-02-10 13:11:36 +01:00
|
|
|
checksumServer=$(sshpass -p ${1} ssh -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no -o CheckHostIP=no -p ${portSelected} ${3}@${4} md5sum ${5} 2> /dev/null)
|
2022-01-23 00:03:17 +01:00
|
|
|
OUTPUT=$?
|
|
|
|
fi
|
2022-01-21 22:06:47 +01:00
|
|
|
fi
|
|
|
|
if [ ${OUTPUT} -ne 0 ] ; then
|
|
|
|
echo "Failed to get checksum for ${5}"
|
|
|
|
echo "Retrying..."
|
|
|
|
sleep 5
|
|
|
|
countChecksum=$(expr ${countChecksum} + 1)
|
|
|
|
if [ ${countChecksum} -eq 3 ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
correct=1
|
|
|
|
fi
|
2022-01-21 22:06:47 +01:00
|
|
|
else
|
|
|
|
echo "Local checksum: ${checksumLocal}"
|
|
|
|
echo "Server checksum: ${checksumServer}"
|
|
|
|
correct=1
|
|
|
|
fi
|
|
|
|
done
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
2022-01-03 19:06:15 +01:00
|
|
|
# Generate random codes
|
|
|
|
function generate_codes() {
|
|
|
|
chars="abcdefghijklmnopqrstywxz1234567890ABCDEFHIJKLMNOPQRSTYWXZ@/"
|
|
|
|
long_code="${1}"
|
|
|
|
for i in {1} ; do
|
|
|
|
echo -n "${chars:RANDOM%${#chars}:1}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to encrypt pass on config file
|
|
|
|
# Syntax: encrypt_kstools <password>
|
|
|
|
function encrypt_kstools() {
|
|
|
|
raw_pass="${1}"
|
|
|
|
characters_pass_raw=$(echo ${raw_pass} | wc -m)
|
|
|
|
characters_pass=$(expr ${characters_pass_raw} - 1)
|
|
|
|
total_characters=0
|
|
|
|
mkdir -p ${HOME}/.ks-tools/
|
|
|
|
rm -rf ${HOME}/.ks-tools/.seq-codes
|
|
|
|
while [ ${total_characters} -le ${characters_pass} ] ; do
|
|
|
|
num_gen=$(echo -n ${RANDOM} | cut -c1)
|
|
|
|
echo -n ${num_gen} >> ${HOME}/.ks-tools/.seq-codes
|
|
|
|
total_characters=$(expr ${total_characters} + 1)
|
|
|
|
done
|
|
|
|
characters_seq_raw=$(cat ${HOME}/.ks-tools/.seq-codes 2> /dev/null | wc -m)
|
|
|
|
characters_seq=$(expr ${characters_seq_raw} - 1)
|
|
|
|
total_characters=1
|
|
|
|
encrypted_pass=""
|
|
|
|
while [ ${total_characters} -le ${characters_pass} ] ; do
|
|
|
|
num_seq_read=$(cat ${HOME}/.ks-tools/.seq-codes 2> /dev/null | cut -c${total_characters})
|
|
|
|
character=$(echo ${raw_pass} | cut -c${total_characters})
|
|
|
|
repeat_seq=0
|
|
|
|
while [ ${repeat_seq} -lt ${num_seq_read} ] ; do
|
|
|
|
code_gen=$(generate_codes)
|
|
|
|
encrypted_pass="${encrypted_pass}${code_gen}"
|
|
|
|
repeat_seq=$(expr ${repeat_seq} + 1)
|
|
|
|
done
|
|
|
|
encrypted_pass="${encrypted_pass}${character}"
|
|
|
|
total_characters=$(expr ${total_characters} + 1)
|
|
|
|
done
|
|
|
|
code_gen=$(generate_codes)
|
|
|
|
encrypted_pass="${encrypted_pass}${code_gen}"
|
|
|
|
echo ${encrypted_pass}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to decrypt pass on config file
|
|
|
|
# Syntax: decrypt_kstools <password>
|
|
|
|
function decrypt_kstools() {
|
|
|
|
raw_pass_encrypted="${1}"
|
|
|
|
total_characters=1
|
|
|
|
codes_seq=$(cat ${HOME}/.ks-tools/.seq-codes 2> /dev/null)
|
|
|
|
num_codes_seq=$(cat ${HOME}/.ks-tools/.seq-codes 2> /dev/null | wc -m)
|
|
|
|
pass_decrypt=""
|
|
|
|
total_characters=1
|
|
|
|
pos_codes_pass=0
|
|
|
|
while [ ${total_characters} -lt ${num_codes_seq} ] ; do
|
|
|
|
pos_codes=$(echo ${codes_seq} | cut -c${total_characters})
|
|
|
|
pos_codes_pass=$(expr ${pos_codes_pass} + ${pos_codes} + 1)
|
|
|
|
pos_pass=$(expr ${raw_pass_encrypted} | cut -c${pos_codes_pass})
|
|
|
|
pass_decrypt="${pass_decrypt}${pos_pass}"
|
|
|
|
total_characters=$(expr ${total_characters} + 1)
|
|
|
|
done
|
|
|
|
echo ${pass_decrypt}
|
|
|
|
}
|
|
|
|
|
2021-03-06 12:54:52 +01:00
|
|
|
# Function to show config
|
|
|
|
function showConfig() {
|
2021-03-28 01:56:41 +01:00
|
|
|
configAvailable=0
|
|
|
|
echo ""
|
|
|
|
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
2022-01-03 19:06:15 +01:00
|
|
|
if [ -f ${dirConfig}/ks-upload-user ] ; then
|
|
|
|
showUser=$(cat ${dirConfig}/ks-upload-user)
|
2021-03-28 01:56:41 +01:00
|
|
|
echo "- Server User: ${showUser}"
|
|
|
|
configAvailable=1
|
|
|
|
fi
|
2022-01-03 19:06:15 +01:00
|
|
|
if [ -f ${dirConfig}/ks-upload-pass ] ; then
|
|
|
|
readPasswordEncrypted=$(cat ${dirConfig}/ks-upload-pass)
|
|
|
|
readPasswordDecrypted=$(decrypt_kstools "${readPasswordEncrypted}")
|
|
|
|
readPasswordChars=$(echo ${readPasswordDecrypted} | wc -m)
|
|
|
|
totalchars=0
|
|
|
|
showPassword=""
|
|
|
|
while [ ${totalchars} -lt ${readPasswordChars} ] ; do
|
|
|
|
showPassword="${showPassword}*"
|
|
|
|
totalchars=$(expr ${totalchars} + 1)
|
|
|
|
done
|
2021-03-28 01:56:41 +01:00
|
|
|
echo "- Server Password: ${showPassword}"
|
|
|
|
configAvailable=1
|
|
|
|
fi
|
2022-01-03 19:06:15 +01:00
|
|
|
if [ -f ${dirConfig}/ks-upload-server ] ; then
|
|
|
|
showServer=$(cat ${dirConfig}/ks-upload-server)
|
2021-03-28 01:56:41 +01:00
|
|
|
echo "- URL (or IP) Server: ${showServer}"
|
|
|
|
configAvailable=1
|
|
|
|
fi
|
2022-01-03 19:06:15 +01:00
|
|
|
if [ -f ${dirConfig}/ks-upload-dirserver ] ; then
|
|
|
|
showDirServer=$(cat ${dirConfig}/ks-upload-dirserver)
|
2021-03-28 01:56:41 +01:00
|
|
|
echo "- Destination Path (Server): ${showDirServer}"
|
|
|
|
configAvailable=1
|
|
|
|
fi
|
2022-01-03 19:06:15 +01:00
|
|
|
if [ -f ${dirConfig}/ks-upload-dirlocal ] ; then
|
|
|
|
showDirLocal=$(cat ${dirConfig}/ks-upload-dirlocal)
|
2021-03-28 01:56:41 +01:00
|
|
|
echo "- Scan Path (Local): ${showDirLocal}"
|
|
|
|
configAvailable=1
|
|
|
|
fi
|
2022-01-21 21:22:01 +01:00
|
|
|
if [ -f ${dirConfig}/ks-upload-tool ] ; then
|
|
|
|
showUpvTool=$(cat ${dirConfig}/ks-upload-tool)
|
|
|
|
echo "- Upload Tool: ${showUpvTool}"
|
|
|
|
configAvailable=1
|
|
|
|
fi
|
2022-01-25 20:11:59 +01:00
|
|
|
if [ -f ${dirConfig}/ks-upload-port ] ; then
|
|
|
|
showUpvPort=$(cat ${dirConfig}/ks-upload-port)
|
|
|
|
echo "- Port Connection: ${showUpvPort}"
|
|
|
|
configAvailable=1
|
|
|
|
fi
|
2021-03-28 01:56:41 +01:00
|
|
|
if [ ${configAvailable} -eq 0 ] ; then
|
|
|
|
echo "* The configuration file does not exist!"
|
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
exit
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to edit the configuration file
|
|
|
|
function editConfig() {
|
2021-03-28 01:56:41 +01:00
|
|
|
editConfig=0
|
|
|
|
while [ ${editConfig} -eq 0 ] ; do
|
|
|
|
clear
|
2022-01-03 19:06:15 +01:00
|
|
|
editUser=$(cat ${dirConfig}/ks-upload-user 2> /dev/null)
|
|
|
|
readPasswordEncrypted=$(cat ${dirConfig}/ks-upload-pass)
|
|
|
|
readPasswordDecrypted=$(decrypt_kstools "${readPasswordEncrypted}")
|
|
|
|
readPasswordChars=$(echo ${readPasswordDecrypted} | wc -m)
|
|
|
|
totalchars=0
|
|
|
|
editPassword=""
|
|
|
|
while [ ${totalchars} -lt ${readPasswordChars} ] ; do
|
|
|
|
editPassword="${editPassword}*"
|
|
|
|
totalchars=$(expr ${totalchars} + 1)
|
|
|
|
done
|
|
|
|
editServer=$(cat ${dirConfig}/ks-upload-server 2> /dev/null)
|
|
|
|
editDirServer=$(cat ${dirConfig}/ks-upload-dirserver 2> /dev/null)
|
|
|
|
editDirLocal=$(cat ${dirConfig}/ks-upload-dirlocal 2> /dev/null)
|
2022-01-21 21:22:01 +01:00
|
|
|
editUpvTool=$(cat ${dirConfig}/ks-upload-tool 2> /dev/null)
|
2022-01-25 20:11:59 +01:00
|
|
|
editUpvPort=$(cat ${dirConfig}/ks-upload-port 2> /dev/null)
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
|
|
|
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
2022-01-25 20:11:59 +01:00
|
|
|
echo "+ Config: ${dirConfig}/ks-upload-*"
|
|
|
|
echo ""
|
2021-03-28 01:56:41 +01:00
|
|
|
echo " 1 - Edit User (${editUser})"
|
|
|
|
echo " 2 - Edit Password (${editPassword})"
|
|
|
|
echo " 3 - Edit Server (${editServer})"
|
|
|
|
echo " 4 - Edit Dest. Path (${editDirServer})"
|
|
|
|
echo " 5 - Edit Local Path (${editDirLocal})"
|
2022-01-21 21:22:01 +01:00
|
|
|
echo " 6 - Edit Upload Tool (${editUpvTool})"
|
2022-01-25 20:11:59 +01:00
|
|
|
echo " 7 - Edit Port Connection (${editUpvPort})"
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
2022-01-25 20:11:59 +01:00
|
|
|
echo " 8 - Exit"
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
|
|
|
echo -n "* Choose an option: " ; read EDIT
|
|
|
|
echo ""
|
|
|
|
if [ "${EDIT}" == "1" ] ; then
|
|
|
|
echo -n "* Enter the server user: " ; read USER
|
|
|
|
user=${USER}
|
2022-01-03 19:06:15 +01:00
|
|
|
echo ${user} > ${dirConfig}/ks-upload-user
|
2021-03-28 01:56:41 +01:00
|
|
|
elif [ "${EDIT}" == "2" ] ; then
|
2022-01-28 18:15:10 +01:00
|
|
|
echo -n "* Enter the server password: " ; read PASS
|
2022-01-03 19:06:15 +01:00
|
|
|
raw_password_enter=${PASS}
|
|
|
|
encrypt_password_enter=$(encrypt_kstools "${raw_password_enter}")
|
|
|
|
echo ${encrypt_password_enter} > ${dirConfig}/ks-upload-pass
|
2021-03-28 01:56:41 +01:00
|
|
|
elif [ "${EDIT}" == "3" ] ; then
|
|
|
|
echo -n "* Enter the server URL: " ; read SERVER
|
|
|
|
server=${SERVER}
|
2022-01-03 19:06:15 +01:00
|
|
|
echo ${server} > ${dirConfig}/ks-upload-server
|
2021-03-28 01:56:41 +01:00
|
|
|
elif [ "${EDIT}" == "4" ] ; then
|
|
|
|
echo -n "* Enter the path on the server: " ; read DIR_SERVER
|
|
|
|
dirServer=${DIR_SERVER}
|
2022-01-03 19:06:15 +01:00
|
|
|
echo ${dirServer} > ${dirConfig}/ks-upload-dirserver
|
2021-03-28 01:56:41 +01:00
|
|
|
elif [ "${EDIT}" == "5" ] ; then
|
|
|
|
echo -n "* Enter the local path to scan: " ; read DIR
|
|
|
|
dirLocal=${DIR}
|
2022-01-03 19:06:15 +01:00
|
|
|
echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal
|
2022-01-21 21:22:01 +01:00
|
|
|
elif [ "${EDIT}" == "6" ] ; then
|
2022-01-23 00:03:17 +01:00
|
|
|
echo ""
|
|
|
|
echo "* Available options:"
|
|
|
|
echo ""
|
|
|
|
echo "- scp"
|
|
|
|
echo "- rsync"
|
|
|
|
echo "- scp-rsa (legacy RSA algorithm)"
|
|
|
|
echo "- rsync-rsa (legacy RSA algorithm)"
|
|
|
|
echo ""
|
|
|
|
echo -n "* [Default: scp] Type upload tool (scp/rsync/scp-rsa/rsync-rsa): " ; read TOOL
|
2022-01-21 21:22:01 +01:00
|
|
|
if [ -z "${TOOL}" ] ; then
|
|
|
|
upvTool="scp"
|
2022-01-23 00:03:17 +01:00
|
|
|
elif [ "${TOOL}" == "rsync" ] ; then
|
|
|
|
upvTool="rsync"
|
|
|
|
elif [ "${TOOL}" == "rsync-rsa" ] ; then
|
|
|
|
upvTool="rsync-rsa"
|
|
|
|
elif [ "${TOOL}" == "scp-rsa" ] ; then
|
|
|
|
upvTool="scp-rsa"
|
2022-01-21 21:22:01 +01:00
|
|
|
else
|
2022-01-23 00:03:17 +01:00
|
|
|
upvTool="scp"
|
2022-01-21 21:22:01 +01:00
|
|
|
fi
|
|
|
|
echo ${upvTool} > ${dirConfig}/ks-upload-tool
|
|
|
|
elif [ "${EDIT}" == "7" ] ; then
|
2022-01-25 20:11:59 +01:00
|
|
|
echo -n "* [Default: 22] Type port connection: " ; read PORT
|
|
|
|
if [ -z "${PORT}" ] ; then
|
|
|
|
upvPort="22"
|
|
|
|
else
|
|
|
|
upvPort="${PORT}"
|
|
|
|
fi
|
|
|
|
echo ${upvPort} > ${dirConfig}/ks-upload-port
|
|
|
|
elif [ "${EDIT}" == "8" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
editConfig=1
|
|
|
|
else
|
|
|
|
echo "+ Invalid option!"
|
|
|
|
echo -n "- Press ENTER to continue " ; read CONTINUE
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
exit
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
2022-01-04 11:58:24 +01:00
|
|
|
# Function to create initial config file.
|
|
|
|
function createConfig() {
|
|
|
|
# Start script
|
|
|
|
clear
|
|
|
|
echo ""
|
|
|
|
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
|
|
|
checkDependencies
|
|
|
|
# Ask the user and if it exists, read it from the config.
|
|
|
|
if [ -f ${dirConfig}/ks-upload-user ] ; then
|
|
|
|
echo "+ The USER configuration already exists (Use: 'ks-upv -e' for edit)"
|
|
|
|
else
|
|
|
|
echo -n "* Enter the server user: " ; read USER
|
|
|
|
user=${USER}
|
|
|
|
echo ${user} > ${dirConfig}/ks-upload-user
|
|
|
|
fi
|
|
|
|
# Ask the password and if it exists, read it from the config.
|
|
|
|
if [ -f ${dirConfig}/ks-upload-pass ] ; then
|
|
|
|
echo "+ The PASSWORD configuration already exists (Use: 'ks-upv -e' for edit)"
|
|
|
|
else
|
|
|
|
echo -n "* Enter the server password: " ; read PASS
|
|
|
|
raw_password_enter=${PASS}
|
|
|
|
encrypt_password_enter=$(encrypt_kstools "${raw_password_enter}")
|
|
|
|
echo ${encrypt_password_enter} > ${dirConfig}/ks-upload-pass
|
|
|
|
fi
|
|
|
|
# Ask the server URL and if it exists, read it from the config.
|
|
|
|
if [ -f ${dirConfig}/ks-upload-server ] ; then
|
|
|
|
echo "+ The SERVER configuration already exists (Use: 'ks-upv -e' for edit)"
|
|
|
|
else
|
|
|
|
echo -n "* Enter the server URL: " ; read SERVER
|
|
|
|
server=${SERVER}
|
|
|
|
echo ${server} > ${dirConfig}/ks-upload-server
|
|
|
|
fi
|
|
|
|
# Ask the path on the server and if it exists, read it from the config.
|
|
|
|
if [ -f ${dirConfig}/ks-upload-dirserver ] ; then
|
|
|
|
echo "+ The SERVER PATH configuration already exists (Use: 'ks-upv -e' for edit)"
|
|
|
|
else
|
|
|
|
echo -n "* Enter the path on the server: " ; read DIR_SERVER
|
|
|
|
dirServer=${DIR_SERVER}
|
|
|
|
echo ${dirServer} > ${dirConfig}/ks-upload-dirserver
|
|
|
|
fi
|
|
|
|
# Ask the local path and if it exists, read it from the config.
|
|
|
|
if [ -f ${dirConfig}/ks-upload-dirlocal ] ; then
|
|
|
|
echo "+ The LOCAL PATH configuration already exists (Use: 'ks-upv -e' for edit)"
|
|
|
|
else
|
|
|
|
echo -n "* Enter the local path to scan: " ; read DIR
|
|
|
|
dirLocal=${DIR}
|
|
|
|
echo ${dirLocal} > ${dirConfig}/ks-upload-dirlocal
|
|
|
|
fi
|
2022-01-21 21:22:01 +01:00
|
|
|
# Configure upload tool by default
|
|
|
|
if [ -f ${dirConfig}/ks-upload-tool ] ; then
|
2022-01-23 00:09:05 +01:00
|
|
|
echo "+ The UPLOAD TOOL configuration already exists (Use: 'ks-upv -e' for edit)"
|
2022-01-21 21:22:01 +01:00
|
|
|
else
|
2022-01-25 20:11:59 +01:00
|
|
|
echo "* Setting 'scp' as the default tool"
|
2022-01-21 21:22:01 +01:00
|
|
|
echo "scp" > ${dirConfig}/ks-upload-tool
|
2022-01-25 20:11:59 +01:00
|
|
|
fi
|
|
|
|
# Configure port by default
|
|
|
|
if [ -f ${dirConfig}/ks-upload-port ] ; then
|
|
|
|
echo "+ The PORT configuration already exists (Use: 'ks-upv -e' for edit)"
|
|
|
|
else
|
|
|
|
echo "* Setting port 22 as the default port"
|
|
|
|
echo "22" > ${dirConfig}/ks-upload-port
|
2022-01-21 21:22:01 +01:00
|
|
|
fi
|
2022-01-04 11:58:24 +01:00
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2021-03-06 12:54:52 +01:00
|
|
|
# Function to show version
|
|
|
|
function showVersion() {
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
|
|
|
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
|
|
|
exit
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to show help
|
|
|
|
function showHelp() {
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
|
|
|
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
2022-01-23 00:03:17 +01:00
|
|
|
echo "- Upload videos file(s) to server with scp or rsync"
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ""
|
2022-01-25 20:11:59 +01:00
|
|
|
echo "+ Config: ${dirConfig}/ks-upload-*"
|
|
|
|
echo ""
|
2021-03-28 01:56:41 +01:00
|
|
|
echo "+ Syntax:"
|
|
|
|
echo ""
|
|
|
|
echo " $ ks-upv -i - Start upload"
|
2022-01-04 11:58:24 +01:00
|
|
|
echo " $ ks-upv -g - Create configuration"
|
2021-03-28 01:56:41 +01:00
|
|
|
echo " $ ks-upv -r - Remove configuration"
|
|
|
|
echo " $ ks-upv -c - Show configuration"
|
|
|
|
echo " $ ks-upv -e - Edit configuration"
|
|
|
|
echo " $ ks-upv -v - Show version"
|
|
|
|
echo " $ ks-upv -h - Show help"
|
|
|
|
echo ""
|
|
|
|
exit
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to check if all the necessary tools
|
|
|
|
# for the execution are installed.
|
|
|
|
function checkDependencies() {
|
2021-03-28 01:56:41 +01:00
|
|
|
dependence=0
|
|
|
|
echo -n "* Checking necessary tools... "
|
|
|
|
sleep 3 && echo ""
|
|
|
|
sshpass -h &> /dev/null
|
|
|
|
OUTPUT=$?
|
|
|
|
if [ ${OUTPUT} -ne 0 ] ; then
|
|
|
|
echo "* The 'sshpass' tool is not installed!"
|
|
|
|
dependence=1
|
|
|
|
fi
|
|
|
|
md5sum --help &> /dev/null
|
|
|
|
OUTPUT=$?
|
|
|
|
if [ ${OUTPUT} -ne 0 ] ; then
|
|
|
|
echo "* The 'md5sum' tool is not installed!"
|
|
|
|
dependence=1
|
|
|
|
fi
|
|
|
|
rsync --version &> /dev/null
|
|
|
|
OUTPUT=$?
|
|
|
|
if [ ${OUTPUT} -ne 0 ] ; then
|
|
|
|
echo "* The 'rsync' tool is not installed!"
|
|
|
|
dependence=1
|
|
|
|
fi
|
|
|
|
if [ -f /usr/bin/scp ] ; then
|
|
|
|
echo "OK" > /dev/null
|
|
|
|
else
|
|
|
|
echo "* The 'scp' tool is not installed!"
|
|
|
|
dependence=1
|
|
|
|
fi
|
|
|
|
if [ -f /usr/bin/ssh ] ; then
|
|
|
|
echo "OK" > /dev/null
|
|
|
|
else
|
|
|
|
echo "* The 'ssh' tool is not installed!"
|
|
|
|
dependence=1
|
|
|
|
fi
|
|
|
|
if [ ${dependence} -eq 0 ] ; then
|
|
|
|
echo "* Necessary tools installed!"
|
|
|
|
echo ""
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
exit
|
|
|
|
fi
|
2021-03-06 12:54:52 +01:00
|
|
|
}
|
|
|
|
|
2022-01-03 19:31:11 +01:00
|
|
|
# Function to migrate old configuration.
|
|
|
|
if [ -f ${dirConfig}/USER ] ; then
|
|
|
|
cat ${dirConfig}/USER > ${dirConfig}/ks-upload-user
|
|
|
|
echo "* Migrating ${dirConfig}/USER > ${dirConfig}/ks-upload-user"
|
|
|
|
rm -rf ${dirConfig}/USER
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
if [ -f ${dirConfig}/PASS ] ; then
|
|
|
|
echo "* Migrating ${dirConfig}/PASS > ${dirConfig}/ks-upload-pass"
|
|
|
|
current_pass=$(cat ${dirConfig}/PASS)
|
|
|
|
encrypt_kstools "${current_pass}" > ${dirConfig}/ks-upload-pass
|
|
|
|
rm -rf ${dirConfig}/PASS
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
if [ -f ${dirConfig}/SERVER ] ; then
|
|
|
|
cat ${dirConfig}/SERVER > ${dirConfig}/ks-upload-server
|
|
|
|
echo "* Migrating ${dirConfig}/SERVER > ${dirConfig}/ks-upload-server"
|
|
|
|
rm -rf ${dirConfig}/SERVER
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
if [ -f ${dirConfig}/DIR_SERVER ] ; then
|
|
|
|
cat ${dirConfig}/DIR_SERVER > ${dirConfig}/ks-upload-dirserver
|
|
|
|
echo "* Migrating ${dirConfig}/DIR_SERVER > ${dirConfig}/ks-upload-dirserver"
|
|
|
|
rm -rf ${dirConfig}/DIR_SERVER
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
if [ -f ${dirConfig}/DIR ] ; then
|
|
|
|
cat ${dirConfig}/DIR > ${dirConfig}/ks-upload-dirlocal
|
|
|
|
echo "* Migrating ${dirConfig}/DIR > ${dirConfig}/ks-upload-dirlocal"
|
|
|
|
rm -rf ${dirConfig}/DIR
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
2021-03-06 12:54:52 +01:00
|
|
|
# Check if the configuration directory exists.
|
|
|
|
if [ -d ${dirConfig} ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
echo ${dirConfig} > /dev/null
|
2021-03-06 12:54:52 +01:00
|
|
|
else
|
2021-03-28 01:56:41 +01:00
|
|
|
mkdir -p ${dirConfig}
|
2021-03-06 12:54:52 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Delete the existing configuration.
|
2022-01-04 12:10:33 +01:00
|
|
|
if [ "${1}" == "-r" ] ; then
|
|
|
|
echo ""
|
|
|
|
echo "* ks-upv (ks-tools) v${VERSION} (${M_DATE})"
|
|
|
|
echo ""
|
|
|
|
echo -n "* [Default: n] Are you sure you want to delete the configuration? (y/n): " ; read confirm
|
|
|
|
if [ "${confirm}" == "y" ] ; then
|
|
|
|
echo ""
|
|
|
|
echo "+ Removing USER file configuration..."
|
|
|
|
rm -rf ${dirConfig}/ks-upload-user
|
|
|
|
echo "+ Removing PASSWORD file configuration..."
|
|
|
|
rm -rf ${dirConfig}/ks-upload-pass
|
|
|
|
echo "+ Removing SERVER file configuration..."
|
|
|
|
rm -rf ${dirConfig}/ks-upload-server
|
|
|
|
echo "+ Removing SERVER PATH file configuration..."
|
|
|
|
rm -rf ${dirConfig}/ks-upload-dirserver
|
|
|
|
echo "+ Removing LOCAL PATH file configuration..."
|
|
|
|
rm -rf ${dirConfig}/ks-upload-dirlocal
|
|
|
|
echo "* Removed all configuration"
|
2022-01-25 20:11:59 +01:00
|
|
|
rm -rf ${dirConfig}/ks-upload-tool
|
|
|
|
rm -rf ${dirConfig}/ks-upload-port
|
2022-01-04 12:10:33 +01:00
|
|
|
echo ""
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
echo "+ Remove configuration canceled"
|
|
|
|
echo ""
|
|
|
|
exit
|
|
|
|
fi
|
2021-03-06 12:54:52 +01:00
|
|
|
fi
|
|
|
|
# Show configuration file
|
2022-01-04 12:35:09 +01:00
|
|
|
if [ "${1}" == "-c" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
showConfig
|
|
|
|
# Show configuration file
|
2022-01-04 12:35:09 +01:00
|
|
|
elif [ "${1}" == "-e" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
editConfig
|
|
|
|
# Show the version
|
2022-01-04 12:35:09 +01:00
|
|
|
elif [ "${1}" == "-v" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
showVersion
|
|
|
|
# Show the help
|
2022-01-04 12:35:09 +01:00
|
|
|
elif [ "${1}" == "-h" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
showHelp
|
2022-01-04 11:58:24 +01:00
|
|
|
# Create config
|
2022-01-04 12:35:09 +01:00
|
|
|
elif [ "${1}" == "-g" ] ; then
|
2022-01-04 11:58:24 +01:00
|
|
|
createConfig
|
2021-03-28 01:56:41 +01:00
|
|
|
# Init
|
2022-01-04 12:35:09 +01:00
|
|
|
elif [ "${1}" == "-i" ] ; then
|
2021-03-28 01:56:41 +01:00
|
|
|
# Start script
|
2022-01-04 11:58:24 +01:00
|
|
|
createConfig
|
|
|
|
user=$(cat ${dirConfig}/ks-upload-user)
|
|
|
|
raw_password=$(cat ${dirConfig}/ks-upload-pass)
|
|
|
|
password=$(decrypt_kstools "${raw_password}")
|
|
|
|
server=$(cat ${dirConfig}/ks-upload-server)
|
|
|
|
dirServer=$(cat ${dirConfig}/ks-upload-dirserver)
|
|
|
|
dirLocal=$(cat ${dirConfig}/ks-upload-dirlocal)
|
2021-03-28 01:56:41 +01:00
|
|
|
# Call the functions to perform the whole process.
|
|
|
|
echo -n "* Scanning ${dirLocal} " && sleep 4
|
|
|
|
echo ""
|
|
|
|
if [ -d ${dirLocal} ] ; then
|
|
|
|
listArchives "${dirLocal}"
|
|
|
|
totalFiles=$(countArchives)
|
|
|
|
count=1
|
|
|
|
echo "+ ${totalFiles} video file(s) found!"
|
|
|
|
echo ""
|
2022-01-21 23:41:16 +01:00
|
|
|
current_tool=$(cat ${dirConfig}/ks-upload-tool)
|
|
|
|
if [ "${current_tool}" == "scp" ] ; then
|
|
|
|
echo "* NOTE: You are using 'scp' to upload files and no progress will be shown."
|
|
|
|
echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)"
|
|
|
|
echo ""
|
|
|
|
fi
|
2022-01-23 00:03:17 +01:00
|
|
|
if [ "${current_tool}" == "scp-rsa" ] ; then
|
|
|
|
echo "* NOTE: You are using 'scp' to upload files and no progress will be shown."
|
|
|
|
echo "* IMPORTANT: It's possible switch to 'rsync' if you wish (Command: ks-upv -e)"
|
|
|
|
echo ""
|
|
|
|
fi
|
2021-03-28 01:56:41 +01:00
|
|
|
while [ ${count} -le ${totalFiles} ] ; do
|
|
|
|
fullNameFile=$(showFile ${count})
|
|
|
|
fullPathFile=$(showPathFile ${count})
|
|
|
|
echo "Uploading '${fullNameFile}' "
|
|
|
|
sendFile ${password} ${fullPathFile} ${user} ${server} ${dirServer} ${fullNameFile}
|
|
|
|
checkChecksum ${password} ${fullPathFile} ${user} ${server} ${dirServer}/${fullNameFile}
|
|
|
|
echo ""
|
|
|
|
count=$(expr ${count} + 1)
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "* Directory ${dirLocal} does not exist!"
|
|
|
|
echo ""
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
# Show help
|
2021-03-06 12:54:52 +01:00
|
|
|
else
|
2021-03-28 01:56:41 +01:00
|
|
|
showHelp
|
2021-03-06 12:54:52 +01:00
|
|
|
fi
|