VPS侦探论坛

 找回密码
 注册
查看: 6726|回复: 3

ubuntu执行这类脚本就报错

[复制链接]
发表于 2013-6-20 20:07:23 | 显示全部楼层 |阅读模式

  1. #!/usr/bin/env bash
  2. #
  3. # Dropbox Uploader
  4. #
  5. # Copyright (C) 2010-2013 Andrea Fabrizi
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. #

  21. #Default configuration file
  22. CONFIG_FILE=~/.dropbox_uploader

  23. #If you are experiencing problems establishing SSL connection with the DropBox
  24. #server, try to uncomment this option.
  25. #Note: This option explicitly allows curl to perform "insecure" SSL connections and transfers.
  26. #CURL_ACCEPT_CERTIFICATES="-k"

  27. #Default chunk size in Mb for the upload process
  28. #It is recommended to increase this value only if you have enough free space on your /tmp partition
  29. #Lower values may increase the number of http requests
  30. CHUNK_SIZE=4

  31. #Set to 1 to enable DEBUG mode
  32. DEBUG=0

  33. #Set to 1 to enable VERBOSE mode
  34. VERBOSE=1

  35. #Curl location
  36. #If not set, curl will be searched into the $PATH
  37. #CURL_BIN="/usr/bin/curl"

  38. #Temporary folder
  39. TMP_DIR="/tmp"

  40. #Don't edit these...
  41. API_REQUEST_TOKEN_URL="https://api.dropbox.com/1/oauth/request_token"
  42. API_USER_AUTH_URL="https://www2.dropbox.com/1/oauth/authorize"
  43. API_ACCESS_TOKEN_URL="https://api.dropbox.com/1/oauth/access_token"
  44. API_CHUNKED_UPLOAD_URL="https://api-content.dropbox.com/1/chunked_upload"
  45. API_CHUNKED_UPLOAD_COMMIT_URL="https://api-content.dropbox.com/1/commit_chunked_upload"
  46. API_UPLOAD_URL="https://api-content.dropbox.com/1/files_put"
  47. API_DOWNLOAD_URL="https://api-content.dropbox.com/1/files"
  48. API_DELETE_URL="https://api.dropbox.com/1/fileops/delete"
  49. API_MOVE_URL="https://api.dropbox.com/1/fileops/move"
  50. API_METADATA_URL="https://api.dropbox.com/1/metadata"
  51. API_INFO_URL="https://api.dropbox.com/1/account/info"
  52. API_MKDIR_URL="https://api.dropbox.com/1/fileops/create_folder"
  53. API_SHARES_URL="https://api.dropbox.com/1/shares"
  54. APP_CREATE_URL="https://www2.dropbox.com/developers/apps"
  55. RESPONSE_FILE="$TMP_DIR/du_resp_$RANDOM"
  56. CHUNK_FILE="$TMP_DIR/du_chunk_$RANDOM"
  57. BIN_DEPS="sed basename date grep stat dd printf mkdir"
  58. VERSION="0.11.8"

  59. umask 077

  60. #Check the shell
  61. if [ -z "$BASH_VERSION" ]; then
  62.     echo -e "Error: this script requires BASH shell!"
  63.     exit 1
  64. fi

  65. if [ $DEBUG -ne 0 ]; then
  66.     set -x
  67.     RESPONSE_FILE="$TMP_DIR/du_resp_debug"
  68. fi

  69. #Look for optional config file parameter
  70. while getopts ":f:" opt; do
  71.     case $opt in

  72.     f)
  73.       CONFIG_FILE=$OPTARG
  74.       shift $((OPTIND-1))
  75.     ;;

  76.     \?)
  77.       echo "Invalid option: -$OPTARG" >&2
  78.       exit 1
  79.     ;;

  80.    
  81.       echo "Option -$OPTARG requires an argument." >&2
  82.       exit 1
  83.     ;;

  84.   esac
  85. done

  86. #Print verbose information depends on $VERBOSE variable
  87. function print
  88. {
  89.     if [ $VERBOSE -eq 1 ]; then
  90.             echo -ne "$1";
  91.     fi
  92. }

  93. #Returns unix timestamp
  94. function utime
  95. {
  96.     echo $(date +%s)
  97. }

  98. #Remove temporary files
  99. function remove_temp_files
  100. {
  101.     if [ $DEBUG -eq 0 ]; then
  102.         rm -fr "$RESPONSE_FILE"
  103.         rm -fr "$CHUNK_FILE"
  104.     fi
  105. }

  106. #Returns the file size in bytes
  107. # generic GNU Linux: linux-gnu
  108. # windows cygwin:    cygwin
  109. # raspberry pi:      linux-gnueabihf
  110. # macosx:            darwin10.0
  111. # freebsd:           FreeBSD
  112. # qnap:              linux-gnueabi
  113. # iOS:               darwin9
  114. function file_size
  115. {
  116.     #Some embedded linux devices
  117.     if [ "$OSTYPE" == "linux-gnueabi" -o "$OSTYPE" == "linux-gnu" ]; then
  118.         stat -c "%s" "$1"
  119.         return

  120.     #Generic Unix
  121.     elif [ "${OSTYPE:0:5}" == "linux" -o "$OSTYPE" == "cygwin" -o "${OSTYPE:0:7}" == "solaris" -o "${OSTYPE}" == "darwin9" ]; then
  122.         stat --format="%s" "$1"
  123.         return

  124.     #BSD or others OS
  125.     else
  126.         stat -f "%z" "$1"
  127.         return
  128.     fi
  129. }

  130. #USAGE
  131. function usage
  132. {
  133.     echo -e "Dropbox Uploader v$VERSION"
  134.     echo -e "Andrea Fabrizi - andrea.fabrizi@gmail.com\n"
  135.     echo -e "Usage: $0 COMMAND [PARAMETERS]..."
  136.     echo -e "\nCommands:"

  137.     echo -e "\t upload   [LOCAL_FILE/DIR]  "
  138.     echo -e "\t download [REMOTE_FILE/DIR] "
  139.     echo -e "\t delete   [REMOTE_FILE/DIR]"
  140.     echo -e "\t move     [REMOTE_FILE/DIR] [REMOTE_FILE/DIR]"
  141.     echo -e "\t mkdir    [REMOTE_DIR]"
  142.     echo -e "\t list     "
  143.     echo -e "\t share    [REMOTE_FILE]"
  144.     echo -e "\t info"
  145.     echo -e "\t unlink"

  146.     echo -en "\nFor more info and examples, please see the README file.\n\n"
  147.     remove_temp_files
  148.     exit 1
  149. }

  150. if [ -z "$CURL_BIN" ]; then
  151.     BIN_DEPS="$BIN_DEPS curl"
  152.     CURL_BIN="curl"
  153. fi

  154. #DEPENDENCIES CHECK
  155. for i in $BIN_DEPS; do
  156.     which $i > /dev/null
  157.     if [ $? -ne 0 ]; then
  158.         echo -e "Error: Required program could not be found: $i"
  159.         remove_temp_files
  160.         exit 1
  161.     fi
  162. done

  163. #Urlencode
  164. function urlencode
  165. {
  166.     local string="${1}"
  167.     local strlen=${#string}
  168.     local encoded=""

  169.     for (( pos=0 ; pos<strlen ;="" pos++="" ));="" do
  170.         c=${stringpos:1}
  171.         case "$c" in
  172.             [-_.~a-zA-Z0-9] ) o="${c}" ;;
  173.             * )               printf -v o '%%%02x' "'$c"
  174.         esac
  175.         encoded+="${o}"
  176.     done

  177.     echo "$encoded"
  178. }

  179. #Generic upload wrapper around db_upload_file and db_upload_dir functions
  180. #$1 = Local source file/dir
  181. #$2 = Remote destination file/dir
  182. function db_upload
  183. {
  184.     local SRC="$1"
  185.     local DST="$2"

  186.     #It's a file
  187.     if [ -f "$SRC" ]; then
  188.         db_upload_file "$SRC" "$DST"
  189.    
  190.     #It's a directory
  191.     elif [ -d "$SRC" ]; then
  192.         db_upload_dir "$SRC" "$DST"

  193.     #Unsupported object...
  194.     else
  195.         print " > Skipping not regular file '$SRC'"
  196.     fi
  197. }

  198. #Generic upload wrapper around db_chunked_upload_file and db_simple_upload_file
  199. #The final upload function will be choosen based on the file size
  200. #$1 = Local source file
  201. #$2 = Remote destination file
  202. function db_upload_file
  203. {
  204.     local FILE_SRC="$1"
  205.     local FILE_DST="$2"

  206.     #Checking file size
  207.     FILE_SIZE=$(file_size "$FILE_SRC")

  208.     #Checking the free quota
  209.     FREE_QUOTA=$(db_free_quota)
  210.     if [ $FILE_SIZE -gt $FREE_QUOTA ]; then
  211.         let FREE_MB_QUOTA=$FREE_QUOTA/1024/1024
  212.         echo -e "Error: You have no enough space on your DropBox!"
  213.         echo -e "Free quota: $FREE_MB_QUOTA Mb"
  214.         remove_temp_files
  215.         exit 1
  216.     fi

  217.     if [ $FILE_SIZE -gt 157286000 ]; then
  218.         #If the file is greater than 150Mb, the chunked_upload API will be used
  219.         db_chunked_upload_file "$FILE_SRC" "$FILE_DST"
  220.     else
  221.         db_simple_upload_file "$FILE_SRC" "$FILE_DST"
  222.     fi
  223. }

  224. #Simple file upload
  225. #$1 = Local source file
  226. #$2 = Remote destination file
  227. function db_simple_upload_file
  228. {
  229.     local FILE_SRC="$1"
  230.     local FILE_DST=$(urlencode "$2")
  231. ........................
  232.    
复制代码
代码权限:chmod +x dropbox_uploader.sh

网上说的用这个 sudo dpkg-reconfigure dash 修改代码执行方式,但是执行过后就提示
错误代码:
  1. root@bcsytv:~# sh dropbox_uploader.sh
  2. dropbox_uploader.sh: dropbox_uploader.sh: cannot execute binary file
复制代码
程序版本是ubuntu 13.04

[ 本帖最后由 jalena 于 2013-6-20 20:09 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2013-6-20 21:45:15 | 显示全部楼层


bash dropbox_uploader.sh试试
之前好像也用过这个脚本,没发现有问题
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2013-6-21 18:52:18 | 显示全部楼层

回复 2# 的帖子


依然是那个问题,蛋都碎了一地啊!!
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2013-6-21 20:45:43 | 显示全部楼层



不折腾了,直接换到centos去~
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-11-24 22:59 , Processed in 0.026757 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表