Created
May 12, 2019 14:41
-
-
Save LostInsight/708e4b7ff8ef1c1b33e4a4814a761823 to your computer and use it in GitHub Desktop.
Shell script to fix permission for downloaded files, upload to cloud with onedrivecmd, refresh customized oneindex cache, and notify with serverchan.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo `date --rfc-3339=seconds` "oneup.sh" "$1" "$2" "$3">>/tmp/oneup.log | |
GID="$1"; | |
FileNum="$2"; | |
File="$3"; | |
MaxSize="15728640" | |
RemoteDIR="od:/share/Downloads"; # no "/" at last | |
LocalDIR="/data/downloads"; # no "/" at last | |
serverchan="https://sc.ftqq.com/SCKey.send" | |
if [[ -z $(echo "$FileNum" |grep -o '[0-9]*' |head -n1) ]]; then FileNum='0'; fi | |
if [[ "$FileNum" -le '0' ]]; then exit 0; fi | |
if [[ "$#" != '3' ]]; then exit 0; fi | |
curl --data-urlencode "text=下载完成通知" --data-urlencode "desp=$( echo "$File" | sed 's:'"$LocalDIR/"'::g' )已下载完成,正在上传..." $serverchan | |
function onemd(){ # remoteroot, dirname | |
if [ "$(onedrivecmd list "$1/" |sed -r 's#od:/(.*)\t.*\t.*#\1#g'|grep -cF "$2")" -eq '0' ] | |
then | |
onedrivecmd mkdir "$1/$2" | |
return 1 | |
else | |
echo "Folder \"$1/$2\" already exists!" | |
return 0 | |
fi | |
} | |
function rupload(){ # localdir, remotedir | |
if [ -d "$1" ] | |
then | |
echo "Checking in folder \"$1\"" | |
for file in `ls "$1" | sed 's/ /|/g'` | |
do | |
file=`echo "$file" | sed 's/|/ /g'` | |
if [ -d "$1/$file" ] | |
then | |
echo "onedrivecmd mkdir \"$2/$file\"" | |
onemd "$2" "$file" | |
rupload "$1/$file" "$2/$file" | |
else | |
if [ "$(onedrivecmd list "$2/" |sed -r 's#od:/(.*)\t.*\t.*#\1#g'|grep -cF "$file")" -ge '1' ]; then echo "File \"$file\" already exists."; continue; fi | |
echo "onedrivecmd put \"$1/$file\" \"$2\"" | |
onedrivecmd put "$1/$file" "$2" | |
fi | |
done | |
fi | |
} | |
if [ "$FileNum" -eq '1' ] | |
then | |
sudo chown www-data:www-data "$File" | |
UFile="$( echo "$File" | sed 's:'"$LocalDIR"'::g')" | |
tfolder=${UFile%/*}/ | |
tfolder=${tfolder#/} | |
ufolder=${RemoteDIR#/} | |
while [ $tfolder ] | |
do | |
onemd "$ufolder" "${tfolder%%/*}" | |
ufolder=$ufolder/${tfolder%%/*} | |
tfolder=${tfolder#*/} | |
done | |
echo "onedrivecmd put \"$File\" \"$ufolder\"" | |
onedrivecmd put "$File" "$ufolder" | |
else | |
Folder="$( echo "$File" | sed -r 's:'"$LocalDIR"'/([^/]*)/.*:\1:g')" | |
sudo chown -R www-data:www-data "$LocalDIR/$Folder" | |
onemd "$RemoteDIR" "$Folder" | |
rupload "/data/downloads/$Folder" "$RemoteDIR/$Folder" | |
fi | |
curl -I -m 5 -o /dev/null -s -w %{http_code} https://examples.com/refresh.php | |
curl --data-urlencode "text=上传完成通知" --data-urlencode "desp=$( echo "$File" | sed 's:'"$LocalDIR/"'::g' )已上传" $serverchan | |
echo `date --rfc-3339=seconds` "$3""上传成功">>/tmp/oneup.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment