#点击右边的回复URL,将其修改为:https://onedrive.live.com/about/business/,即脚本所需要的Reply URL参数。 #点击所需权限,点击Windows Azure Active Directory确认是否已选中Sign in and user profile,如果没有则选中并点击完成。 #点击上方的添加,点击选择API,选中Office 365 SharePoint Online,并点击选择。在选择权限中选中Read user files 和Read and write user files,并点击选择。点击完成按钮,并关掉此小窗口。 #点击密钥,填入密钥描述,如:OneDrive,选择年限1年,点击保存,再复制密匙,即脚本所需要的Secret参数。
不过这里说下密匙(Secret参数)填写的一个坑,由唯一度博主填平。就是当我们获取到带+号的密匙时候,我们需要使用编码符号,把+改成%2B,然后再填入脚本里,不然最后会出现Something went wrong, here is the API response的错误,导致验证失败。
3、运行账号认证程序 运行命令onedrive -a,将返回的网址复制到浏览器打开,再登陆你的OneDrive for Business账号,登陆成功后复制地址栏中的地址(复制包括localhost的所有链接地址),粘贴到SSH客户端里,敲回车键即可。
如果返回以下字段:It seems like we have a refresh token, so we are ready to go,那就恭喜你,设置成功!
1
提示:如果你遇到bash: onedrive: command not found错误,则需要找到/usr/local/etc/OneDrive文件夹,修改onedrive和onedrive-d脚本,在第二行都加上export PATH=/usr/local/bin:$PATH代码,再保存就行了。
if [[ -z $(echo"$FileNum" |grep -o '[0-9]*' |head -n1) ]]; then FileNum='0'; fi if [[ "$FileNum" -le '0' ]]; thenexit 0; fi if [[ "$#" != '3' ]]; thenexit 0; fi
functionLoadFile(){ IFS_BAK=$IFS IFS=$'\n' if [[ ! -d "$LocalDIR" ]]; thenreturn; fi if [[ -e "$File" ]]; then if [[ $(dirname "$File") == $(readlink -f $LocalDIR) ]]; then ONEDRIVE="onedrive"; else ONEDRIVE="onedrive-d"; fi FileLoad="${File/#$LocalDIR}" whiletrue do if [[ "$FileLoad" == '/' ]]; thenreturn; fi echo"$FileLoad" |grep -q '/'; if [[ "$?" == "0" ]]; then FileLoad=$(dirname "$FileLoad"); else break; fi; done; if [[ "$FileLoad" == "$LocalDIR" ]]; thenreturn; fi if [[ -n "$RemoteDIR" ]]; then Option=" -f $RemoteDIR"; else Option=""; fi EXEC="$(command -v $ONEDRIVE)"; if [[ -z "$EXEC" ]]; thenreturn; fi cd"$LocalDIR"; if [[ -e "$FileLoad" ]]; then ItemSize=$(du -s "$FileLoad" |cut -f1 |grep -o '[0-9]*' |head -n1) if [[ -z "$ItemSize" ]]; thenreturn; fi if [[ "$ItemSize" -ge "$MaxSize" ]]; then echo -ne "\033[33m$File \033[0mtoo large to spik.\n"; return; fi eval"${EXEC}${Option}" \'"${FileLoad}"\'; if [[ $? == '0' ]]; then rm -rf "$FileLoad"; fi fi fi IFS=$IFS_BAK } LoadFile;
functionInit(){ uploaded=`cat /root/sh/uploaded.log` #记录上传过的文件/创建过的文件夹 #FileLoad=${File##*/}; #/www/wwwroot/blog/usr/uploads的结果为uploads if [[ $uploaded =~ $File ]] then echo"${File}早已创建"; else echo"onedrive -c ${RemoteDIR}"/"${File##*/}"; eval"onedrive -c ${RemoteDIR}"/"${File##*/}"; #创建文件夹 if [[ $? == '0' ]]; then#若eval的语句返回成功 echo${File} >> '/root/sh/uploaded.log'; fi fi }
functionupload(){ for file in `ls $1` do dir=$1"/"$file; remote_dir=${RemoteDIR}${1#`dirname $File`}; if [ -d $dir ] then if [[ $uploaded =~ $dir ]] then echo"${dir}早已创建"; else echo"onedrive -c ${remote_dir}"/"${file}"; eval"onedrive -c ${remote_dir}"/"${file}"; if [[ $? == '0' ]]; then echo${dir} >> '/root/sh/uploaded.log'; fi fi upload $dir; #递归子文件夹 else file_path=$1"/"$file; if [[ $uploaded =~ $file_path ]] then echo"${file_path}早已上传"; else echo"onedrive -f ${remote_dir} '${file_path}'"; eval"onedrive -f ${remote_dir} '${file_path}'"; if [[ $? == '0' ]]; then echo${file_path} >> '/root/sh/uploaded.log'; fi fi fi done }
for File in"${uploads[@]}" do Init; upload ${File}; done