├── Dropbox-uploader ├── CHANGELOG.md ├── Dockerfile ├── Dockerfile.pi ├── LICENSE ├── README.md ├── dropShell.sh ├── dropbox_uploader.sh └── testUnit.sh ├── README.md ├── delete_old_files.py ├── dropbox_sync_folder_4_videos └── video_2018-01-31_22-43-57.mp4 ├── generate_webcam_frame.py ├── global_streaming_using_localtunnel.py ├── local_streaming_using_flask.py ├── opencv-security-cam ├── haarcascade_eye.xml ├── haarcascade_eye_tree_eyeglasses.xml ├── haarcascade_frontalface_alt.xml ├── haarcascade_frontalface_alt2.xml ├── haarcascade_frontalface_alt_tree.xml ├── haarcascade_frontalface_default.xml ├── haarcascade_fullbody.xml ├── haarcascade_lefteye_2splits.xml ├── haarcascade_licence_plate_rus_16stages.xml ├── haarcascade_lowerbody.xml ├── haarcascade_profileface.xml ├── haarcascade_righteye_2splits.xml ├── haarcascade_russian_plate_number.xml ├── haarcascade_smile.xml ├── haarcascade_upperbody.xml ├── image_saved.png └── opencv-security-cam-5.py ├── sending_email_using_smtplib.py ├── sending_messages_using_twilio.py ├── sync_using_dropbox_rpi.py └── templates └── index.html /Dropbox-uploader/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## Version 1.0 - 10 Aug 2016 4 | * Add search option 5 | * Increase chunk size to 50MB for better performance 6 | * Add testUnit script 7 | * Upgrade to API v2 8 | * Fix #278: Documentation issue for command line 9 | * Add -h option to show human readable file sizes 10 | * Fix issue #240: the connection is retried in case of error for chunked uploads 11 | * The file name encoding problems including the issue #139 should be fixed now 12 | * Add system info to debug output 13 | * Fix issue #230: Version String isn't updated in dropbox_uploader 14 | * Fixed issue #227 15 | 16 | ## Version 0.16 - 31 Jul 2015 17 | * Add saveurl command to download remote files directly into a dropbox folder 18 | * Fixed issue #174: $DU needs quoting in dropShell 19 | * The share command will now return by default the short url 20 | * Improved portability of the file_size function 21 | * Fixed minor bash compatibility issue in the urlencode function 22 | * Improved normalize_path function and minor fix 23 | * Removed deprecated db_free_quota function 24 | 25 | ## Version 0.15 - 08 Jun 2015 26 | * Fix issue #163, List only show folders but not files 27 | * Fix issue #168, Share call not returning a share link 28 | * Fix issue #172, list command always return an unnamed dir on an empty directory 29 | * Fix issue #165, Issue with uploading a file to a folder 30 | * Fix issue #162, Uploading a folder to a folder that already exists on dropbox has unexpected behaviour 31 | * Updated setup procedure 32 | 33 | ## Version 0.14 - 15 Jul 2014 34 | * Fix issue #112, replaced bash condition -f with -e 35 | * Fix issue #117, sed: 1: invalid command code z 36 | * Fix issue #122, Directory upload doesn't work 37 | * Fix issue #132, enhanced cross compatibility for bash conditions 38 | 39 | ## Version 0.13 - 17 Jan 2014 40 | * Minor languages fixes, based on issue #88 41 | * Fix issue #91, sed take long time to process regexp on big data 42 | * Fix issue #87, second chunked upload fails after successful first 43 | * Fix issue #97, greadlink not selected on OSX Mavericks 44 | * Fix issues #99 and #100: The stat command in OSX 10.9 has no parameter named --format 45 | * Fix issue #99, clarified how to install greadlink (via homebrew) for Mac OS X. Thanks to paultreny 46 | * Improved list command and minor changes 47 | * Fix issue #103, transform Unicode code-points to characters in list command 48 | * Add VERSION output in DEBUG mode 49 | * DropShell: Fixed issue with quoted command parameters 50 | * Fix issue with absolute paths in CD command 51 | * Enhancement request #108: add initial wildcard support in upload command 52 | * Now the destination file/dir for the upload command is mandatory 53 | * Fixed issue listing files/folders names containing quotes 54 | 55 | ## Version 0.12.1 - 24 Oct 2013 56 | * Fixed unicode problem with special chars in file names 57 | * Fixed problem removing temp files 58 | * Improved detection of configuration error and better handling of http errors 59 | * Updated setup procedure 60 | * Fixed incompatibility with old bash version 61 | 62 | ## Version 0.12 - 06 Sep 2013 63 | * Fixed problem uploading twice the same directory 64 | * Add checking for not allowed file names 65 | * Handling connection/resolving host errors 66 | * Better error handling 67 | * Converted if condition to BASH native syntax 68 | * Add normalize_path function, to canonicalize paths 69 | * Add -s option to skip existing files when upload/download 70 | * Removed check for free quota on every file upload to improve performance 71 | * Add checks for file permissions before writing/reading files on the local fs 72 | * Add copy function 73 | * Fixed unicode problem in file listing 74 | * A lot of minor changes and improvements 75 | 76 | ## Version 0.11.9 - 27 Jun 2013 77 | * Add missing -f option in usage 78 | * Add some /dev/null redirects 79 | * Improved error messages 80 | * Improved grep syntax 81 | * Add function to check the cURL exit code 82 | * Improved messages output 83 | * Add new command line options: -q -d -k 84 | 85 | ## Version 0.11.8 - 05 Jun 2013 86 | * Add move/rename function 87 | * Improved the configuration file management (thanks to Robert G.) 88 | * Updated strings to reflect the new Dropbox "Create App" page 89 | * Add support for download directories 90 | * Add support for upload directories 91 | 92 | ## Version 0.11.7 - 23 Apr 2013 93 | * Fixed issue with special chars 94 | * Fix for iOS 95 | 96 | ## Version 0.11.6 - 15 Mar 2013 97 | * Add optional command-line parameter ('-f') to read dropbox configuration from a specific file (thanks to pjv) 98 | 99 | ## Version 0.11.5 - 22 Gen 2013 100 | * Added the ability to get a share link for a specified file (thanks to camspiers) 101 | 102 | ## Version 0.11.4 - 17 Gen 2013 103 | * Fix for QNAP compatibility (thanks to Fritz Ferstl) 104 | * Implemented mkdir command (thanks to Joel Maslak) 105 | * Fix for Solaris compatibility 106 | 107 | ## Version 0.11.3 - 22 Dec 2012: 108 | * Improved list command (thanks to Robert González) 109 | * Fixed problem with unicode characters 110 | 111 | ## Version 0.11.2 - 14 Nov 2012: 112 | * Added a check for the free quota before uploading a file 113 | * Now the quota informations are displayed in Mb 114 | * Removed urlencode function for incompatibility with older curl versions 115 | * Fixed problem uploading files that contains @ character 116 | * Minor changes 117 | 118 | ## Version 0.11.1 - 12 Nov 2012: 119 | * As suggested by the DropBox API documentation, the default chunk for chunked uploads is now 4Mb 120 | * Minor changes 121 | 122 | ## Version 0.11 - 11 Nov 2012: 123 | * Parameterized the curl binary location 124 | * Fix for MacOSX 10.8 (thanks to Ben - www.aquiltforever.com) 125 | 126 | ## Version 0.10 - 03 Nov 2012: 127 | * Code clean 128 | * Improved urlencode function (thanks to Stefan Trauth * www.stefantrauth.de) 129 | * Added command remove as alias of delete 130 | * Fix for Raspberry PI 131 | * Now if an error occurs during a chunk uploading, the upload is retried for a maximum of three times 132 | * Minor changes 133 | * Tested on Cygwin and MacOSX 134 | 135 | ## Version 0.9.9 - 24 Oct 2012: 136 | * Added the possibility to choose the access level (App folder o Full Dropbox) during the setup procedure 137 | * Added a check for the BASH shell version 138 | * Fixed problems in listing files/directories with special characters 139 | * Added the option CURL_ACCEPT_CERTIFICATES (see the script source) 140 | * Added back the standard upload function. Now only if the file is greater than 150Mb, the chunked_upload API will be used. 141 | * Fixed compatibility with bsd sed. Tested on FreeBSD, but probably it works on others bsd versions and osx. Let me know! 142 | * Minor changes 143 | 144 | ## Version 0.9.8 - 03 Oct 2012: 145 | * Implemented chunked upload. Now there is no limit to file size! 146 | 147 | ## Version 0.9.7 - 14 Sep 2012: 148 | * Fixed bug in listing empty directories 149 | 150 | ## Version 0.9.6 - 12 Sep 2012: 151 | * Implemented list command 152 | * Minor changes 153 | 154 | ## Version 0.9.5 - 18 Jul 2012: 155 | * Added a check for the maximum file size allowed by the DropBox API 156 | * Minor changes 157 | 158 | ## Version 0.9.4 - 19 Mar 2012: 159 | * Implemented delete command 160 | * Minor changes 161 | 162 | ## Version 0.9.3 - 01 Mar 2012: 163 | * Implemented download command 164 | * Improved info output 165 | * Fixed utime function 166 | * Added dependency check for basename 167 | * The script always returns 1 when errors occurs 168 | * Improved error handling 169 | * Fixed problem with spaces in config file name 170 | * Minor bug fixes 171 | 172 | ## Version 0.9.2 - 28 Feb 2012: 173 | * Increased security, now any user can create his own Dropbox App 174 | 175 | ## Version 0.9.1 - 27 Feb 2012: 176 | * Fixed problem with spaces in dst file name 177 | 178 | ## Version 0.9 - 27 Feb 2012: 179 | * Code rewritten from scratch (CLI changed) 180 | * Improved security and stability using official dropbox API, no more username/password needed! 181 | 182 | ## Version 0.8.2 - 07 Sep 2011: 183 | * Removed INTERACTIVE_MODE variable (now the progress bar is shown in VERBOSE mode) 184 | * Improved command line interface and error messages 185 | * Minor bug fixes 186 | 187 | ## Version 0.8.1 - 31 Aug 2011 (by Dawid Ferenczy - www.ferenczy.cz) 188 | * added prompt for the Dropbox password from keyboard, if there is no password 189 | hardcoded or given as script command line parameter (interactive mode) 190 | * added INTERACTIVE_MODE variable - when set to 1 show CURL progress bar. 191 | Set to 1 automatically when there is no password hardcoded or given as 192 | parameter. Controls verbosity of CURL. 193 | 194 | ## Version 0.7.1 - 10 Mar 2011: 195 | * Minor bug fixes 196 | 197 | ## Version 0.7 - 10 Mar 2011: 198 | * New command line interface 199 | * Code clean 200 | 201 | ## Version 0.6 - 11 Gen 2011: 202 | * Fixed issue with spaces in file/forder name 203 | 204 | ## Version 0.5 - 04 Gen 2011: 205 | * Recursive directory upload 206 | 207 | ## Version 0.4 - 29 Dec 2010: 208 | * Now works on BSD and MAC 209 | * Interactive prompt for username and password 210 | * Speeded up the uploading process 211 | * Debug mode 212 | 213 | ## Version 0.3 - 18 Nov 2010: 214 | * Regex updated 215 | 216 | ## Version 0.2 - 04 Sep 2010: 217 | * Removed dependencies from tempfile 218 | * Code clean 219 | 220 | ## Version 0.1 - 23 Aug 2010: 221 | * Initial release 222 | -------------------------------------------------------------------------------- /Dropbox-uploader/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.5 2 | MAINTAINER peez@stiffi.de 3 | 4 | RUN apk add --no-cache bash curl 5 | COPY / /opt/dropbox_uploader 6 | RUN mkdir -p /config && mkdir -p /workdir 7 | 8 | VOLUME /config /workdir 9 | 10 | WORKDIR /workdir 11 | 12 | ENTRYPOINT ["/opt/dropbox_uploader/dropbox_uploader.sh", "-f", "/config/dropbox_uploader.conf"] -------------------------------------------------------------------------------- /Dropbox-uploader/Dockerfile.pi: -------------------------------------------------------------------------------- 1 | FROM hypriot/rpi-alpine-scratch 2 | MAINTAINER github@vanefferenonline.nl 3 | 4 | RUN apk update && apk add bash curl 5 | COPY *.sh /opt/dropbox_uploader/ 6 | RUN mkdir -p /config && mkdir -p /workdir 7 | 8 | VOLUME /config /workdir 9 | 10 | WORKDIR /workdir 11 | 12 | ENTRYPOINT ["/opt/dropbox_uploader/dropbox_uploader.sh", "-f", "/config/dropbox_uploader.conf"] 13 | -------------------------------------------------------------------------------- /Dropbox-uploader/LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Dropbox-uploader/README.md: -------------------------------------------------------------------------------- 1 | # Dropbox Uploader 2 | 3 | Dropbox Uploader is a **BASH** script which can be used to upload, download, delete, list files (and more!) from **Dropbox**, an online file sharing, synchronization and backup service. 4 | 5 | It's written in BASH scripting language and only needs **cURL**. 6 | 7 | You can take a look to the [GiHub project page](https://github.com/andreafabrizi/Dropbox-Uploader). 8 | 9 | **Why use this script?** 10 | 11 | * **Portable:** It's written in BASH scripting and only needs `cURL` (curl is a tool to transfer data from or to a server, available for all operating systems and installed by default in many linux distributions). 12 | * **Secure:** It's not required to provide your username/password to this script, because it uses the official Dropbox API v2 for the authentication process. 13 | 14 | Please refer to the [Wiki](https://github.com/andreafabrizi/Dropbox-Uploader/wiki) for tips and additional information about this project. The Wiki is also the place where you can share your scripts and examples related to Dropbox Uploader. 15 | 16 | ## Features 17 | 18 | * Cross platform 19 | * Support for the official Dropbox API v2 20 | * No password required or stored 21 | * Simple step-by-step configuration wizard 22 | * Simple and chunked file upload 23 | * File and recursive directory download 24 | * File and recursive directory upload 25 | * Shell wildcard expansion (only for upload) 26 | * Delete/Move/Rename/Copy/List/Share files 27 | * Create share link 28 | * Monitor for changes 29 | 30 | ## Getting started 31 | 32 | First, clone the repository using git (recommended): 33 | 34 | ```bash 35 | git clone https://github.com/andreafabrizi/Dropbox-Uploader.git 36 | ``` 37 | 38 | or download the script manually using this command: 39 | 40 | ```bash 41 | curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh 42 | ``` 43 | 44 | Then give the execution permission to the script and run it: 45 | 46 | ```bash 47 | $chmod +x dropbox_uploader.sh 48 | $./dropbox_uploader.sh 49 | ``` 50 | 51 | The first time you run `dropbox_uploader`, you'll be guided through a wizard in order to configure access to your Dropbox. This configuration will be stored in `~/.dropbox_uploader`. 52 | 53 | ## Usage 54 | 55 | The syntax is quite simple: 56 | 57 | ``` 58 | ./dropbox_uploader.sh [PARAMETERS] COMMAND... 59 | 60 | [%%]: Optional param 61 | <%%>: Required param 62 | ``` 63 | 64 | **Available commands:** 65 | 66 | * **upload** <LOCAL_FILE/DIR ...> <REMOTE_FILE/DIR> 67 | Upload a local file or directory to a remote Dropbox folder. 68 | If the file is bigger than 150Mb the file is uploaded using small chunks (default 50Mb); 69 | in this case a . (dot) is printed for every chunk successfully uploaded and a * (star) if an error 70 | occurs (the upload is retried for a maximum of three times). 71 | Only if the file is smaller than 150Mb, the standard upload API is used, and if the -p option is specified 72 | the default curl progress bar is displayed during the upload process. 73 | The local file/dir parameter supports wildcards expansion. 74 | 75 | * **download** <REMOTE_FILE/DIR> [LOCAL_FILE/DIR] 76 | Download file or directory from Dropbox to a local folder 77 | 78 | * **delete** <REMOTE_FILE/DIR> 79 | Remove a remote file or directory from Dropbox 80 | 81 | * **move** <REMOTE_FILE/DIR> <REMOTE_FILE/DIR> 82 | Move or rename a remote file or directory 83 | 84 | * **copy** <REMOTE_FILE/DIR> <REMOTE_FILE/DIR> 85 | Copy a remote file or directory 86 | 87 | * **mkdir** <REMOTE_DIR> 88 | Create a remote directory on Dropbox 89 | 90 | * **list** [REMOTE_DIR] 91 | List the contents of the remote Dropbox folder 92 | 93 | * **monitor** [REMOTE_DIR] [TIMEOUT] 94 | Monitor the remote Dropbox folder for changes. If timeout is specified, at the first change event the function will return. 95 | 96 | * **share** <REMOTE_FILE> 97 | Get a public share link for the specified file or directory 98 | 99 | * **saveurl** <URL> <REMOTE_DIR> 100 | Download a file from an URL to a Dropbox folder directly (the file is NOT downloaded locally) 101 | 102 | * **search** <QUERY> 103 | Search for a specific pattern on Dropbox and returns the list of matching files or directories 104 | 105 | * **info** 106 | Print some info about your Dropbox account 107 | 108 | * **space** 109 | Print some info about the space usage on your Dropbox account 110 | 111 | * **unlink** 112 | Unlink the script from your Dropbox account 113 | 114 | 115 | **Optional parameters:** 116 | * **-f <FILENAME>** 117 | Load the configuration file from a specific file 118 | 119 | * **-s** 120 | Skip already existing files when download/upload. Default: Overwrite 121 | 122 | * **-d** 123 | Enable DEBUG mode 124 | 125 | * **-q** 126 | Quiet mode. Don't show progress meter or messages 127 | 128 | * **-h** 129 | Show file sizes in human readable format 130 | 131 | * **-p** 132 | Show cURL progress meter 133 | 134 | * **-k** 135 | Doesn't check for SSL certificates (insecure) 136 | 137 | * **-x <FILENAME>** 138 | Ignores/excludes directories or files from syncing. 139 | -x filename -x directoryname. 140 | 141 | **Examples:** 142 | ```bash 143 | ./dropbox_uploader.sh upload /etc/passwd /myfiles/passwd.old 144 | ./dropbox_uploader.sh upload *.zip / 145 | ./dropbox_uploader.sh -x .git upload ./project / 146 | ./dropbox_uploader.sh download /backup.zip 147 | ./dropbox_uploader.sh delete /backup.zip 148 | ./dropbox_uploader.sh mkdir /myDir/ 149 | ./dropbox_uploader.sh upload "My File.txt" "My File 2.txt" 150 | ./dropbox_uploader.sh share "My File.txt" 151 | ./dropbox_uploader.sh list 152 | ``` 153 | 154 | ## Tested Environments 155 | 156 | * GNU Linux 157 | * FreeBSD 8.3/10.0 158 | * MacOSX 159 | * Windows/Cygwin 160 | * Raspberry Pi 161 | * QNAP 162 | * iOS 163 | * OpenWRT 164 | * Chrome OS 165 | * OpenBSD 166 | 167 | If you have successfully tested this script on others systems or platforms please let me know! 168 | 169 | ## Running as cron job 170 | Dropbox Uploader relies on a different configuration file for each system user. The default configuration file location is `$HOME/.dropbox_uploader`. This means that if you setup the script with your user and then you try to run a cron job as root, it won't work. 171 | So, when running this script using cron, please keep in mind the following: 172 | * Remember to setup the script with the user used to run the cron job 173 | * Always specify the full script path when running it (e.g. /path/to/dropbox_uploader.sh) 174 | * Use always the -f option to specify the full configuration file path, because sometimes in the cron environment the home folder path is not detected correctly (e.g. -f /home/youruser/.dropbox_uploader) 175 | * My advice is, for security reasons, to not share the same configuration file with different users 176 | 177 | ## How to setup a proxy 178 | 179 | To use a proxy server, just set the **https_proxy** environment variable: 180 | 181 | **Linux:** 182 | ```bash 183 | export HTTP_PROXY_USER=XXXX 184 | export HTTP_PROXY_PASSWORD=YYYY 185 | export https_proxy=http://192.168.0.1:8080 186 | ``` 187 | 188 | **BSD:** 189 | ```bash 190 | setenv HTTP_PROXY_USER XXXX 191 | setenv HTTP_PROXY_PASSWORD YYYY 192 | setenv https_proxy http://192.168.0.1:8080 193 | ``` 194 | 195 | ## BASH and Curl installation 196 | 197 | **Debian & Ubuntu Linux:** 198 | ```bash 199 | sudo apt-get install bash (Probably BASH is already installed on your system) 200 | sudo apt-get install curl 201 | ``` 202 | 203 | **BSD:** 204 | ```bash 205 | cd /usr/ports/shells/bash && make install clean 206 | cd /usr/ports/ftp/curl && make install clean 207 | ``` 208 | 209 | **Cygwin:** 210 | You need to install these packages: 211 | * curl 212 | * ca-certificates 213 | * dos2unix 214 | 215 | Before running the script, you need to convert it using the dos2unix command. 216 | 217 | 218 | **Build cURL from source:** 219 | * Download the source tarball from http://curl.haxx.se/download.html 220 | * Follow the INSTALL instructions 221 | 222 | ## DropShell 223 | 224 | DropShell is an interactive DropBox shell, based on DropBox Uploader: 225 | 226 | ```bash 227 | DropShell v0.2 228 | The Intractive Dropbox SHELL 229 | Andrea Fabrizi - andrea.fabrizi@gmail.com 230 | 231 | Type help for the list of the available commands. 232 | 233 | andrea@Dropbox:/$ ls 234 | [D] 0 Apps 235 | [D] 0 Camera Uploads 236 | [D] 0 Public 237 | [D] 0 scripts 238 | [D] 0 Security 239 | [F] 105843 notes.txt 240 | andrea@DropBox:/ServerBackup$ get notes.txt 241 | ``` 242 | 243 | ## Running as Docker Container 244 | First build the docker image: 245 | ```bash 246 | docker build https://github.com/sircuri/Dropbox-Uploader.git -f Dockerfile -t 247 | ``` 248 | or for RaspBerry: 249 | ```bash 250 | docker build https://github.com/sircuri/Dropbox-Uploader.git -f Dockerfile.pi -t 251 | ``` 252 | then, you can run it as following: 253 | ```bash 254 | docker run -i --rm --user=$(id -u):$(id -g) -v :/config -v :/workdir 255 | ``` 256 | This will store the auth token information in the given local directory in ``. To ensure access to your mounted directories it can be important to pass a UID and GID to the docker deamon (as stated in the example by the --user argument) 257 | 258 | Using the script with docker makes it also possible to run the script even on windows machines. 259 | 260 | To use a proxy, just set the mentioned environment variables via the docker `-e` parameter. 261 | 262 | ## Related projects 263 | [thunar-dropbox](https://github.com/mDfRg/Thunar-Dropbox-Uploader-plugin/tree/thunar-dropbox/plugins/thunar): A simple extension to Dropbox Uploader that provides a convenient method to share your Dropbox files with one click! 264 | 265 | ## Donations 266 | 267 | If you want to support this project, please consider donating: 268 | * PayPal: https://www.paypal.me/AndreaFabrizi83 269 | * BTC: 1JHCGAMpKqUwBjcT3Kno9Wd5z16K6WKPqG 270 | -------------------------------------------------------------------------------- /Dropbox-uploader/dropShell.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # DropShell 4 | # 5 | # Copyright (C) 2013-2014 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 | 22 | #Looking for dropbox uploader 23 | if [ -f "./dropbox_uploader.sh" ]; then 24 | DU="./dropbox_uploader.sh" 25 | else 26 | DU=$(which dropbox_uploader.sh) 27 | if [ $? -ne 0 ]; then 28 | echo "Dropbox Uploader not found!" 29 | exit 1 30 | fi 31 | fi 32 | 33 | #For MacOSX, install coreutils (which includes greadlink) 34 | # $brew install coreutils 35 | if [ "${OSTYPE:0:6}" == "darwin" -o "${OSTYPE:0:7}" == "freebsd" ]; then 36 | READLINK="greadlink" 37 | else 38 | READLINK="readlink" 39 | fi 40 | 41 | SHELL_HISTORY=~/.dropshell_history 42 | DU_OPT="-q" 43 | BIN_DEPS="id $READLINK ls basename ls pwd cut" 44 | VERSION="0.2" 45 | 46 | umask 077 47 | 48 | #Dependencies check 49 | for i in $BIN_DEPS; do 50 | which $i > /dev/null 51 | if [ $? -ne 0 ]; then 52 | echo -e "Error: Required program could not be found: $i" 53 | exit 1 54 | fi 55 | done 56 | 57 | #Check DropBox Uploader 58 | if [ ! -f "$DU" ]; then 59 | echo "Dropbox Uploader not found: $DU" 60 | echo "Please change the 'DU' variable according to the Dropbox Uploader location." 61 | exit 1 62 | else 63 | DU=$($READLINK -m "$DU") 64 | fi 65 | 66 | #Returns the current user 67 | function get_current_user 68 | { 69 | id -nu 70 | } 71 | 72 | function normalize_path 73 | { 74 | $READLINK -m "$1" 75 | } 76 | 77 | ################ 78 | #### START #### 79 | ################ 80 | 81 | echo -e "DropShell v$VERSION" 82 | echo -e "The Interactive Dropbox SHELL" 83 | echo -e "Andrea Fabrizi - andrea.fabrizi@gmail.com\n" 84 | echo -e "Type help for the list of the available commands.\n" 85 | 86 | history -r "$SHELL_HISTORY" 87 | username=$(get_current_user) 88 | 89 | #Initial Working Directory 90 | CWD="/" 91 | 92 | function sh_ls 93 | { 94 | local arg1=$1 95 | 96 | #Listing current dir 97 | if [ -z "$arg1" ]; then 98 | "$DU" $DU_OPT list "$CWD" 99 | 100 | #Listing $arg1 101 | else 102 | 103 | #Relative or absolute path? 104 | if [ ${arg1:0:1} == "/" ]; then 105 | "$DU" $DU_OPT list "$(normalize_path "$arg1")" 106 | else 107 | "$DU" $DU_OPT list "$(normalize_path "$CWD/$arg1")" 108 | fi 109 | 110 | #Checking for errors 111 | if [ $? -ne 0 ]; then 112 | echo -e "ls: cannot access '$arg1': No such file or directory" 113 | fi 114 | fi 115 | } 116 | 117 | function sh_cd 118 | { 119 | local arg1=$1 120 | 121 | OLD_CWD=$CWD 122 | 123 | if [ -z "$arg1" ]; then 124 | CWD="/" 125 | elif [ ${arg1:0:1} == "/" ]; then 126 | CWD=$arg1 127 | else 128 | CWD=$(normalize_path "$OLD_CWD/$arg1/") 129 | fi 130 | 131 | "$DU" $DU_OPT list "$CWD" > /dev/null 132 | 133 | #Checking for errors 134 | if [ $? -ne 0 ]; then 135 | echo -e "cd: $arg1: No such file or directory" 136 | CWD=$OLD_CWD 137 | fi 138 | } 139 | 140 | function sh_get 141 | { 142 | local arg1=$1 143 | local arg2=$2 144 | 145 | if [ ! -z "$arg1" ]; then 146 | 147 | #Relative or absolute path? 148 | if [ ${arg1:0:1} == "/" ]; then 149 | "$DU" $DU_OPT download "$(normalize_path "$arg1")" "$arg2" 150 | else 151 | "$DU" $DU_OPT download "$(normalize_path "$CWD/$arg1")" "$arg2" 152 | fi 153 | 154 | #Checking for errors 155 | if [ $? -ne 0 ]; then 156 | echo -e "get: Download error" 157 | fi 158 | 159 | #args error 160 | else 161 | echo -e "get: missing operand" 162 | echo -e "syntax: get [LOCAL_FILE/DIR]" 163 | fi 164 | } 165 | 166 | function sh_put 167 | { 168 | local arg1=$1 169 | local arg2=$2 170 | 171 | if [ ! -z "$arg1" ]; then 172 | 173 | #Relative or absolute path? 174 | if [ "${arg2:0:1}" == "/" ]; then 175 | "$DU" $DU_OPT upload "$arg1" "$(normalize_path "$arg2")" 176 | else 177 | "$DU" $DU_OPT upload "$arg1" "$(normalize_path "$CWD/$arg2")" 178 | fi 179 | 180 | #Checking for errors 181 | if [ $? -ne 0 ]; then 182 | echo -e "put: Upload error" 183 | fi 184 | 185 | #args error 186 | else 187 | echo -e "put: missing operand" 188 | echo -e "syntax: put " 189 | fi 190 | } 191 | 192 | function sh_rm 193 | { 194 | local arg1=$1 195 | 196 | if [ ! -z "$arg1" ]; then 197 | 198 | #Relative or absolute path? 199 | if [ ${arg1:0:1} == "/" ]; then 200 | "$DU" $DU_OPT remove "$(normalize_path "$arg1")" 201 | else 202 | "$DU" $DU_OPT remove "$(normalize_path "$CWD/$arg1")" 203 | fi 204 | 205 | #Checking for errors 206 | if [ $? -ne 0 ]; then 207 | echo -e "rm: cannot remove '$arg1'" 208 | fi 209 | 210 | #args error 211 | else 212 | echo -e "rm: missing operand" 213 | echo -e "syntax: rm " 214 | fi 215 | } 216 | 217 | function sh_mkdir 218 | { 219 | local arg1=$1 220 | 221 | if [ ! -z "$arg1" ]; then 222 | 223 | #Relative or absolute path? 224 | if [ ${arg1:0:1} == "/" ]; then 225 | "$DU" $DU_OPT mkdir "$(normalize_path "$arg1")" 226 | else 227 | "$DU" $DU_OPT mkdir "$(normalize_path "$CWD/$arg1")" 228 | fi 229 | 230 | #Checking for errors 231 | if [ $? -ne 0 ]; then 232 | echo -e "mkdir: cannot create directory '$arg1'" 233 | fi 234 | 235 | #args error 236 | else 237 | echo -e "mkdir: missing operand" 238 | echo -e "syntax: mkdir " 239 | fi 240 | } 241 | 242 | function sh_mv 243 | { 244 | local arg1=$1 245 | local arg2=$2 246 | 247 | if [ ! -z "$arg1" -a ! -z "$arg2" ]; then 248 | 249 | #SRC relative or absolute path? 250 | if [ ${arg1:0:1} == "/" ]; then 251 | SRC="$arg1" 252 | else 253 | SRC="$CWD/$arg1" 254 | fi 255 | 256 | #DST relative or absolute path? 257 | if [ ${arg2:0:1} == "/" ]; then 258 | DST="$arg2" 259 | else 260 | DST="$CWD/$arg2" 261 | fi 262 | 263 | "$DU" $DU_OPT move "$(normalize_path "$SRC")" "$(normalize_path "$DST")" 264 | 265 | #Checking for errors 266 | if [ $? -ne 0 ]; then 267 | echo -e "mv: cannot move '$arg1' to '$arg2'" 268 | fi 269 | 270 | #args error 271 | else 272 | echo -e "mv: missing operand" 273 | echo -e "syntax: mv " 274 | fi 275 | } 276 | 277 | function sh_cp 278 | { 279 | local arg1=$1 280 | local arg2=$2 281 | 282 | if [ ! -z "$arg1" -a ! -z "$arg2" ]; then 283 | 284 | #SRC relative or absolute path? 285 | if [ ${arg1:0:1} == "/" ]; then 286 | SRC="$arg1" 287 | else 288 | SRC="$CWD/$arg1" 289 | fi 290 | 291 | #DST relative or absolute path? 292 | if [ ${arg2:0:1} == "/" ]; then 293 | DST="$arg2" 294 | else 295 | DST="$CWD/$arg2" 296 | fi 297 | 298 | "$DU" $DU_OPT copy "$(normalize_path "$SRC")" "$(normalize_path "$DST")" 299 | 300 | #Checking for errors 301 | if [ $? -ne 0 ]; then 302 | echo -e "cp: cannot copy '$arg1' to '$arg2'" 303 | fi 304 | 305 | #args error 306 | else 307 | echo -e "cp: missing operand" 308 | echo -e "syntax: cp " 309 | fi 310 | } 311 | 312 | function sh_free 313 | { 314 | "$DU" $DU_OPT info | grep "Free:" | cut -f 2 315 | } 316 | 317 | function sh_cat 318 | { 319 | local arg1=$1 320 | 321 | if [ ! -z "$arg1" ]; then 322 | 323 | tmp_cat="/tmp/sh_cat_$RANDOM" 324 | sh_get "$arg1" "$tmp_cat" 325 | cat "$tmp_cat" 326 | rm -fr "$tmp_cat" 327 | 328 | #args error 329 | else 330 | echo -e "cat: missing operand" 331 | echo -e "syntax: cat " 332 | fi 333 | } 334 | 335 | while (true); do 336 | 337 | #Reading command from shell 338 | read -e -p "$username@Dropbox:$CWD$ " input 339 | 340 | #Tokenizing command 341 | eval tokens=($input) 342 | cmd=${tokens[0]} 343 | arg1=${tokens[1]} 344 | arg2=${tokens[2]} 345 | 346 | #Saving command in the history file 347 | history -s "$input" 348 | history -w "$SHELL_HISTORY" 349 | 350 | case $cmd in 351 | 352 | ls) 353 | sh_ls "$arg1" 354 | ;; 355 | 356 | cd) 357 | sh_cd "$arg1" 358 | ;; 359 | 360 | pwd) 361 | echo $CWD 362 | ;; 363 | 364 | get) 365 | sh_get "$arg1" "$arg2" 366 | ;; 367 | 368 | put) 369 | sh_put "$arg1" "$arg2" 370 | ;; 371 | 372 | rm) 373 | sh_rm "$arg1" 374 | ;; 375 | 376 | mkdir) 377 | sh_mkdir "$arg1" 378 | ;; 379 | 380 | mv) 381 | sh_mv "$arg1" "$arg2" 382 | ;; 383 | 384 | cp) 385 | sh_cp "$arg1" "$arg2" 386 | ;; 387 | 388 | cat) 389 | sh_cat "$arg1" 390 | ;; 391 | 392 | free) 393 | sh_free 394 | ;; 395 | 396 | lls) 397 | ls -l 398 | ;; 399 | 400 | lpwd) 401 | pwd 402 | ;; 403 | 404 | lcd) 405 | cd "$arg1" 406 | ;; 407 | 408 | help) 409 | echo -e "Supported commands: ls, cd, pwd, get, put, cat, rm, mkdir, mv, cp, free, lls, lpwd, lcd, help, exit\n" 410 | ;; 411 | 412 | quit|exit) 413 | exit 0 414 | ;; 415 | 416 | *) 417 | if [ ! -z "$cmd" ]; then 418 | echo -ne "Unknown command: $cmd\n" 419 | fi 420 | ;; 421 | esac 422 | done 423 | 424 | -------------------------------------------------------------------------------- /Dropbox-uploader/dropbox_uploader.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Dropbox Uploader 4 | # 5 | # Copyright (C) 2010-2017 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 | 22 | #Default configuration file 23 | CONFIG_FILE=~/.dropbox_uploader 24 | 25 | #Default chunk size in Mb for the upload process 26 | #It is recommended to increase this value only if you have enough free space on your /tmp partition 27 | #Lower values may increase the number of http requests 28 | CHUNK_SIZE=50 29 | 30 | #Curl location 31 | #If not set, curl will be searched into the $PATH 32 | #CURL_BIN="/usr/bin/curl" 33 | 34 | #Default values 35 | TMP_DIR="/tmp" 36 | DEBUG=0 37 | QUIET=0 38 | SHOW_PROGRESSBAR=1 39 | SKIP_EXISTING_FILES=0 40 | ERROR_STATUS=0 41 | EXCLUDE=() 42 | 43 | #Don't edit these... 44 | API_LONGPOLL_FOLDER="https://notify.dropboxapi.com/2/files/list_folder/longpoll" 45 | API_CHUNKED_UPLOAD_START_URL="https://content.dropboxapi.com/2/files/upload_session/start" 46 | API_CHUNKED_UPLOAD_FINISH_URL="https://content.dropboxapi.com/2/files/upload_session/finish" 47 | API_CHUNKED_UPLOAD_APPEND_URL="https://content.dropboxapi.com/2/files/upload_session/append_v2" 48 | API_UPLOAD_URL="https://content.dropboxapi.com/2/files/upload" 49 | API_DOWNLOAD_URL="https://content.dropboxapi.com/2/files/download" 50 | API_DELETE_URL="https://api.dropboxapi.com/2/files/delete" 51 | API_MOVE_URL="https://api.dropboxapi.com/2/files/move" 52 | API_COPY_URL="https://api.dropboxapi.com/2/files/copy" 53 | API_METADATA_URL="https://api.dropboxapi.com/2/files/get_metadata" 54 | API_LIST_FOLDER_URL="https://api.dropboxapi.com/2/files/list_folder" 55 | API_LIST_FOLDER_CONTINUE_URL="https://api.dropboxapi.com/2/files/list_folder/continue" 56 | API_ACCOUNT_INFO_URL="https://api.dropboxapi.com/2/users/get_current_account" 57 | API_ACCOUNT_SPACE_URL="https://api.dropboxapi.com/2/users/get_space_usage" 58 | API_MKDIR_URL="https://api.dropboxapi.com/2/files/create_folder" 59 | API_SHARE_URL="https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings" 60 | API_SHARE_LIST="https://api.dropboxapi.com/2/sharing/list_shared_links" 61 | API_SAVEURL_URL="https://api.dropboxapi.com/2/files/save_url" 62 | API_SAVEURL_JOBSTATUS_URL="https://api.dropboxapi.com/2/files/save_url/check_job_status" 63 | API_SEARCH_URL="https://api.dropboxapi.com/2/files/search" 64 | APP_CREATE_URL="https://www.dropbox.com/developers/apps" 65 | RESPONSE_FILE="$TMP_DIR/du_resp_$RANDOM" 66 | CHUNK_FILE="$TMP_DIR/du_chunk_$RANDOM" 67 | TEMP_FILE="$TMP_DIR/du_tmp_$RANDOM" 68 | BIN_DEPS="sed basename date grep stat dd mkdir" 69 | VERSION="1.0" 70 | 71 | umask 077 72 | 73 | #Check the shell 74 | if [ -z "$BASH_VERSION" ]; then 75 | echo -e "Error: this script requires the BASH shell!" 76 | exit 1 77 | fi 78 | 79 | shopt -s nullglob #Bash allows filename patterns which match no files to expand to a null string, rather than themselves 80 | shopt -s dotglob #Bash includes filenames beginning with a "." in the results of filename expansion 81 | 82 | #Check temp folder 83 | if [[ ! -d "$TMP_DIR" ]]; then 84 | echo -e "Error: the temporary folder $TMP_DIR doesn't exists!" 85 | echo -e "Please edit this script and set the TMP_DIR variable to a valid temporary folder to use." 86 | exit 1 87 | fi 88 | 89 | #Look for optional config file parameter 90 | while getopts ":qpskdhf:x:" opt; do 91 | case $opt in 92 | 93 | f) 94 | CONFIG_FILE=$OPTARG 95 | ;; 96 | 97 | d) 98 | DEBUG=1 99 | ;; 100 | 101 | q) 102 | QUIET=1 103 | ;; 104 | 105 | p) 106 | SHOW_PROGRESSBAR=1 107 | ;; 108 | 109 | k) 110 | CURL_ACCEPT_CERTIFICATES="-k" 111 | ;; 112 | 113 | s) 114 | SKIP_EXISTING_FILES=1 115 | ;; 116 | 117 | h) 118 | HUMAN_READABLE_SIZE=1 119 | ;; 120 | 121 | x) 122 | EXCLUDE+=( $OPTARG ) 123 | ;; 124 | 125 | \?) 126 | echo "Invalid option: -$OPTARG" >&2 127 | exit 1 128 | ;; 129 | 130 | :) 131 | echo "Option -$OPTARG requires an argument." >&2 132 | exit 1 133 | ;; 134 | 135 | esac 136 | done 137 | 138 | if [[ $DEBUG != 0 ]]; then 139 | echo $VERSION 140 | uname -a 2> /dev/null 141 | cat /etc/issue 2> /dev/null 142 | set -x 143 | RESPONSE_FILE="$TMP_DIR/du_resp_debug" 144 | fi 145 | 146 | if [[ $CURL_BIN == "" ]]; then 147 | BIN_DEPS="$BIN_DEPS curl" 148 | CURL_BIN="curl" 149 | fi 150 | 151 | #Dependencies check 152 | which $BIN_DEPS > /dev/null 153 | if [[ $? != 0 ]]; then 154 | for i in $BIN_DEPS; do 155 | which $i > /dev/null || 156 | NOT_FOUND="$i $NOT_FOUND" 157 | done 158 | echo -e "Error: Required program could not be found: $NOT_FOUND" 159 | exit 1 160 | fi 161 | 162 | #Check if readlink is installed and supports the -m option 163 | #It's not necessary, so no problem if it's not installed 164 | which readlink > /dev/null 165 | if [[ $? == 0 && $(readlink -m "//test" 2> /dev/null) == "/test" ]]; then 166 | HAVE_READLINK=1 167 | else 168 | HAVE_READLINK=0 169 | fi 170 | 171 | #Forcing to use the builtin printf, if it's present, because it's better 172 | #otherwise the external printf program will be used 173 | #Note that the external printf command can cause character encoding issues! 174 | builtin printf "" 2> /dev/null 175 | if [[ $? == 0 ]]; then 176 | PRINTF="builtin printf" 177 | PRINTF_OPT="-v o" 178 | else 179 | PRINTF=$(which printf) 180 | if [[ $? != 0 ]]; then 181 | echo -e "Error: Required program could not be found: printf" 182 | fi 183 | PRINTF_OPT="" 184 | fi 185 | 186 | #Print the message based on $QUIET variable 187 | function print 188 | { 189 | if [[ $QUIET == 0 ]]; then 190 | echo -ne "$1"; 191 | fi 192 | } 193 | 194 | #Returns unix timestamp 195 | function utime 196 | { 197 | date '+%s' 198 | } 199 | 200 | #Remove temporary files 201 | function remove_temp_files 202 | { 203 | if [[ $DEBUG == 0 ]]; then 204 | rm -fr "$RESPONSE_FILE" 205 | rm -fr "$CHUNK_FILE" 206 | rm -fr "$TEMP_FILE" 207 | fi 208 | } 209 | 210 | #Converts bytes to human readable format 211 | function convert_bytes 212 | { 213 | if [[ $HUMAN_READABLE_SIZE == 1 && "$1" != "" ]]; then 214 | if (($1 > 1073741824));then 215 | echo $(($1/1073741824)).$(($1%1073741824/100000000))"G"; 216 | elif (($1 > 1048576));then 217 | echo $(($1/1048576)).$(($1%1048576/100000))"M"; 218 | elif (($1 > 1024));then 219 | echo $(($1/1024)).$(($1%1024/100))"K"; 220 | else 221 | echo $1; 222 | fi 223 | else 224 | echo $1; 225 | fi 226 | } 227 | 228 | #Returns the file size in bytes 229 | function file_size 230 | { 231 | #Generic GNU 232 | SIZE=$(stat --format="%s" "$1" 2> /dev/null) 233 | if [ $? -eq 0 ]; then 234 | echo $SIZE 235 | return 236 | fi 237 | 238 | #Some embedded linux devices 239 | SIZE=$(stat -c "%s" "$1" 2> /dev/null) 240 | if [ $? -eq 0 ]; then 241 | echo $SIZE 242 | return 243 | fi 244 | 245 | #BSD, OSX and other OSs 246 | SIZE=$(stat -f "%z" "$1" 2> /dev/null) 247 | if [ $? -eq 0 ]; then 248 | echo $SIZE 249 | return 250 | fi 251 | 252 | echo "0" 253 | } 254 | 255 | 256 | #Usage 257 | function usage 258 | { 259 | echo -e "Dropbox Uploader v$VERSION" 260 | echo -e "Andrea Fabrizi - andrea.fabrizi@gmail.com\n" 261 | echo -e "Usage: $0 [PARAMETERS] COMMAND..." 262 | echo -e "\nCommands:" 263 | 264 | echo -e "\t upload " 265 | echo -e "\t download [LOCAL_FILE/DIR]" 266 | echo -e "\t delete " 267 | echo -e "\t move " 268 | echo -e "\t copy " 269 | echo -e "\t mkdir " 270 | echo -e "\t list [REMOTE_DIR]" 271 | echo -e "\t monitor [REMOTE_DIR] [TIMEOUT]" 272 | echo -e "\t share " 273 | echo -e "\t saveurl " 274 | echo -e "\t search " 275 | echo -e "\t info" 276 | echo -e "\t space" 277 | echo -e "\t unlink" 278 | 279 | echo -e "\nOptional parameters:" 280 | echo -e "\t-f Load the configuration file from a specific file" 281 | echo -e "\t-s Skip already existing files when download/upload. Default: Overwrite" 282 | echo -e "\t-d Enable DEBUG mode" 283 | echo -e "\t-q Quiet mode. Don't show messages" 284 | echo -e "\t-h Show file sizes in human readable format" 285 | echo -e "\t-p Show cURL progress meter" 286 | echo -e "\t-k Doesn't check for SSL certificates (insecure)" 287 | echo -e "\t-x Ignores/excludes directories or files from syncing. -x filename -x directoryname. example: -x .git" 288 | 289 | echo -en "\nFor more info and examples, please see the README file.\n\n" 290 | remove_temp_files 291 | exit 1 292 | } 293 | 294 | #Check the curl exit code 295 | function check_http_response 296 | { 297 | CODE=$? 298 | 299 | #Checking curl exit code 300 | case $CODE in 301 | 302 | #OK 303 | 0) 304 | 305 | ;; 306 | 307 | #Proxy error 308 | 5) 309 | print "\nError: Couldn't resolve proxy. The given proxy host could not be resolved.\n" 310 | 311 | remove_temp_files 312 | exit 1 313 | ;; 314 | 315 | #Missing CA certificates 316 | 60|58|77) 317 | print "\nError: cURL is not able to performs peer SSL certificate verification.\n" 318 | print "Please, install the default ca-certificates bundle.\n" 319 | print "To do this in a Debian/Ubuntu based system, try:\n" 320 | print " sudo apt-get install ca-certificates\n\n" 321 | print "If the problem persists, try to use the -k option (insecure).\n" 322 | 323 | remove_temp_files 324 | exit 1 325 | ;; 326 | 327 | 6) 328 | print "\nError: Couldn't resolve host.\n" 329 | 330 | remove_temp_files 331 | exit 1 332 | ;; 333 | 334 | 7) 335 | print "\nError: Couldn't connect to host.\n" 336 | 337 | remove_temp_files 338 | exit 1 339 | ;; 340 | 341 | esac 342 | 343 | #Checking response file for generic errors 344 | if grep -q "HTTP/1.1 400" "$RESPONSE_FILE"; then 345 | ERROR_MSG=$(sed -n -e 's/{"error": "\([^"]*\)"}/\1/p' "$RESPONSE_FILE") 346 | 347 | case $ERROR_MSG in 348 | *access?attempt?failed?because?this?app?is?not?configured?to?have*) 349 | echo -e "\nError: The Permission type/Access level configured doesn't match the DropBox App settings!\nPlease run \"$0 unlink\" and try again." 350 | exit 1 351 | ;; 352 | esac 353 | 354 | fi 355 | 356 | } 357 | 358 | #Urlencode 359 | function urlencode 360 | { 361 | #The printf is necessary to correctly decode unicode sequences 362 | local string=$($PRINTF "${1}") 363 | local strlen=${#string} 364 | local encoded="" 365 | 366 | for (( pos=0 ; pos /dev/null 409 | check_http_response 410 | 411 | local TYPE=$(sed -n 's/{".tag": *"*\([^"]*\)"*.*/\1/p' "$RESPONSE_FILE") 412 | 413 | case $TYPE in 414 | 415 | file) 416 | echo "FILE" 417 | ;; 418 | 419 | folder) 420 | echo "DIR" 421 | ;; 422 | 423 | deleted) 424 | echo "ERR" 425 | ;; 426 | 427 | *) 428 | echo "ERR" 429 | ;; 430 | 431 | esac 432 | } 433 | 434 | #Generic upload wrapper around db_upload_file and db_upload_dir functions 435 | #$1 = Local source file/dir 436 | #$2 = Remote destination file/dir 437 | function db_upload 438 | { 439 | local SRC=$(normalize_path "$1") 440 | local DST=$(normalize_path "$2") 441 | 442 | for j in "${EXCLUDE[@]}" 443 | do : 444 | if [[ $(echo "$SRC" | grep "$j" | wc -l) -gt 0 ]]; then 445 | print "Skipping excluded file/dir: "$j 446 | return 447 | fi 448 | done 449 | 450 | #Checking if the file/dir exists 451 | if [[ ! -e $SRC && ! -d $SRC ]]; then 452 | print " > No such file or directory: $SRC\n" 453 | ERROR_STATUS=1 454 | return 455 | fi 456 | 457 | #Checking if the file/dir has read permissions 458 | if [[ ! -r $SRC ]]; then 459 | print " > Error reading file $SRC: permission denied\n" 460 | ERROR_STATUS=1 461 | return 462 | fi 463 | 464 | TYPE=$(db_stat "$DST") 465 | 466 | #If DST it's a file, do nothing, it's the default behaviour 467 | if [[ $TYPE == "FILE" ]]; then 468 | DST="$DST" 469 | 470 | #if DST doesn't exists and doesn't ends with a /, it will be the destination file name 471 | elif [[ $TYPE == "ERR" && "${DST: -1}" != "/" ]]; then 472 | DST="$DST" 473 | 474 | #if DST doesn't exists and ends with a /, it will be the destination folder 475 | elif [[ $TYPE == "ERR" && "${DST: -1}" == "/" ]]; then 476 | local filename=$(basename "$SRC") 477 | DST="$DST/$filename" 478 | 479 | #If DST it's a directory, it will be the destination folder 480 | elif [[ $TYPE == "DIR" ]]; then 481 | local filename=$(basename "$SRC") 482 | DST="$DST/$filename" 483 | fi 484 | 485 | #It's a directory 486 | if [[ -d $SRC ]]; then 487 | db_upload_dir "$SRC" "$DST" 488 | 489 | #It's a file 490 | elif [[ -e $SRC ]]; then 491 | db_upload_file "$SRC" "$DST" 492 | 493 | #Unsupported object... 494 | else 495 | print " > Skipping not regular file \"$SRC\"\n" 496 | fi 497 | } 498 | 499 | #Generic upload wrapper around db_chunked_upload_file and db_simple_upload_file 500 | #The final upload function will be choosen based on the file size 501 | #$1 = Local source file 502 | #$2 = Remote destination file 503 | function db_upload_file 504 | { 505 | local FILE_SRC=$(normalize_path "$1") 506 | local FILE_DST=$(normalize_path "$2") 507 | 508 | shopt -s nocasematch 509 | 510 | #Checking not allowed file names 511 | basefile_dst=$(basename "$FILE_DST") 512 | if [[ $basefile_dst == "thumbs.db" || \ 513 | $basefile_dst == "desktop.ini" || \ 514 | $basefile_dst == ".ds_store" || \ 515 | $basefile_dst == "icon\r" || \ 516 | $basefile_dst == ".dropbox" || \ 517 | $basefile_dst == ".dropbox.attr" \ 518 | ]]; then 519 | print " > Skipping not allowed file name \"$FILE_DST\"\n" 520 | return 521 | fi 522 | 523 | shopt -u nocasematch 524 | 525 | #Checking file size 526 | FILE_SIZE=$(file_size "$FILE_SRC") 527 | 528 | #Checking if the file already exists 529 | TYPE=$(db_stat "$FILE_DST") 530 | if [[ $TYPE != "ERR" && $SKIP_EXISTING_FILES == 1 ]]; then 531 | print " > Skipping already existing file \"$FILE_DST\"\n" 532 | return 533 | fi 534 | 535 | # Checking if the file has the correct check sum 536 | if [[ $TYPE != "ERR" ]]; then 537 | sha_src=$(db_sha_local "$FILE_SRC") 538 | sha_dst=$(db_sha "$FILE_DST") 539 | if [[ $sha_src == $sha_dst && $sha_src != "ERR" ]]; then 540 | print "> Skipping file \"$FILE_SRC\", file exists with the same hash\n" 541 | return 542 | fi 543 | fi 544 | 545 | if [[ $FILE_SIZE -gt 157286000 ]]; then 546 | #If the file is greater than 150Mb, the chunked_upload API will be used 547 | db_chunked_upload_file "$FILE_SRC" "$FILE_DST" 548 | else 549 | db_simple_upload_file "$FILE_SRC" "$FILE_DST" 550 | fi 551 | 552 | } 553 | 554 | #Simple file upload 555 | #$1 = Local source file 556 | #$2 = Remote destination file 557 | function db_simple_upload_file 558 | { 559 | local FILE_SRC=$(normalize_path "$1") 560 | local FILE_DST=$(normalize_path "$2") 561 | 562 | if [[ $SHOW_PROGRESSBAR == 1 && $QUIET == 0 ]]; then 563 | CURL_PARAMETERS="--progress-bar" 564 | LINE_CR="\n" 565 | else 566 | CURL_PARAMETERS="-L -s" 567 | LINE_CR="" 568 | fi 569 | 570 | print " > Uploading \"$FILE_SRC\" to \"$FILE_DST\"... $LINE_CR" 571 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES $CURL_PARAMETERS -X POST -i --globoff -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Dropbox-API-Arg: {\"path\": \"$FILE_DST\",\"mode\": \"overwrite\",\"autorename\": true,\"mute\": false}" --header "Content-Type: application/octet-stream" --data-binary @"$FILE_SRC" "$API_UPLOAD_URL" 572 | check_http_response 573 | 574 | #Check 575 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 576 | print "DONE\n" 577 | else 578 | print "FAILED\n" 579 | print "An error occurred requesting /upload\n" 580 | ERROR_STATUS=1 581 | fi 582 | } 583 | 584 | #Chunked file upload 585 | #$1 = Local source file 586 | #$2 = Remote destination file 587 | function db_chunked_upload_file 588 | { 589 | local FILE_SRC=$(normalize_path "$1") 590 | local FILE_DST=$(normalize_path "$2") 591 | 592 | 593 | if [[ $SHOW_PROGRESSBAR == 1 && $QUIET == 0 ]]; then 594 | VERBOSE=1 595 | CURL_PARAMETERS="--progress-bar" 596 | else 597 | VERBOSE=0 598 | CURL_PARAMETERS="-L -s" 599 | fi 600 | 601 | 602 | 603 | local FILE_SIZE=$(file_size "$FILE_SRC") 604 | local OFFSET=0 605 | local UPLOAD_ID="" 606 | local UPLOAD_ERROR=0 607 | local CHUNK_PARAMS="" 608 | 609 | ## Ceil division 610 | let NUMBEROFCHUNK=($FILE_SIZE/1024/1024+$CHUNK_SIZE-1)/$CHUNK_SIZE 611 | 612 | if [[ $VERBOSE == 1 ]]; then 613 | print " > Uploading \"$FILE_SRC\" to \"$FILE_DST\" by $NUMBEROFCHUNK chunks ...\n" 614 | else 615 | print " > Uploading \"$FILE_SRC\" to \"$FILE_DST\" by $NUMBEROFCHUNK chunks " 616 | fi 617 | 618 | #Starting a new upload session 619 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Dropbox-API-Arg: {\"close\": false}" --header "Content-Type: application/octet-stream" --data-binary @/dev/null "$API_CHUNKED_UPLOAD_START_URL" 2> /dev/null 620 | check_http_response 621 | 622 | SESSION_ID=$(sed -n 's/{"session_id": *"*\([^"]*\)"*.*/\1/p' "$RESPONSE_FILE") 623 | 624 | chunkNumber=1 625 | #Uploading chunks... 626 | while ([[ $OFFSET != "$FILE_SIZE" ]]); do 627 | 628 | let OFFSET_MB=$OFFSET/1024/1024 629 | 630 | #Create the chunk 631 | dd if="$FILE_SRC" of="$CHUNK_FILE" bs=1048576 skip=$OFFSET_MB count=$CHUNK_SIZE 2> /dev/null 632 | local CHUNK_REAL_SIZE=$(file_size "$CHUNK_FILE") 633 | 634 | if [[ $VERBOSE == 1 ]]; then 635 | print " >> Uploading chunk $chunkNumber of $NUMBEROFCHUNK\n" 636 | fi 637 | 638 | #Uploading the chunk... 639 | echo > "$RESPONSE_FILE" 640 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST $CURL_PARAMETERS --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Dropbox-API-Arg: {\"cursor\": {\"session_id\": \"$SESSION_ID\",\"offset\": $OFFSET},\"close\": false}" --header "Content-Type: application/octet-stream" --data-binary @"$CHUNK_FILE" "$API_CHUNKED_UPLOAD_APPEND_URL" 641 | #check_http_response not needed, because we have to retry the request in case of error 642 | 643 | #Check 644 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 645 | let OFFSET=$OFFSET+$CHUNK_REAL_SIZE 646 | UPLOAD_ERROR=0 647 | if [[ $VERBOSE != 1 ]]; then 648 | print "." 649 | fi 650 | ((chunkNumber=chunkNumber+1)) 651 | else 652 | if [[ $VERBOSE != 1 ]]; then 653 | print "*" 654 | fi 655 | let UPLOAD_ERROR=$UPLOAD_ERROR+1 656 | 657 | #On error, the upload is retried for max 3 times 658 | if [[ $UPLOAD_ERROR -gt 2 ]]; then 659 | print " FAILED\n" 660 | print "An error occurred requesting /chunked_upload\n" 661 | ERROR_STATUS=1 662 | return 663 | fi 664 | fi 665 | 666 | done 667 | 668 | UPLOAD_ERROR=0 669 | 670 | #Commit the upload 671 | while (true); do 672 | 673 | echo > "$RESPONSE_FILE" 674 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Dropbox-API-Arg: {\"cursor\": {\"session_id\": \"$SESSION_ID\",\"offset\": $OFFSET},\"commit\": {\"path\": \"$FILE_DST\",\"mode\": \"overwrite\",\"autorename\": true,\"mute\": false}}" --header "Content-Type: application/octet-stream" --data-binary @/dev/null "$API_CHUNKED_UPLOAD_FINISH_URL" 2> /dev/null 675 | #check_http_response not needed, because we have to retry the request in case of error 676 | 677 | #Check 678 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 679 | UPLOAD_ERROR=0 680 | break 681 | else 682 | print "*" 683 | let UPLOAD_ERROR=$UPLOAD_ERROR+1 684 | 685 | #On error, the commit is retried for max 3 times 686 | if [[ $UPLOAD_ERROR -gt 2 ]]; then 687 | print " FAILED\n" 688 | print "An error occurred requesting /commit_chunked_upload\n" 689 | ERROR_STATUS=1 690 | return 691 | fi 692 | fi 693 | 694 | done 695 | 696 | print " DONE\n" 697 | } 698 | 699 | #Directory upload 700 | #$1 = Local source dir 701 | #$2 = Remote destination dir 702 | function db_upload_dir 703 | { 704 | local DIR_SRC=$(normalize_path "$1") 705 | local DIR_DST=$(normalize_path "$2") 706 | 707 | #Creatig remote directory 708 | db_mkdir "$DIR_DST" 709 | 710 | for file in "$DIR_SRC/"*; do 711 | db_upload "$file" "$DIR_DST" 712 | done 713 | } 714 | 715 | #Generic download wrapper 716 | #$1 = Remote source file/dir 717 | #$2 = Local destination file/dir 718 | function db_download 719 | { 720 | local SRC=$(normalize_path "$1") 721 | local DST=$(normalize_path "$2") 722 | 723 | TYPE=$(db_stat "$SRC") 724 | 725 | #It's a directory 726 | if [[ $TYPE == "DIR" ]]; then 727 | 728 | #If the DST folder is not specified, I assume that is the current directory 729 | if [[ $DST == "" ]]; then 730 | DST="." 731 | fi 732 | 733 | #Checking if the destination directory exists 734 | if [[ ! -d $DST ]]; then 735 | local basedir="" 736 | else 737 | local basedir=$(basename "$SRC") 738 | fi 739 | 740 | local DEST_DIR=$(normalize_path "$DST/$basedir") 741 | print " > Downloading folder \"$SRC\" to \"$DEST_DIR\"... \n" 742 | 743 | if [[ ! -d "$DEST_DIR" ]]; then 744 | print " > Creating local directory \"$DEST_DIR\"... " 745 | mkdir -p "$DEST_DIR" 746 | 747 | #Check 748 | if [[ $? == 0 ]]; then 749 | print "DONE\n" 750 | else 751 | print "FAILED\n" 752 | ERROR_STATUS=1 753 | return 754 | fi 755 | fi 756 | 757 | if [[ $SRC == "/" ]]; then 758 | SRC_REQ="" 759 | else 760 | SRC_REQ="$SRC" 761 | fi 762 | 763 | OUT_FILE=$(db_list_outfile "$SRC_REQ") 764 | if [ $? -ne 0 ]; then 765 | # When db_list_outfile fail, the error message is OUT_FILE 766 | print "$OUT_FILE\n" 767 | ERROR_STATUS=1 768 | return 769 | fi 770 | 771 | #For each entry... 772 | while read -r line; do 773 | 774 | local FILE=${line%:*} 775 | local META=${line##*:} 776 | local TYPE=${META%;*} 777 | local SIZE=${META#*;} 778 | 779 | #Removing unneeded / 780 | FILE=${FILE##*/} 781 | 782 | if [[ $TYPE == "file" ]]; then 783 | db_download_file "$SRC/$FILE" "$DEST_DIR/$FILE" 784 | elif [[ $TYPE == "folder" ]]; then 785 | db_download "$SRC/$FILE" "$DEST_DIR" 786 | fi 787 | 788 | done < $OUT_FILE 789 | 790 | rm -fr $OUT_FILE 791 | 792 | #It's a file 793 | elif [[ $TYPE == "FILE" ]]; then 794 | 795 | #Checking DST 796 | if [[ $DST == "" ]]; then 797 | DST=$(basename "$SRC") 798 | fi 799 | 800 | #If the destination is a directory, the file will be download into 801 | if [[ -d $DST ]]; then 802 | DST="$DST/$SRC" 803 | fi 804 | 805 | db_download_file "$SRC" "$DST" 806 | 807 | #Doesn't exists 808 | else 809 | print " > No such file or directory: $SRC\n" 810 | ERROR_STATUS=1 811 | return 812 | fi 813 | } 814 | 815 | #Simple file download 816 | #$1 = Remote source file 817 | #$2 = Local destination file 818 | function db_download_file 819 | { 820 | local FILE_SRC=$(normalize_path "$1") 821 | local FILE_DST=$(normalize_path "$2") 822 | 823 | if [[ $SHOW_PROGRESSBAR == 1 && $QUIET == 0 ]]; then 824 | CURL_PARAMETERS="-L --progress-bar" 825 | LINE_CR="\n" 826 | else 827 | CURL_PARAMETERS="-L -s" 828 | LINE_CR="" 829 | fi 830 | 831 | #Checking if the file already exists 832 | if [[ -e $FILE_DST && $SKIP_EXISTING_FILES == 1 ]]; then 833 | print " > Skipping already existing file \"$FILE_DST\"\n" 834 | return 835 | fi 836 | 837 | # Checking if the file has the correct check sum 838 | if [[ $TYPE != "ERR" ]]; then 839 | sha_src=$(db_sha "$FILE_SRC") 840 | sha_dst=$(db_sha_local "$FILE_DST") 841 | if [[ $sha_src == $sha_dst && $sha_src != "ERR" ]]; then 842 | print "> Skipping file \"$FILE_SRC\", file exists with the same hash\n" 843 | return 844 | fi 845 | fi 846 | 847 | #Creating the empty file, that for two reasons: 848 | #1) In this way I can check if the destination file is writable or not 849 | #2) Curl doesn't automatically creates files with 0 bytes size 850 | dd if=/dev/zero of="$FILE_DST" count=0 2> /dev/null 851 | if [[ $? != 0 ]]; then 852 | print " > Error writing file $FILE_DST: permission denied\n" 853 | ERROR_STATUS=1 854 | return 855 | fi 856 | 857 | print " > Downloading \"$FILE_SRC\" to \"$FILE_DST\"... $LINE_CR" 858 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES $CURL_PARAMETERS -X POST --globoff -D "$RESPONSE_FILE" -o "$FILE_DST" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Dropbox-API-Arg: {\"path\": \"$FILE_SRC\"}" "$API_DOWNLOAD_URL" 859 | check_http_response 860 | 861 | #Check 862 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 863 | print "DONE\n" 864 | else 865 | print "FAILED\n" 866 | rm -fr "$FILE_DST" 867 | ERROR_STATUS=1 868 | return 869 | fi 870 | } 871 | 872 | #Saveurl 873 | #$1 = URL 874 | #$2 = Remote file destination 875 | function db_saveurl 876 | { 877 | local URL="$1" 878 | local FILE_DST=$(normalize_path "$2") 879 | local FILE_NAME=$(basename "$URL") 880 | 881 | print " > Downloading \"$URL\" to \"$FILE_DST\"..." 882 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"$FILE_DST/$FILE_NAME\", \"url\": \"$URL\"}" "$API_SAVEURL_URL" 2> /dev/null 883 | check_http_response 884 | 885 | JOB_ID=$(sed -n 's/.*"async_job_id": *"*\([^"]*\)"*.*/\1/p' "$RESPONSE_FILE") 886 | if [[ $JOB_ID == "" ]]; then 887 | print " > Error getting the job id\n" 888 | return 889 | fi 890 | 891 | #Checking the status 892 | while (true); do 893 | 894 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"async_job_id\": \"$JOB_ID\"}" "$API_SAVEURL_JOBSTATUS_URL" 2> /dev/null 895 | check_http_response 896 | 897 | STATUS=$(sed -n 's/{".tag": *"*\([^"]*\)"*.*/\1/p' "$RESPONSE_FILE") 898 | case $STATUS in 899 | 900 | in_progress) 901 | print "+" 902 | ;; 903 | 904 | complete) 905 | print " DONE\n" 906 | break 907 | ;; 908 | 909 | failed) 910 | print " ERROR\n" 911 | MESSAGE=$(sed -n 's/.*"error_summary": *"*\([^"]*\)"*.*/\1/p' "$RESPONSE_FILE") 912 | print " > Error: $MESSAGE\n" 913 | break 914 | ;; 915 | 916 | esac 917 | 918 | sleep 2 919 | 920 | done 921 | } 922 | 923 | #Prints account info 924 | function db_account_info 925 | { 926 | print "Dropbox Uploader v$VERSION\n\n" 927 | print " > Getting info... " 928 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" "$API_ACCOUNT_INFO_URL" 2> /dev/null 929 | check_http_response 930 | 931 | #Check 932 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 933 | 934 | name=$(sed -n 's/.*"display_name": "\([^"]*\).*/\1/p' "$RESPONSE_FILE") 935 | echo -e "\n\nName:\t\t$name" 936 | 937 | uid=$(sed -n 's/.*"account_id": "\([^"]*\).*/\1/p' "$RESPONSE_FILE") 938 | echo -e "UID:\t\t$uid" 939 | 940 | email=$(sed -n 's/.*"email": "\([^"]*\).*/\1/p' "$RESPONSE_FILE") 941 | echo -e "Email:\t\t$email" 942 | 943 | country=$(sed -n 's/.*"country": "\([^"]*\).*/\1/p' "$RESPONSE_FILE") 944 | echo -e "Country:\t$country" 945 | 946 | echo "" 947 | 948 | else 949 | print "FAILED\n" 950 | ERROR_STATUS=1 951 | fi 952 | } 953 | 954 | #Prints account space usage info 955 | function db_account_space 956 | { 957 | print "Dropbox Uploader v$VERSION\n\n" 958 | print " > Getting space usage info... " 959 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" "$API_ACCOUNT_SPACE_URL" 2> /dev/null 960 | check_http_response 961 | 962 | #Check 963 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 964 | 965 | quota=$(sed -n 's/.*"allocated": \([0-9]*\).*/\1/p' "$RESPONSE_FILE") 966 | let quota_mb=$quota/1024/1024 967 | echo -e "\n\nQuota:\t$quota_mb Mb" 968 | 969 | used=$(sed -n 's/.*"used": \([0-9]*\).*/\1/p' "$RESPONSE_FILE") 970 | let used_mb=$used/1024/1024 971 | echo -e "Used:\t$used_mb Mb" 972 | 973 | let free_mb=$((quota-used))/1024/1024 974 | echo -e "Free:\t$free_mb Mb" 975 | 976 | echo "" 977 | 978 | else 979 | print "FAILED\n" 980 | ERROR_STATUS=1 981 | fi 982 | } 983 | 984 | #Account unlink 985 | function db_unlink 986 | { 987 | echo -ne "Are you sure you want unlink this script from your Dropbox account? [y/n]" 988 | read -r answer 989 | if [[ $answer == "y" ]]; then 990 | rm -fr "$CONFIG_FILE" 991 | echo -ne "DONE\n" 992 | fi 993 | } 994 | 995 | #Delete a remote file 996 | #$1 = Remote file to delete 997 | function db_delete 998 | { 999 | local FILE_DST=$(normalize_path "$1") 1000 | 1001 | print " > Deleting \"$FILE_DST\"... " 1002 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"$FILE_DST\"}" "$API_DELETE_URL" 2> /dev/null 1003 | check_http_response 1004 | 1005 | #Check 1006 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1007 | print "DONE\n" 1008 | else 1009 | print "FAILED\n" 1010 | ERROR_STATUS=1 1011 | fi 1012 | } 1013 | 1014 | #Move/Rename a remote file 1015 | #$1 = Remote file to rename or move 1016 | #$2 = New file name or location 1017 | function db_move 1018 | { 1019 | local FILE_SRC=$(normalize_path "$1") 1020 | local FILE_DST=$(normalize_path "$2") 1021 | 1022 | TYPE=$(db_stat "$FILE_DST") 1023 | 1024 | #If the destination it's a directory, the source will be moved into it 1025 | if [[ $TYPE == "DIR" ]]; then 1026 | local filename=$(basename "$FILE_SRC") 1027 | FILE_DST=$(normalize_path "$FILE_DST/$filename") 1028 | fi 1029 | 1030 | print " > Moving \"$FILE_SRC\" to \"$FILE_DST\" ... " 1031 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"from_path\": \"$FILE_SRC\", \"to_path\": \"$FILE_DST\"}" "$API_MOVE_URL" 2> /dev/null 1032 | check_http_response 1033 | 1034 | #Check 1035 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1036 | print "DONE\n" 1037 | else 1038 | print "FAILED\n" 1039 | ERROR_STATUS=1 1040 | fi 1041 | } 1042 | 1043 | #Copy a remote file to a remote location 1044 | #$1 = Remote file to rename or move 1045 | #$2 = New file name or location 1046 | function db_copy 1047 | { 1048 | local FILE_SRC=$(normalize_path "$1") 1049 | local FILE_DST=$(normalize_path "$2") 1050 | 1051 | TYPE=$(db_stat "$FILE_DST") 1052 | 1053 | #If the destination it's a directory, the source will be copied into it 1054 | if [[ $TYPE == "DIR" ]]; then 1055 | local filename=$(basename "$FILE_SRC") 1056 | FILE_DST=$(normalize_path "$FILE_DST/$filename") 1057 | fi 1058 | 1059 | print " > Copying \"$FILE_SRC\" to \"$FILE_DST\" ... " 1060 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"from_path\": \"$FILE_SRC\", \"to_path\": \"$FILE_DST\"}" "$API_COPY_URL" 2> /dev/null 1061 | check_http_response 1062 | 1063 | #Check 1064 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1065 | print "DONE\n" 1066 | else 1067 | print "FAILED\n" 1068 | ERROR_STATUS=1 1069 | fi 1070 | } 1071 | 1072 | #Create a new directory 1073 | #$1 = Remote directory to create 1074 | function db_mkdir 1075 | { 1076 | local DIR_DST=$(normalize_path "$1") 1077 | 1078 | print " > Creating Directory \"$DIR_DST\"... " 1079 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"$DIR_DST\"}" "$API_MKDIR_URL" 2> /dev/null 1080 | check_http_response 1081 | 1082 | #Check 1083 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1084 | print "DONE\n" 1085 | elif grep -q "^HTTP/1.1 403 Forbidden" "$RESPONSE_FILE"; then 1086 | print "ALREADY EXISTS\n" 1087 | else 1088 | print "FAILED\n" 1089 | ERROR_STATUS=1 1090 | fi 1091 | } 1092 | 1093 | #List a remote folder and returns the path to the file containing the output 1094 | #$1 = Remote directory 1095 | #$2 = Cursor (Optional) 1096 | function db_list_outfile 1097 | { 1098 | 1099 | local DIR_DST="$1" 1100 | local HAS_MORE="false" 1101 | local CURSOR="" 1102 | 1103 | if [[ -n "$2" ]]; then 1104 | CURSOR="$2" 1105 | HAS_MORE="true" 1106 | fi 1107 | 1108 | OUT_FILE="$TMP_DIR/du_tmp_out_$RANDOM" 1109 | 1110 | while (true); do 1111 | 1112 | if [[ $HAS_MORE == "true" ]]; then 1113 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"cursor\": \"$CURSOR\"}" "$API_LIST_FOLDER_CONTINUE_URL" 2> /dev/null 1114 | else 1115 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"$DIR_DST\",\"include_media_info\": false,\"include_deleted\": false,\"include_has_explicit_shared_members\": false}" "$API_LIST_FOLDER_URL" 2> /dev/null 1116 | fi 1117 | 1118 | check_http_response 1119 | 1120 | HAS_MORE=$(sed -n 's/.*"has_more": *\([a-z]*\).*/\1/p' "$RESPONSE_FILE") 1121 | CURSOR=$(sed -n 's/.*"cursor": *"\([^"]*\)".*/\1/p' "$RESPONSE_FILE") 1122 | 1123 | #Check 1124 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1125 | 1126 | #Extracting directory content [...] 1127 | #and replacing "}, {" with "}\n{" 1128 | #I don't like this piece of code... but seems to be the only way to do this with SED, writing a portable code... 1129 | local DIR_CONTENT=$(sed -n 's/.*: \[{\(.*\)/\1/p' "$RESPONSE_FILE" | sed 's/}, *{/}\ 1130 | {/g') 1131 | 1132 | #Converting escaped quotes to unicode format 1133 | echo "$DIR_CONTENT" | sed 's/\\"/\\u0022/' > "$TEMP_FILE" 1134 | 1135 | #Extracting files and subfolders 1136 | while read -r line; do 1137 | 1138 | local FILE=$(echo "$line" | sed -n 's/.*"path_display": *"\([^"]*\)".*/\1/p') 1139 | local TYPE=$(echo "$line" | sed -n 's/.*".tag": *"\([^"]*\).*/\1/p') 1140 | local SIZE=$(convert_bytes $(echo "$line" | sed -n 's/.*"size": *\([0-9]*\).*/\1/p')) 1141 | 1142 | echo -e "$FILE:$TYPE;$SIZE" >> "$OUT_FILE" 1143 | 1144 | done < "$TEMP_FILE" 1145 | 1146 | if [[ $HAS_MORE == "false" ]]; then 1147 | break 1148 | fi 1149 | 1150 | else 1151 | return 1152 | fi 1153 | 1154 | done 1155 | 1156 | echo $OUT_FILE 1157 | } 1158 | 1159 | #List remote directory 1160 | #$1 = Remote directory 1161 | function db_list 1162 | { 1163 | local DIR_DST=$(normalize_path "$1") 1164 | 1165 | print " > Listing \"$DIR_DST\"... " 1166 | 1167 | if [[ "$DIR_DST" == "/" ]]; then 1168 | DIR_DST="" 1169 | fi 1170 | 1171 | OUT_FILE=$(db_list_outfile "$DIR_DST") 1172 | if [ -z "$OUT_FILE" ]; then 1173 | print "FAILED\n" 1174 | ERROR_STATUS=1 1175 | return 1176 | else 1177 | print "DONE\n" 1178 | fi 1179 | 1180 | #Looking for the biggest file size 1181 | #to calculate the padding to use 1182 | local padding=0 1183 | while read -r line; do 1184 | local FILE=${line%:*} 1185 | local META=${line##*:} 1186 | local SIZE=${META#*;} 1187 | 1188 | if [[ ${#SIZE} -gt $padding ]]; then 1189 | padding=${#SIZE} 1190 | fi 1191 | done < "$OUT_FILE" 1192 | 1193 | #For each entry, printing directories... 1194 | while read -r line; do 1195 | 1196 | local FILE=${line%:*} 1197 | local META=${line##*:} 1198 | local TYPE=${META%;*} 1199 | local SIZE=${META#*;} 1200 | 1201 | #Removing unneeded / 1202 | FILE=${FILE##*/} 1203 | 1204 | if [[ $TYPE == "folder" ]]; then 1205 | FILE=$(echo -e "$FILE") 1206 | $PRINTF " [D] %-${padding}s %s\n" "$SIZE" "$FILE" 1207 | fi 1208 | 1209 | done < "$OUT_FILE" 1210 | 1211 | #For each entry, printing files... 1212 | while read -r line; do 1213 | 1214 | local FILE=${line%:*} 1215 | local META=${line##*:} 1216 | local TYPE=${META%;*} 1217 | local SIZE=${META#*;} 1218 | 1219 | #Removing unneeded / 1220 | FILE=${FILE##*/} 1221 | 1222 | if [[ $TYPE == "file" ]]; then 1223 | FILE=$(echo -e "$FILE") 1224 | $PRINTF " [F] %-${padding}s %s\n" "$SIZE" "$FILE" 1225 | fi 1226 | 1227 | done < "$OUT_FILE" 1228 | 1229 | rm -fr "$OUT_FILE" 1230 | } 1231 | 1232 | #Longpoll remote directory only once 1233 | #$1 = Timeout 1234 | #$2 = Remote directory 1235 | function db_monitor_nonblock 1236 | { 1237 | local TIMEOUT=$1 1238 | local DIR_DST=$(normalize_path "$2") 1239 | 1240 | if [[ "$DIR_DST" == "/" ]]; then 1241 | DIR_DST="" 1242 | fi 1243 | 1244 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"$DIR_DST\",\"include_media_info\": false,\"include_deleted\": false,\"include_has_explicit_shared_members\": false}" "$API_LIST_FOLDER_URL" 2> /dev/null 1245 | check_http_response 1246 | 1247 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1248 | 1249 | local CURSOR=$(sed -n 's/.*"cursor": *"\([^"]*\)".*/\1/p' "$RESPONSE_FILE") 1250 | 1251 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Content-Type: application/json" --data "{\"cursor\": \"$CURSOR\",\"timeout\": ${TIMEOUT}}" "$API_LONGPOLL_FOLDER" 2> /dev/null 1252 | check_http_response 1253 | 1254 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1255 | local CHANGES=$(sed -n 's/.*"changes" *: *\([a-z]*\).*/\1/p' "$RESPONSE_FILE") 1256 | else 1257 | ERROR_MSG=$(grep "Error in call" "$RESPONSE_FILE") 1258 | print "FAILED to longpoll (http error): $ERROR_MSG\n" 1259 | ERROR_STATUS=1 1260 | return 1 1261 | fi 1262 | 1263 | if [[ -z "$CHANGES" ]]; then 1264 | print "FAILED to longpoll (unexpected response)\n" 1265 | ERROR_STATUS=1 1266 | return 1 1267 | fi 1268 | 1269 | if [ "$CHANGES" == "true" ]; then 1270 | 1271 | OUT_FILE=$(db_list_outfile "$DIR_DST" "$CURSOR") 1272 | 1273 | if [ -z "$OUT_FILE" ]; then 1274 | print "FAILED to list changes\n" 1275 | ERROR_STATUS=1 1276 | return 1277 | fi 1278 | 1279 | #For each entry, printing directories... 1280 | while read -r line; do 1281 | 1282 | local FILE=${line%:*} 1283 | local META=${line##*:} 1284 | local TYPE=${META%;*} 1285 | local SIZE=${META#*;} 1286 | 1287 | #Removing unneeded / 1288 | FILE=${FILE##*/} 1289 | 1290 | if [[ $TYPE == "folder" ]]; then 1291 | FILE=$(echo -e "$FILE") 1292 | $PRINTF " [D] %s\n" "$FILE" 1293 | elif [[ $TYPE == "file" ]]; then 1294 | FILE=$(echo -e "$FILE") 1295 | $PRINTF " [F] %s %s\n" "$SIZE" "$FILE" 1296 | elif [[ $TYPE == "deleted" ]]; then 1297 | FILE=$(echo -e "$FILE") 1298 | $PRINTF " [-] %s\n" "$FILE" 1299 | fi 1300 | 1301 | done < "$OUT_FILE" 1302 | 1303 | rm -fr "$OUT_FILE" 1304 | fi 1305 | 1306 | else 1307 | ERROR_STATUS=1 1308 | return 1 1309 | fi 1310 | 1311 | } 1312 | 1313 | #Longpoll continuously remote directory 1314 | #$1 = Timeout 1315 | #$2 = Remote directory 1316 | function db_monitor 1317 | { 1318 | local TIMEOUT=$1 1319 | local DIR_DST=$(normalize_path "$2") 1320 | 1321 | while (true); do 1322 | db_monitor_nonblock "$TIMEOUT" "$2" 1323 | done 1324 | } 1325 | 1326 | #Share remote file 1327 | #$1 = Remote file 1328 | function db_share 1329 | { 1330 | local FILE_DST=$(normalize_path "$1") 1331 | 1332 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"$FILE_DST\",\"settings\": {\"requested_visibility\": \"public\"}}" "$API_SHARE_URL" 2> /dev/null 1333 | check_http_response 1334 | 1335 | #Check 1336 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1337 | print " > Share link: " 1338 | SHARE_LINK=$(sed -n 's/.*"url": "\([^"]*\).*/\1/p' "$RESPONSE_FILE") 1339 | echo "$SHARE_LINK" 1340 | else 1341 | get_Share "$FILE_DST" 1342 | fi 1343 | } 1344 | 1345 | #Query existing shared link 1346 | #$1 = Remote file 1347 | function get_Share 1348 | { 1349 | local FILE_DST=$(normalize_path "$1") 1350 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"$FILE_DST\",\"direct_only\": true}" "$API_SHARE_LIST" 1351 | check_http_response 1352 | 1353 | #Check 1354 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1355 | print " > Share link: " 1356 | SHARE_LINK=$(sed -n 's/.*"url": "\([^"]*\).*/\1/p' "$RESPONSE_FILE") 1357 | echo "$SHARE_LINK" 1358 | else 1359 | print "FAILED\n" 1360 | MESSAGE=$(sed -n 's/.*"error_summary": *"*\([^"]*\)"*.*/\1/p' "$RESPONSE_FILE") 1361 | print " > Error: $MESSAGE\n" 1362 | ERROR_STATUS=1 1363 | fi 1364 | } 1365 | 1366 | #Search on Dropbox 1367 | #$1 = query 1368 | function db_search 1369 | { 1370 | local QUERY="$1" 1371 | 1372 | print " > Searching for \"$QUERY\"... " 1373 | 1374 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"\",\"query\": \"$QUERY\",\"start\": 0,\"max_results\": 1000,\"mode\": \"filename\"}" "$API_SEARCH_URL" 2> /dev/null 1375 | check_http_response 1376 | 1377 | #Check 1378 | if grep -q "^HTTP/1.1 200 OK" "$RESPONSE_FILE"; then 1379 | print "DONE\n" 1380 | else 1381 | print "FAILED\n" 1382 | ERROR_STATUS=1 1383 | fi 1384 | 1385 | #Extracting directory content [...] 1386 | #and replacing "}, {" with "}\n{" 1387 | #I don't like this piece of code... but seems to be the only way to do this with SED, writing a portable code... 1388 | local DIR_CONTENT=$(sed 's/}, *{/}\ 1389 | {/g' "$RESPONSE_FILE") 1390 | 1391 | #Converting escaped quotes to unicode format 1392 | echo "$DIR_CONTENT" | sed 's/\\"/\\u0022/' > "$TEMP_FILE" 1393 | 1394 | #Extracting files and subfolders 1395 | rm -fr "$RESPONSE_FILE" 1396 | while read -r line; do 1397 | 1398 | local FILE=$(echo "$line" | sed -n 's/.*"path_display": *"\([^"]*\)".*/\1/p') 1399 | local TYPE=$(echo "$line" | sed -n 's/.*".tag": *"\([^"]*\).*/\1/p') 1400 | local SIZE=$(convert_bytes $(echo "$line" | sed -n 's/.*"size": *\([0-9]*\).*/\1/p')) 1401 | 1402 | echo -e "$FILE:$TYPE;$SIZE" >> "$RESPONSE_FILE" 1403 | 1404 | done < "$TEMP_FILE" 1405 | 1406 | #Looking for the biggest file size 1407 | #to calculate the padding to use 1408 | local padding=0 1409 | while read -r line; do 1410 | local FILE=${line%:*} 1411 | local META=${line##*:} 1412 | local SIZE=${META#*;} 1413 | 1414 | if [[ ${#SIZE} -gt $padding ]]; then 1415 | padding=${#SIZE} 1416 | fi 1417 | done < "$RESPONSE_FILE" 1418 | 1419 | #For each entry, printing directories... 1420 | while read -r line; do 1421 | 1422 | local FILE=${line%:*} 1423 | local META=${line##*:} 1424 | local TYPE=${META%;*} 1425 | local SIZE=${META#*;} 1426 | 1427 | if [[ $TYPE == "folder" ]]; then 1428 | FILE=$(echo -e "$FILE") 1429 | $PRINTF " [D] %-${padding}s %s\n" "$SIZE" "$FILE" 1430 | fi 1431 | 1432 | done < "$RESPONSE_FILE" 1433 | 1434 | #For each entry, printing files... 1435 | while read -r line; do 1436 | 1437 | local FILE=${line%:*} 1438 | local META=${line##*:} 1439 | local TYPE=${META%;*} 1440 | local SIZE=${META#*;} 1441 | 1442 | if [[ $TYPE == "file" ]]; then 1443 | FILE=$(echo -e "$FILE") 1444 | $PRINTF " [F] %-${padding}s %s\n" "$SIZE" "$FILE" 1445 | fi 1446 | 1447 | done < "$RESPONSE_FILE" 1448 | 1449 | } 1450 | 1451 | #Query the sha256-dropbox-sum of a remote file 1452 | #see https://www.dropbox.com/developers/reference/content-hash for more information 1453 | #$1 = Remote file 1454 | function db_sha 1455 | { 1456 | local FILE=$(normalize_path "$1") 1457 | 1458 | if [[ $FILE == "/" ]]; then 1459 | echo "ERR" 1460 | return 1461 | fi 1462 | 1463 | #Checking if it's a file or a directory and get the sha-sum 1464 | $CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"$FILE\"}" "$API_METADATA_URL" 2> /dev/null 1465 | check_http_response 1466 | 1467 | local TYPE=$(sed -n 's/{".tag": *"*\([^"]*\)"*.*/\1/p' "$RESPONSE_FILE") 1468 | if [[ $TYPE == "folder" ]]; then 1469 | echo "ERR" 1470 | return 1471 | fi 1472 | 1473 | local SHA256=$(sed -n 's/.*"content_hash": "\([^"]*\).*/\1/p' "$RESPONSE_FILE") 1474 | echo "$SHA256" 1475 | } 1476 | 1477 | #Query the sha256-dropbox-sum of a local file 1478 | #see https://www.dropbox.com/developers/reference/content-hash for more information 1479 | #$1 = Local file 1480 | function db_sha_local 1481 | { 1482 | local FILE=$(normalize_path "$1") 1483 | local FILE_SIZE=$(file_size "$FILE") 1484 | local OFFSET=0 1485 | local SKIP=0 1486 | local SHA_CONCAT="" 1487 | 1488 | which shasum > /dev/null 1489 | if [[ $? != 0 ]]; then 1490 | echo "ERR" 1491 | return 1492 | fi 1493 | 1494 | while ([[ $OFFSET -lt "$FILE_SIZE" ]]); do 1495 | dd if="$FILE" of="$CHUNK_FILE" bs=4194304 skip=$SKIP count=1 2> /dev/null 1496 | local SHA=$(shasum -a 256 "$CHUNK_FILE" | awk '{print $1}') 1497 | SHA_CONCAT="${SHA_CONCAT}${SHA}" 1498 | 1499 | let OFFSET=$OFFSET+4194304 1500 | let SKIP=$SKIP+1 1501 | done 1502 | 1503 | shaHex=$(echo $SHA_CONCAT | sed 's/\([0-9A-F]\{2\}\)/\\x\1/gI') 1504 | echo -ne $shaHex | shasum -a 256 | awk '{print $1}' 1505 | } 1506 | 1507 | ################ 1508 | #### SETUP #### 1509 | ################ 1510 | 1511 | #CHECKING FOR AUTH FILE 1512 | if [[ -e $CONFIG_FILE ]]; then 1513 | 1514 | #Loading data... and change old format config if necesary. 1515 | source "$CONFIG_FILE" 2>/dev/null || { 1516 | sed -i'' 's/:/=/' "$CONFIG_FILE" && source "$CONFIG_FILE" 2>/dev/null 1517 | } 1518 | 1519 | #Checking if it's still a v1 API configuration file 1520 | if [[ $APPKEY != "" || $APPSECRET != "" ]]; then 1521 | echo -ne "The config file contains the old deprecated v1 oauth tokens.\n" 1522 | echo -ne "Please run again the script and follow the configuration wizard. The old configuration file has been backed up to $CONFIG_FILE.old\n" 1523 | mv "$CONFIG_FILE" "$CONFIG_FILE".old 1524 | exit 1 1525 | fi 1526 | 1527 | #Checking loaded data 1528 | if [[ $OAUTH_ACCESS_TOKEN = "" ]]; then 1529 | echo -ne "Error loading data from $CONFIG_FILE...\n" 1530 | echo -ne "It is recommended to run $0 unlink\n" 1531 | remove_temp_files 1532 | exit 1 1533 | fi 1534 | 1535 | #NEW SETUP... 1536 | else 1537 | 1538 | echo -ne "\n This is the first time you run this script, please follow the instructions:\n\n" 1539 | echo -ne " 1) Open the following URL in your Browser, and log in using your account: $APP_CREATE_URL\n" 1540 | echo -ne " 2) Click on \"Create App\", then select \"Dropbox API app\"\n" 1541 | echo -ne " 3) Now go on with the configuration, choosing the app permissions and access restrictions to your DropBox folder\n" 1542 | echo -ne " 4) Enter the \"App Name\" that you prefer (e.g. MyUploader$RANDOM$RANDOM$RANDOM)\n\n" 1543 | 1544 | echo -ne " Now, click on the \"Create App\" button.\n\n" 1545 | 1546 | echo -ne " When your new App is successfully created, please click on the Generate button\n" 1547 | echo -ne " under the 'Generated access token' section, then copy and paste the new access token here:\n\n" 1548 | 1549 | echo -ne " # Access token: " 1550 | read -r OAUTH_ACCESS_TOKEN 1551 | 1552 | echo -ne "\n > The access token is $OAUTH_ACCESS_TOKEN. Looks ok? [y/N]: " 1553 | read -r answer 1554 | if [[ $answer != "y" ]]; then 1555 | remove_temp_files 1556 | exit 1 1557 | fi 1558 | 1559 | echo "OAUTH_ACCESS_TOKEN=$OAUTH_ACCESS_TOKEN" > "$CONFIG_FILE" 1560 | echo " The configuration has been saved." 1561 | 1562 | remove_temp_files 1563 | exit 0 1564 | fi 1565 | 1566 | ################ 1567 | #### START #### 1568 | ################ 1569 | 1570 | COMMAND=${*:$OPTIND:1} 1571 | ARG1=${*:$OPTIND+1:1} 1572 | ARG2=${*:$OPTIND+2:1} 1573 | 1574 | let argnum=$#-$OPTIND 1575 | 1576 | #CHECKING PARAMS VALUES 1577 | case $COMMAND in 1578 | 1579 | upload) 1580 | 1581 | if [[ $argnum -lt 2 ]]; then 1582 | usage 1583 | fi 1584 | 1585 | FILE_DST=${*:$#:1} 1586 | 1587 | for (( i=OPTIND+1; i<$#; i++ )); do 1588 | FILE_SRC=${*:$i:1} 1589 | db_upload "$FILE_SRC" "/$FILE_DST" 1590 | done 1591 | 1592 | ;; 1593 | 1594 | download) 1595 | 1596 | if [[ $argnum -lt 1 ]]; then 1597 | usage 1598 | fi 1599 | 1600 | FILE_SRC=$ARG1 1601 | FILE_DST=$ARG2 1602 | 1603 | db_download "/$FILE_SRC" "$FILE_DST" 1604 | 1605 | ;; 1606 | 1607 | saveurl) 1608 | 1609 | if [[ $argnum -lt 1 ]]; then 1610 | usage 1611 | fi 1612 | 1613 | URL=$ARG1 1614 | FILE_DST=$ARG2 1615 | 1616 | db_saveurl "$URL" "/$FILE_DST" 1617 | 1618 | ;; 1619 | 1620 | share) 1621 | 1622 | if [[ $argnum -lt 1 ]]; then 1623 | usage 1624 | fi 1625 | 1626 | FILE_DST=$ARG1 1627 | 1628 | db_share "/$FILE_DST" 1629 | 1630 | ;; 1631 | 1632 | info) 1633 | 1634 | db_account_info 1635 | 1636 | ;; 1637 | 1638 | space) 1639 | 1640 | db_account_space 1641 | 1642 | ;; 1643 | 1644 | delete|remove) 1645 | 1646 | if [[ $argnum -lt 1 ]]; then 1647 | usage 1648 | fi 1649 | 1650 | FILE_DST=$ARG1 1651 | 1652 | db_delete "/$FILE_DST" 1653 | 1654 | ;; 1655 | 1656 | move|rename) 1657 | 1658 | if [[ $argnum -lt 2 ]]; then 1659 | usage 1660 | fi 1661 | 1662 | FILE_SRC=$ARG1 1663 | FILE_DST=$ARG2 1664 | 1665 | db_move "/$FILE_SRC" "/$FILE_DST" 1666 | 1667 | ;; 1668 | 1669 | copy) 1670 | 1671 | if [[ $argnum -lt 2 ]]; then 1672 | usage 1673 | fi 1674 | 1675 | FILE_SRC=$ARG1 1676 | FILE_DST=$ARG2 1677 | 1678 | db_copy "/$FILE_SRC" "/$FILE_DST" 1679 | 1680 | ;; 1681 | 1682 | mkdir) 1683 | 1684 | if [[ $argnum -lt 1 ]]; then 1685 | usage 1686 | fi 1687 | 1688 | DIR_DST=$ARG1 1689 | 1690 | db_mkdir "/$DIR_DST" 1691 | 1692 | ;; 1693 | 1694 | search) 1695 | 1696 | if [[ $argnum -lt 1 ]]; then 1697 | usage 1698 | fi 1699 | 1700 | QUERY=$ARG1 1701 | 1702 | db_search "$QUERY" 1703 | 1704 | ;; 1705 | 1706 | list) 1707 | 1708 | DIR_DST=$ARG1 1709 | 1710 | #Checking DIR_DST 1711 | if [[ $DIR_DST == "" ]]; then 1712 | DIR_DST="/" 1713 | fi 1714 | 1715 | db_list "/$DIR_DST" 1716 | 1717 | ;; 1718 | 1719 | monitor) 1720 | 1721 | DIR_DST=$ARG1 1722 | TIMEOUT=$ARG2 1723 | 1724 | #Checking DIR_DST 1725 | if [[ $DIR_DST == "" ]]; then 1726 | DIR_DST="/" 1727 | fi 1728 | 1729 | print " > Monitoring \"$DIR_DST\" for changes...\n" 1730 | 1731 | if [[ -n $TIMEOUT ]]; then 1732 | db_monitor_nonblock $TIMEOUT "/$DIR_DST" 1733 | else 1734 | db_monitor 60 "/$DIR_DST" 1735 | fi 1736 | 1737 | ;; 1738 | 1739 | unlink) 1740 | 1741 | db_unlink 1742 | 1743 | ;; 1744 | 1745 | *) 1746 | 1747 | if [[ $COMMAND != "" ]]; then 1748 | print "Error: Unknown command: $COMMAND\n\n" 1749 | ERROR_STATUS=1 1750 | fi 1751 | usage 1752 | 1753 | ;; 1754 | 1755 | esac 1756 | 1757 | remove_temp_files 1758 | 1759 | if [[ $ERROR_STATUS -ne 0 ]]; then 1760 | echo "Some error occured. Please check the log." 1761 | fi 1762 | 1763 | exit $ERROR_STATUS 1764 | -------------------------------------------------------------------------------- /Dropbox-uploader/testUnit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DU=./dropbox_uploader.sh 4 | 5 | function check_exit 6 | { 7 | if [ $? -ne 0 ]; then 8 | echo " Error!!!" 9 | exit 1 10 | else 11 | echo " Passed" 12 | fi 13 | } 14 | 15 | #Creating garbage data 16 | echo -ne " - Creating garbage data...\n" 17 | rm -fr "testData" 18 | mkdir -p "testData" 19 | dd if=/dev/urandom of="testData/file 1.txt" bs=1M count=3 20 | dd if=/dev/urandom of="testData/file 2 ù.txt" bs=1M count=5 21 | mkdir -p "testData/recurse" 22 | dd if=/dev/urandom of="testData/recurse/file 3.txt" bs=1M count=1 23 | dd if=/dev/urandom of="testData/recurse/test_Ü.txt" bs=1M count=1 24 | mkdir -p "testData/recurse/dir 1/" 25 | dd if=/dev/urandom of="testData/recurse/dir 1/file 4.txt" bs=1M count=1 26 | mkdir -p "testData/recurse/dir 1/dir 3/" 27 | dd if=/dev/urandom of="testData/recurse/dir 1/dir 3/file 5.txt" bs=1M count=1 28 | mkdir -p "testData/recurse/dir 2/" 29 | 30 | rm -fr recurse 31 | 32 | #Rmdir 33 | echo -ne " - Remove remote directory..." 34 | $DU -q remove du_tests 35 | echo "" 36 | 37 | #Mkdir 38 | echo -ne " - Make remote directory..." 39 | $DU -q mkdir du_tests 40 | check_exit 41 | 42 | #Simple upload 43 | echo -ne " - Simple file upload..." 44 | $DU -q upload "testData/file 1.txt" du_tests 45 | check_exit 46 | 47 | #Checking with list 48 | echo -ne " - Checking file..." 49 | $DU -q list du_tests | grep "file 1.txt" > /dev/null 50 | check_exit 51 | 52 | #Simple upload 2 53 | echo -ne " - Simple file upload with special chars..." 54 | $DU -q upload testData/file\ 2* du_tests 55 | check_exit 56 | 57 | #Checking with list 58 | echo -ne " - Checking file..." 59 | $DU -q list du_tests | grep "file 2 ù.txt" > /dev/null 60 | check_exit 61 | 62 | #Recursive directory upload 63 | echo -ne " - Recursive directory upload..." 64 | $DU -q upload testData/recurse du_tests 65 | check_exit 66 | 67 | #Recursive directory download 68 | echo -ne " - Recursive directory download..." 69 | $DU -q download du_tests/recurse 70 | check_exit 71 | 72 | #Checking the downloaded dir 73 | echo -ne " - Checking the downloaded dir..." 74 | diff -r recurse testData/recurse/ 75 | check_exit 76 | 77 | #Again, recursive directory download 78 | echo -ne " - Again recursive directory download..." 79 | $DU -q download du_tests/recurse 80 | check_exit 81 | 82 | #Again, checking the downloaded dir 83 | echo -ne " - Checking the downloaded dir..." 84 | diff -r recurse testData/recurse/ 85 | check_exit 86 | 87 | rm -fr "recurse" 88 | rm -fr "testData" 89 | 90 | #Rmdir 91 | echo -ne " - Remove remote directory..." 92 | $DU -q remove du_tests 93 | check_exit 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # object_detection_cv2_tf_dn 2 | 3 | OpenCV is used to detect faces or full body on raspberry pi-3. 4 | 5 | **Tasks accomplished-** 6 | 7 | -Once the webcam detect the face/faces/body for continuously more than 20 frames, an email will be sent using **smtplib python library** on gmail address signifying that someone has been detected. 8 | 9 | 10 | -Also in the email there will be links to access real live stream video on browser using **flask python library**. Flask only let you access live stream on local network. 11 | 12 | -Link to access live video stream on global network will also be in sent email. This task requires the use of **localtunnel(free service) or ngrok(paid service)**.I have tried local tunnel on laptop but haven't tried on raspberry pi. Also global streaming can be pretty slow depending upon the network. localtunnel-https://github.com/localtunnel/localtunnel 13 | 14 | -Also when someone will be detected, a message will be sent ot personal registered mobile phone. **Twilio** has been used to send message to mobile, but needs to register on their website first, and also its a paid service. Twilio gives trial account to test their services. 15 | 16 | -A video will also be saved in a directory on raspberry pi(with current date and time), so as to see it later-on. 17 | 18 | -Older videos will automatically be deleted. You can delete videos older than may be 5 days. For testing I was deleting videos older than 1 day. 19 | 20 | -**Dropbox** services has been installed on raspberry-pi so that any videos which will be saved in raspberry pi will automaticall be synced to my personal laptop using 'dropbox'. You need to have authentication from 'Dropbox' website also. Link to get dropbox services on raspberry pi- https://www.raspberrypi.org/magpi/dropbox-raspberry-pi/ 21 | 22 | 23 | 24 | 25 | Will be updating repo for object detection using tensorflow and darknet 26 | -------------------------------------------------------------------------------- /delete_old_files.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | import glob 4 | 5 | 6 | def delete_files(path, old_days): 7 | current_time = time.time() 8 | 9 | for f in glob.glob(os.path.join(path, 'video_*')): 10 | creation_time = os.path.getctime(f) 11 | print(f, '---->>days: ', (current_time-creation_time)//(24*3600)) 12 | 13 | if (current_time - creation_time) // (24*3600) >= old_days: 14 | os.remove(f) 15 | print('{} removed'.format(f)) 16 | 17 | ##### sleeping the thread for 1 hour 18 | time.sleep(3600) 19 | 20 | 21 | -------------------------------------------------------------------------------- /dropbox_sync_folder_4_videos/video_2018-01-31_22-43-57.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pnpatel91/object_detection_cv2_tf_dn/e354a6d02cee287bc04acd05ad7c6b45d4553174/dropbox_sync_folder_4_videos/video_2018-01-31_22-43-57.mp4 -------------------------------------------------------------------------------- /generate_webcam_frame.py: -------------------------------------------------------------------------------- 1 | 2 | import cv2 3 | 4 | #### only run webcam in one python file,and import current frame wherever needed 5 | camera_port = 0 6 | frame = cv2.VideoCapture(camera_port) 7 | 8 | def webcam_frame(): 9 | return frame 10 | -------------------------------------------------------------------------------- /global_streaming_using_localtunnel.py: -------------------------------------------------------------------------------- 1 | 2 | import subprocess 3 | 4 | 5 | def run_global_stream(): 6 | 7 | subprocess.call('lt --port 5000 --subdomain abcxyz',shell=True) -------------------------------------------------------------------------------- /local_streaming_using_flask.py: -------------------------------------------------------------------------------- 1 | import generate_webcam_frame as gwf 2 | 3 | from flask import Flask, render_template, Response 4 | import cv2 5 | 6 | app = Flask(__name__) 7 | 8 | 9 | @app.route('/') 10 | def indexx(): 11 | return render_template('index.html') 12 | 13 | def get_frame(): 14 | 15 | video = gwf.webcam_frame() 16 | 17 | while True: 18 | retval, image = video.read() 19 | # We are using Motion JPEG, but OpenCV defaults to capture raw images, 20 | # so we must encode it into JPEG in order to correctly display the 21 | # video stream. 22 | ret, jpeg = cv2.imencode('.jpg', image) 23 | frame = jpeg.tobytes() 24 | yield (b'--frame\r\n' 25 | b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n') 26 | #yield frame 27 | #video.release() 28 | 29 | @app.route('/video_feed') 30 | def video_feed(): 31 | return Response(get_frame(),mimetype='multipart/x-mixed-replace; boundary=frame') 32 | 33 | def run_app(): 34 | #### try running on separate thread 35 | app.run('0.0.0.0', debug=False, threaded=True) 36 | -------------------------------------------------------------------------------- /opencv-security-cam/haarcascade_licence_plate_rus_16stages.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 64 16 7 | 8 | <_> 9 | 10 | 11 | <_> 12 | 13 | <_> 14 | 15 | 16 | 17 | <_> 18 | 32 2 8 6 -1. 19 | <_> 20 | 32 4 8 2 3. 21 | 0 22 | 1.6915600746870041e-002 23 | -9.5547717809677124e-001 24 | 8.9129137992858887e-001 25 | <_> 26 | 27 | <_> 28 | 29 | 30 | 31 | <_> 32 | 0 4 6 10 -1. 33 | <_> 34 | 3 4 3 10 2. 35 | 0 36 | 2.4228349328041077e-002 37 | -9.2089319229125977e-001 38 | 8.8723921775817871e-001 39 | <_> 40 | 41 | <_> 42 | 43 | 44 | 45 | <_> 46 | 55 0 8 6 -1. 47 | <_> 48 | 55 0 4 3 2. 49 | <_> 50 | 59 3 4 3 2. 51 | 0 52 | -1.0168660432100296e-002 53 | 8.8940089941024780e-001 54 | -7.7847331762313843e-001 55 | <_> 56 | 57 | <_> 58 | 59 | 60 | 61 | <_> 62 | 44 7 4 9 -1. 63 | <_> 64 | 44 10 4 3 3. 65 | 0 66 | 2.0863260142505169e-003 67 | -8.7998157739639282e-001 68 | 5.8651781082153320e-001 69 | -2.0683259963989258e+000 70 | -1 71 | -1 72 | <_> 73 | 74 | 75 | <_> 76 | 77 | <_> 78 | 79 | 80 | 81 | <_> 82 | 29 1 16 4 -1. 83 | <_> 84 | 29 3 16 2 2. 85 | 0 86 | 2.9062159359455109e-002 87 | -8.7765061855316162e-001 88 | 8.5373121500015259e-001 89 | <_> 90 | 91 | <_> 92 | 93 | 94 | 95 | <_> 96 | 0 5 9 8 -1. 97 | <_> 98 | 3 5 3 8 3. 99 | 0 100 | 2.3903399705886841e-002 101 | -9.2079448699951172e-001 102 | 7.5155001878738403e-001 103 | <_> 104 | 105 | <_> 106 | 107 | 108 | 109 | <_> 110 | 44 0 20 14 -1. 111 | <_> 112 | 44 0 10 7 2. 113 | <_> 114 | 54 7 10 7 2. 115 | 0 116 | -3.5404648631811142e-002 117 | 6.7834627628326416e-001 118 | -9.0937072038650513e-001 119 | <_> 120 | 121 | <_> 122 | 123 | 124 | 125 | <_> 126 | 41 7 6 9 -1. 127 | <_> 128 | 43 7 2 9 3. 129 | 0 130 | 6.2988721765577793e-003 131 | -8.1054258346557617e-001 132 | 5.8985030651092529e-001 133 | <_> 134 | 135 | <_> 136 | 137 | 138 | 139 | <_> 140 | 0 4 21 4 -1. 141 | <_> 142 | 7 4 7 4 3. 143 | 0 144 | 3.4959490876644850e-003 145 | -9.7632282972335815e-001 146 | 4.5473039150238037e-001 147 | -1.6632349491119385e+000 148 | 0 149 | -1 150 | <_> 151 | 152 | 153 | <_> 154 | 155 | <_> 156 | 157 | 158 | 159 | <_> 160 | 31 2 11 6 -1. 161 | <_> 162 | 31 4 11 2 3. 163 | 0 164 | 2.3864099755883217e-002 165 | -9.3137168884277344e-001 166 | 8.2478952407836914e-001 167 | <_> 168 | 169 | <_> 170 | 171 | 172 | 173 | <_> 174 | 56 3 6 11 -1. 175 | <_> 176 | 59 3 3 11 2. 177 | 0 178 | -2.5775209069252014e-002 179 | 8.5526448488235474e-001 180 | -8.7574672698974609e-001 181 | <_> 182 | 183 | <_> 184 | 185 | 186 | 187 | <_> 188 | 32 14 32 2 -1. 189 | <_> 190 | 32 15 32 1 2. 191 | 0 192 | -1.0646049864590168e-002 193 | 8.5167151689529419e-001 194 | -6.7789041996002197e-001 195 | <_> 196 | 197 | <_> 198 | 199 | 200 | 201 | <_> 202 | 0 2 8 14 -1. 203 | <_> 204 | 4 2 4 14 2. 205 | 0 206 | 2.7000989764928818e-002 207 | -8.0041092634201050e-001 208 | 6.4893317222595215e-001 209 | <_> 210 | 211 | <_> 212 | 213 | 214 | 215 | <_> 216 | 19 0 22 6 -1. 217 | <_> 218 | 19 0 11 3 2. 219 | <_> 220 | 30 3 11 3 2. 221 | 0 222 | 5.2989721298217773e-003 223 | -9.5342522859573364e-001 224 | 5.0140267610549927e-001 225 | -1.3346730470657349e+000 226 | 1 227 | -1 228 | <_> 229 | 230 | 231 | <_> 232 | 233 | <_> 234 | 235 | 236 | 237 | <_> 238 | 56 0 6 6 -1. 239 | <_> 240 | 56 0 3 3 2. 241 | <_> 242 | 59 3 3 3 2. 243 | 0 244 | -6.9233630783855915e-003 245 | 8.2654470205307007e-001 246 | -8.5396027565002441e-001 247 | <_> 248 | 249 | <_> 250 | 251 | 252 | 253 | <_> 254 | 32 0 14 12 -1. 255 | <_> 256 | 32 0 7 6 2. 257 | <_> 258 | 39 6 7 6 2. 259 | 0 260 | 1.2539249658584595e-001 261 | -1.2996139936149120e-002 262 | -3.2377028808593750e+003 263 | <_> 264 | 265 | <_> 266 | 267 | 268 | 269 | <_> 270 | 2 1 43 4 -1. 271 | <_> 272 | 2 3 43 2 2. 273 | 0 274 | 6.3474893569946289e-002 275 | -6.4648061990737915e-001 276 | 8.2302427291870117e-001 277 | <_> 278 | 279 | <_> 280 | 281 | 282 | 283 | <_> 284 | 34 10 30 5 -1. 285 | <_> 286 | 44 10 10 5 3. 287 | 0 288 | 4.2217150330543518e-002 289 | -7.5190877914428711e-001 290 | 6.3705182075500488e-001 291 | <_> 292 | 293 | <_> 294 | 295 | 296 | 297 | <_> 298 | 0 9 9 5 -1. 299 | <_> 300 | 3 9 3 5 3. 301 | 0 302 | 2.0000640302896500e-002 303 | -6.2077498435974121e-001 304 | 6.1317932605743408e-001 305 | -1.6521669626235962e+000 306 | 2 307 | -1 308 | <_> 309 | 310 | 311 | <_> 312 | 313 | <_> 314 | 315 | 316 | 317 | <_> 318 | 2 1 43 6 -1. 319 | <_> 320 | 2 3 43 2 3. 321 | 0 322 | 9.2297486960887909e-002 323 | -7.2764229774475098e-001 324 | 8.0554759502410889e-001 325 | <_> 326 | 327 | <_> 328 | 329 | 330 | 331 | <_> 332 | 53 4 9 8 -1. 333 | <_> 334 | 56 4 3 8 3. 335 | 0 336 | 2.7613969519734383e-002 337 | -7.0769268274307251e-001 338 | 7.3315787315368652e-001 339 | <_> 340 | 341 | <_> 342 | 343 | 344 | 345 | <_> 346 | 36 4 14 8 -1. 347 | <_> 348 | 36 4 7 4 2. 349 | <_> 350 | 43 8 7 4 2. 351 | 0 352 | 1.2465449981391430e-002 353 | -8.4359270334243774e-001 354 | 5.7046437263488770e-001 355 | <_> 356 | 357 | <_> 358 | 359 | 360 | 361 | <_> 362 | 14 14 49 2 -1. 363 | <_> 364 | 14 15 49 1 2. 365 | 0 366 | -2.3886829614639282e-002 367 | 8.2656508684158325e-001 368 | -5.2783298492431641e-001 369 | -1.4523630142211914e+000 370 | 3 371 | -1 372 | <_> 373 | 374 | 375 | <_> 376 | 377 | <_> 378 | 379 | 380 | 381 | <_> 382 | 0 5 4 9 -1. 383 | <_> 384 | 2 5 2 9 2. 385 | 0 386 | 1.8821349367499352e-002 387 | -8.1122857332229614e-001 388 | 6.9127470254898071e-001 389 | <_> 390 | 391 | <_> 392 | 393 | 394 | 395 | <_> 396 | 21 1 38 4 -1. 397 | <_> 398 | 21 3 38 2 2. 399 | 0 400 | 6.1703320592641830e-002 401 | -7.6482647657394409e-001 402 | 6.4212161302566528e-001 403 | <_> 404 | 405 | <_> 406 | 407 | 408 | 409 | <_> 410 | 44 12 18 3 -1. 411 | <_> 412 | 53 12 9 3 2. 413 | 0 414 | -1.6298670321702957e-002 415 | 5.0207728147506714e-001 416 | -8.4020161628723145e-001 417 | <_> 418 | 419 | <_> 420 | 421 | 422 | 423 | <_> 424 | 10 4 9 3 -1. 425 | <_> 426 | 13 4 3 3 3. 427 | 0 428 | -4.9458951689302921e-003 429 | 6.1991941928863525e-001 430 | -6.1633539199829102e-001 431 | <_> 432 | 433 | <_> 434 | 435 | 436 | 437 | <_> 438 | 40 4 10 4 -1. 439 | <_> 440 | 45 4 5 4 2. 441 | 0 442 | -5.1894597709178925e-003 443 | 4.4975179433822632e-001 444 | -8.0651968717575073e-001 445 | <_> 446 | 447 | <_> 448 | 449 | 450 | 451 | <_> 452 | 17 14 47 2 -1. 453 | <_> 454 | 17 15 47 1 2. 455 | 0 456 | -1.8824130296707153e-002 457 | 6.1992841958999634e-001 458 | -5.5643159151077271e-001 459 | <_> 460 | 461 | <_> 462 | 463 | 464 | 465 | <_> 466 | 8 5 4 7 -1. 467 | <_> 468 | 10 5 2 7 2. 469 | 0 470 | 5.6571601890027523e-003 471 | -4.8346561193466187e-001 472 | 6.8647360801696777e-001 473 | -2.2358059883117676e+000 474 | 4 475 | -1 476 | <_> 477 | 478 | 479 | <_> 480 | 481 | <_> 482 | 483 | 484 | 485 | <_> 486 | 56 0 6 6 -1. 487 | <_> 488 | 56 0 3 3 2. 489 | <_> 490 | 59 3 3 3 2. 491 | 0 492 | -9.1503243893384933e-003 493 | 6.8174481391906738e-001 494 | -7.7866071462631226e-001 495 | <_> 496 | 497 | <_> 498 | 499 | 500 | 501 | <_> 502 | 0 0 6 6 -1. 503 | <_> 504 | 0 0 3 3 2. 505 | <_> 506 | 3 3 3 3 2. 507 | 0 508 | 7.4933180585503578e-003 509 | -6.8696027994155884e-001 510 | 6.6913938522338867e-001 511 | <_> 512 | 513 | <_> 514 | 515 | 516 | 517 | <_> 518 | 13 4 48 2 -1. 519 | <_> 520 | 29 4 16 2 3. 521 | 0 522 | 4.5296419411897659e-002 523 | -7.3576509952545166e-001 524 | 5.9453499317169189e-001 525 | <_> 526 | 527 | <_> 528 | 529 | 530 | 531 | <_> 532 | 42 1 6 15 -1. 533 | <_> 534 | 42 6 6 5 3. 535 | 0 536 | 1.1669679544866085e-002 537 | -8.4733831882476807e-001 538 | 4.5461329817771912e-001 539 | <_> 540 | 541 | <_> 542 | 543 | 544 | 545 | <_> 546 | 30 8 3 5 -1. 547 | <_> 548 | 31 8 1 5 3. 549 | 0 550 | 2.5769430212676525e-003 551 | -5.8270388841629028e-001 552 | 7.7900522947311401e-001 553 | <_> 554 | 555 | <_> 556 | 557 | 558 | 559 | <_> 560 | 55 10 8 6 -1. 561 | <_> 562 | 55 13 8 3 2. 563 | 0 564 | -1.4139170525595546e-003 565 | 4.5126929879188538e-001 566 | -9.0696328878402710e-001 567 | -1.8782069683074951e+000 568 | 5 569 | -1 570 | <_> 571 | 572 | 573 | <_> 574 | 575 | <_> 576 | 577 | 578 | 579 | <_> 580 | 4 6 4 7 -1. 581 | <_> 582 | 6 6 2 7 2. 583 | 0 584 | -5.3149578161537647e-003 585 | 6.5218788385391235e-001 586 | -7.9464268684387207e-001 587 | <_> 588 | 589 | <_> 590 | 591 | 592 | 593 | <_> 594 | 56 3 6 8 -1. 595 | <_> 596 | 59 3 3 8 2. 597 | 0 598 | -2.2906960919499397e-002 599 | 6.6433382034301758e-001 600 | -7.3633247613906860e-001 601 | <_> 602 | 603 | <_> 604 | 605 | 606 | 607 | <_> 608 | 37 2 4 6 -1. 609 | <_> 610 | 37 4 4 2 3. 611 | 0 612 | 9.4887977465987206e-003 613 | -8.2612031698226929e-001 614 | 4.9333500862121582e-001 615 | <_> 616 | 617 | <_> 618 | 619 | 620 | 621 | <_> 622 | 0 10 30 6 -1. 623 | <_> 624 | 0 12 30 2 3. 625 | 0 626 | 4.5138411223888397e-002 627 | -5.4704028367996216e-001 628 | 7.6927912235260010e-001 629 | <_> 630 | 631 | <_> 632 | 633 | 634 | 635 | <_> 636 | 0 4 21 12 -1. 637 | <_> 638 | 7 4 7 12 3. 639 | 0 640 | 2.5049019604921341e-002 641 | -8.6739641427993774e-001 642 | 5.2807968854904175e-001 643 | -1.0597369670867920e+000 644 | 6 645 | -1 646 | <_> 647 | 648 | 649 | <_> 650 | 651 | <_> 652 | 653 | 654 | 655 | <_> 656 | 44 0 1 14 -1. 657 | <_> 658 | 44 7 1 7 2. 659 | 0 660 | 6.6414438188076019e-003 661 | -7.7290147542953491e-001 662 | 6.9723731279373169e-001 663 | <_> 664 | 665 | <_> 666 | 667 | 668 | 669 | <_> 670 | 54 3 4 3 -1. 671 | <_> 672 | 56 3 2 3 2. 673 | 0 674 | 2.4703629314899445e-003 675 | -7.4289917945861816e-001 676 | 6.6825848817825317e-001 677 | <_> 678 | 679 | <_> 680 | 681 | 682 | 683 | <_> 684 | 32 0 30 6 -1. 685 | <_> 686 | 32 0 15 3 2. 687 | <_> 688 | 47 3 15 3 2. 689 | 0 690 | -2.2910499945282936e-002 691 | 4.3986389040946960e-001 692 | -9.0588808059692383e-001 693 | <_> 694 | 695 | <_> 696 | 697 | 698 | 699 | <_> 700 | 0 8 9 7 -1. 701 | <_> 702 | 3 8 3 7 3. 703 | 0 704 | 3.4193221479654312e-002 705 | -6.9507479667663574e-001 706 | 6.2501090764999390e-001 707 | <_> 708 | 709 | <_> 710 | 711 | 712 | 713 | <_> 714 | 30 10 3 3 -1. 715 | <_> 716 | 31 10 1 3 3. 717 | 0 718 | 1.5060020377859473e-003 719 | -6.8670761585235596e-001 720 | 8.2241541147232056e-001 721 | <_> 722 | 723 | <_> 724 | 725 | 726 | 727 | <_> 728 | 21 3 24 4 -1. 729 | <_> 730 | 29 3 8 4 3. 731 | 0 732 | 1.9838380467263050e-005 733 | -9.2727631330490112e-001 734 | 6.4723730087280273e-001 735 | <_> 736 | 737 | <_> 738 | 739 | 740 | 741 | <_> 742 | 42 3 12 6 -1. 743 | <_> 744 | 46 3 4 6 3. 745 | 0 746 | -2.2170299416757189e-005 747 | 5.6555831432342529e-001 748 | -9.6788132190704346e-001 749 | -1.4993519783020020e+000 750 | 7 751 | -1 752 | <_> 753 | 754 | 755 | <_> 756 | 757 | <_> 758 | 759 | 760 | 761 | <_> 762 | 56 9 6 6 -1. 763 | <_> 764 | 59 9 3 6 2. 765 | 0 766 | -1.1395259760320187e-002 767 | 7.1383631229400635e-001 768 | -8.7429678440093994e-001 769 | <_> 770 | 771 | <_> 772 | 773 | 774 | 775 | <_> 776 | 6 4 1 6 -1. 777 | <_> 778 | 6 7 1 3 2. 779 | 0 780 | -2.1864590235054493e-003 781 | 8.5311782360076904e-001 782 | -6.4777731895446777e-001 783 | <_> 784 | 785 | <_> 786 | 787 | 788 | 789 | <_> 790 | 0 0 12 4 -1. 791 | <_> 792 | 0 0 6 2 2. 793 | <_> 794 | 6 2 6 2 2. 795 | 0 796 | 2.3193720262497663e-003 797 | -7.6411879062652588e-001 798 | 7.1867972612380981e-001 799 | <_> 800 | 801 | <_> 802 | 803 | 804 | 805 | <_> 806 | 43 12 18 2 -1. 807 | <_> 808 | 52 12 9 2 2. 809 | 0 810 | -7.9916073009371758e-003 811 | 6.6442942619323730e-001 812 | -7.9540950059890747e-001 813 | <_> 814 | 815 | <_> 816 | 817 | 818 | 819 | <_> 820 | 9 5 2 8 -1. 821 | <_> 822 | 10 5 1 8 2. 823 | 0 824 | 1.4212740352377295e-003 825 | -6.3904231786727905e-001 826 | 7.5050598382949829e-001 827 | -8.4829801321029663e-001 828 | 8 829 | -1 830 | <_> 831 | 832 | 833 | <_> 834 | 835 | <_> 836 | 837 | 838 | 839 | <_> 840 | 1 9 6 3 -1. 841 | <_> 842 | 3 9 2 3 3. 843 | 0 844 | 6.4091659151017666e-003 845 | -8.8425230979919434e-001 846 | 9.9953681230545044e-001 847 | <_> 848 | 849 | <_> 850 | 851 | 852 | 853 | <_> 854 | 56 8 2 8 -1. 855 | <_> 856 | 56 12 2 4 2. 857 | 0 858 | -6.3316390151157975e-004 859 | 8.3822172880172729e-001 860 | -9.8322170972824097e-001 861 | <_> 862 | 863 | <_> 864 | 865 | 866 | 867 | <_> 868 | 24 2 6 13 -1. 869 | <_> 870 | 26 2 2 13 3. 871 | 0 872 | -6.4947169448714703e-005 873 | 1. 874 | -9.1822808980941772e-001 875 | <_> 876 | 877 | <_> 878 | 879 | 880 | 881 | <_> 882 | 33 7 24 4 -1. 883 | <_> 884 | 41 7 8 4 3. 885 | 0 886 | 5.3404141217470169e-003 887 | -9.4317251443862915e-001 888 | 9.0425151586532593e-001 889 | -6.0007210820913315e-002 890 | 9 891 | -1 892 | <_> 893 | 894 | 895 | <_> 896 | 897 | <_> 898 | 899 | 900 | 901 | <_> 902 | 1 1 57 4 -1. 903 | <_> 904 | 1 3 57 2 2. 905 | 0 906 | 1.0755469650030136e-001 907 | -7.1647202968597412e-001 908 | 8.7827038764953613e-001 909 | <_> 910 | 911 | <_> 912 | 913 | 914 | 915 | <_> 916 | 0 2 6 14 -1. 917 | <_> 918 | 3 2 3 14 2. 919 | 0 920 | 3.1668949872255325e-002 921 | -8.7051069736480713e-001 922 | 5.8807212114334106e-001 923 | <_> 924 | 925 | <_> 926 | 927 | 928 | 929 | <_> 930 | 52 3 6 10 -1. 931 | <_> 932 | 54 3 2 10 3. 933 | 0 934 | -1.0572380386292934e-002 935 | 6.2438100576400757e-001 936 | -7.4027371406555176e-001 937 | <_> 938 | 939 | <_> 940 | 941 | 942 | 943 | <_> 944 | 1 14 61 2 -1. 945 | <_> 946 | 1 15 61 1 2. 947 | 0 948 | -2.7396259829401970e-002 949 | 8.9776748418807983e-001 950 | -5.2986758947372437e-001 951 | <_> 952 | 953 | <_> 954 | 955 | 956 | 957 | <_> 958 | 28 0 11 12 -1. 959 | <_> 960 | 28 4 11 4 3. 961 | 0 962 | 2.5918649509549141e-002 963 | -8.6482518911361694e-001 964 | 5.3121817111968994e-001 965 | -9.6125108003616333e-001 966 | 10 967 | -1 968 | <_> 969 | 970 | 971 | <_> 972 | 973 | <_> 974 | 975 | 976 | 977 | <_> 978 | 22 1 41 4 -1. 979 | <_> 980 | 22 3 41 2 2. 981 | 0 982 | 7.1039132773876190e-002 983 | -7.5719678401947021e-001 984 | 7.5645631551742554e-001 985 | <_> 986 | 987 | <_> 988 | 989 | 990 | 991 | <_> 992 | 41 6 6 8 -1. 993 | <_> 994 | 43 6 2 8 3. 995 | 0 996 | 7.6241148635745049e-003 997 | -7.9783838987350464e-001 998 | 7.1733069419860840e-001 999 | <_> 1000 | 1001 | <_> 1002 | 1003 | 1004 | 1005 | <_> 1006 | 50 9 14 5 -1. 1007 | <_> 1008 | 57 9 7 5 2. 1009 | 0 1010 | -2.7092639356851578e-002 1011 | 6.0071170330047607e-001 1012 | -8.4794402122497559e-001 1013 | <_> 1014 | 1015 | <_> 1016 | 1017 | 1018 | 1019 | <_> 1020 | 4 1 12 5 -1. 1021 | <_> 1022 | 10 1 6 5 2. 1023 | 0 1024 | -8.1267888890579343e-004 1025 | 5.9364068508148193e-001 1026 | -8.9295238256454468e-001 1027 | <_> 1028 | 1029 | <_> 1030 | 1031 | 1032 | 1033 | <_> 1034 | 37 9 3 3 -1. 1035 | <_> 1036 | 38 9 1 3 3. 1037 | 0 1038 | 8.3705072756856680e-004 1039 | -6.4887362718582153e-001 1040 | 7.8537952899932861e-001 1041 | -1.0618970394134521e+000 1042 | 11 1043 | -1 1044 | <_> 1045 | 1046 | 1047 | <_> 1048 | 1049 | <_> 1050 | 1051 | 1052 | 1053 | <_> 1054 | 54 0 10 6 -1. 1055 | <_> 1056 | 54 0 5 3 2. 1057 | <_> 1058 | 59 3 5 3 2. 1059 | 0 1060 | -9.7556859254837036e-003 1061 | 7.6982218027114868e-001 1062 | -8.5293501615524292e-001 1063 | <_> 1064 | 1065 | <_> 1066 | 1067 | 1068 | 1069 | <_> 1070 | 47 0 6 11 -1. 1071 | <_> 1072 | 49 0 2 11 3. 1073 | 0 1074 | -8.6617246270179749e-003 1075 | 8.4029090404510498e-001 1076 | -7.1949690580368042e-001 1077 | <_> 1078 | 1079 | <_> 1080 | 1081 | 1082 | 1083 | <_> 1084 | 19 2 20 2 -1. 1085 | <_> 1086 | 19 3 20 1 2. 1087 | 0 1088 | 1.6897840425372124e-002 1089 | -5.3601992130279541e-001 1090 | 9.5484441518783569e-001 1091 | <_> 1092 | 1093 | <_> 1094 | 1095 | 1096 | 1097 | <_> 1098 | 14 4 6 11 -1. 1099 | <_> 1100 | 17 4 3 11 2. 1101 | 0 1102 | 4.7526158596156165e-005 1103 | -7.6412862539291382e-001 1104 | 7.5398761034011841e-001 1105 | <_> 1106 | 1107 | <_> 1108 | 1109 | 1110 | 1111 | <_> 1112 | 31 9 33 2 -1. 1113 | <_> 1114 | 42 9 11 2 3. 1115 | 0 1116 | 6.5607670694589615e-003 1117 | -9.9346441030502319e-001 1118 | 6.4864277839660645e-001 1119 | -7.3307347297668457e-001 1120 | 12 1121 | -1 1122 | <_> 1123 | 1124 | 1125 | <_> 1126 | 1127 | <_> 1128 | 1129 | 1130 | 1131 | <_> 1132 | 6 1 53 6 -1. 1133 | <_> 1134 | 6 3 53 2 3. 1135 | 0 1136 | 1.0103269666433334e-001 1137 | -7.3275578022003174e-001 1138 | 8.4619927406311035e-001 1139 | <_> 1140 | 1141 | <_> 1142 | 1143 | 1144 | 1145 | <_> 1146 | 49 9 4 6 -1. 1147 | <_> 1148 | 49 9 2 3 2. 1149 | <_> 1150 | 51 12 2 3 2. 1151 | 0 1152 | -2.8920811018906534e-004 1153 | 7.1564781665802002e-001 1154 | -8.8221758604049683e-001 1155 | <_> 1156 | 1157 | <_> 1158 | 1159 | 1160 | 1161 | <_> 1162 | 0 9 30 7 -1. 1163 | <_> 1164 | 10 9 10 7 3. 1165 | 0 1166 | 1.0838840156793594e-002 1167 | -8.7420248985290527e-001 1168 | 6.0648679733276367e-001 1169 | <_> 1170 | 1171 | <_> 1172 | 1173 | 1174 | 1175 | <_> 1176 | 40 4 6 2 -1. 1177 | <_> 1178 | 42 4 2 2 3. 1179 | 0 1180 | 5.0803890917450190e-004 1181 | -9.0554022789001465e-001 1182 | 6.4213967323303223e-001 1183 | <_> 1184 | 1185 | <_> 1186 | 1187 | 1188 | 1189 | <_> 1190 | 1 9 6 1 -1. 1191 | <_> 1192 | 3 9 2 1 3. 1193 | 0 1194 | 2.3357039317488670e-003 1195 | -9.2574918270111084e-001 1196 | 8.6384928226470947e-001 1197 | <_> 1198 | 1199 | <_> 1200 | 1201 | 1202 | 1203 | <_> 1204 | 47 3 4 10 -1. 1205 | <_> 1206 | 47 8 4 5 2. 1207 | 0 1208 | 8.0239427916239947e-005 1209 | -9.9618428945541382e-001 1210 | 9.5355111360549927e-001 1211 | <_> 1212 | 1213 | <_> 1214 | 1215 | 1216 | 1217 | <_> 1218 | 31 5 30 11 -1. 1219 | <_> 1220 | 41 5 10 11 3. 1221 | 0 1222 | 3.2030208967626095e-003 1223 | -1. 1224 | 1.0001050233840942e+000 1225 | <_> 1226 | 1227 | <_> 1228 | 1229 | 1230 | 1231 | <_> 1232 | 0 0 2 1 -1. 1233 | <_> 1234 | 1 0 1 1 2. 1235 | 0 1236 | 0. 1237 | 0. 1238 | -1. 1239 | <_> 1240 | 1241 | <_> 1242 | 1243 | 1244 | 1245 | <_> 1246 | 21 3 42 5 -1. 1247 | <_> 1248 | 35 3 14 5 3. 1249 | 0 1250 | 2.6143440045416355e-003 1251 | -1. 1252 | 1.0002139806747437e+000 1253 | <_> 1254 | 1255 | <_> 1256 | 1257 | 1258 | 1259 | <_> 1260 | 0 0 2 1 -1. 1261 | <_> 1262 | 1 0 1 1 2. 1263 | 0 1264 | 0. 1265 | 0. 1266 | -1. 1267 | <_> 1268 | 1269 | <_> 1270 | 1271 | 1272 | 1273 | <_> 1274 | 8 5 30 9 -1. 1275 | <_> 1276 | 8 8 30 3 3. 1277 | 0 1278 | -7.0475979009643197e-004 1279 | 1. 1280 | -9.9976968765258789e-001 1281 | <_> 1282 | 1283 | <_> 1284 | 1285 | 1286 | 1287 | <_> 1288 | 3 12 33 3 -1. 1289 | <_> 1290 | 14 12 11 3 3. 1291 | 0 1292 | 2.1271279547363520e-003 1293 | -9.9694627523422241e-001 1294 | 1.0002720355987549e+000 1295 | <_> 1296 | 1297 | <_> 1298 | 1299 | 1300 | 1301 | <_> 1302 | 0 0 3 2 -1. 1303 | <_> 1304 | 1 0 1 2 3. 1305 | 0 1306 | -2.4224430671893060e-004 1307 | 1. 1308 | -1. 1309 | <_> 1310 | 1311 | <_> 1312 | 1313 | 1314 | 1315 | <_> 1316 | 46 4 3 8 -1. 1317 | <_> 1318 | 47 4 1 8 3. 1319 | 0 1320 | 7.4700301047414541e-004 1321 | -9.9108231067657471e-001 1322 | 9.9941182136535645e-001 1323 | -1.0991690158843994e+000 1324 | 13 1325 | -1 1326 | <_> 1327 | 1328 | 1329 | <_> 1330 | 1331 | <_> 1332 | 1333 | 1334 | 1335 | <_> 1336 | 1 2 6 5 -1. 1337 | <_> 1338 | 3 2 2 5 3. 1339 | 0 1340 | 1.7227890202775598e-003 1341 | -9.3608891963958740e-001 1342 | 8.7251222133636475e-001 1343 | <_> 1344 | 1345 | <_> 1346 | 1347 | 1348 | 1349 | <_> 1350 | 0 3 18 5 -1. 1351 | <_> 1352 | 6 3 6 5 3. 1353 | 0 1354 | 2.7599320746958256e-003 1355 | -9.9757021665573120e-001 1356 | 1.0000289678573608e+000 1357 | <_> 1358 | 1359 | <_> 1360 | 1361 | 1362 | 1363 | <_> 1364 | 3 1 6 14 -1. 1365 | <_> 1366 | 6 1 3 14 2. 1367 | 0 1368 | -8.9444358309265226e-005 1369 | 1. 1370 | -9.9264812469482422e-001 1371 | <_> 1372 | 1373 | <_> 1374 | 1375 | 1376 | 1377 | <_> 1378 | 3 6 2 10 -1. 1379 | <_> 1380 | 3 11 2 5 2. 1381 | 0 1382 | -2.7962020249105990e-004 1383 | 8.2833290100097656e-001 1384 | -9.8444151878356934e-001 1385 | <_> 1386 | 1387 | <_> 1388 | 1389 | 1390 | 1391 | <_> 1392 | 42 0 4 6 -1. 1393 | <_> 1394 | 42 0 2 3 2. 1395 | <_> 1396 | 44 3 2 3 2. 1397 | 0 1398 | -2.7560539820115082e-005 1399 | 1. 1400 | -9.9543339014053345e-001 1401 | -9.1314977407455444e-001 1402 | 14 1403 | -1 1404 | 1405 | -------------------------------------------------------------------------------- /opencv-security-cam/image_saved.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pnpatel91/object_detection_cv2_tf_dn/e354a6d02cee287bc04acd05ad7c6b45d4553174/opencv-security-cam/image_saved.png -------------------------------------------------------------------------------- /opencv-security-cam/opencv-security-cam-5.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import time 4 | 5 | 6 | #### using to import modules saved in different directory 7 | import sys 8 | sys.path.insert(0, '/home/pi/object_detection_cv2_tf_dn') 9 | 10 | #%% 11 | ##### save files to dropbox-rpi 12 | import sync_using_dropbox_rpi as sudr 13 | ##### smtplib is used to send email notifications 14 | import sending_email_using_smtplib as seus 15 | ##### twilio is used to send messages to mobile (trial version,paid service) 16 | import sending_messages_using_twilio as smut 17 | #### only run webcam in one python file,and import current frame wherever needed 18 | import generate_webcam_frame as gwf 19 | #### local streaming using flask with multithreading 20 | import local_streaming_using_flask as lsuf 21 | import threading 22 | print('no of threads active: ', threading.active_count()) 23 | t1 = threading.Thread(target=lsuf.run_app, name='thread1') 24 | t1.daemon = True 25 | t1.start() 26 | 27 | 28 | #### global streaming using localtunnel with multithreading 29 | import global_streaming_using_localtunnel as gsul 30 | print('no of threads active: ', threading.active_count()) 31 | t2 = threading.Thread(target=gsul.run_global_stream, name='thread2') 32 | t2.daemon = True 33 | t2.start() 34 | 35 | #### delete files older than particular no. of days 36 | import delete_old_files as dof 37 | #stored_files_path = "/home/pi/opencv-security-cam" 38 | stored_files_path = "/home/pi/object_detection_cv2_tf_dn/dropbox_sync_folder_4_videos" 39 | older_than_days = 1 40 | 41 | print('no of threads active: ', threading.active_count()) 42 | t3 = threading.Thread(target=dof.delete_files, name='thread3',args=(stored_files_path, older_than_days)) 43 | t3.daemon = True 44 | t3.start() 45 | 46 | print('no of threads active: ', threading.active_count()) 47 | 48 | 49 | 50 | #%% 51 | import collections 52 | 53 | import datetime 54 | print(datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) 55 | 56 | 57 | cap = gwf.webcam_frame() 58 | print(cap.isOpened()) 59 | 60 | #cap = cv2.VideoCapture(0) 61 | #cap = cv2.VideoCapture("test.mp4") 62 | # Define the codec and create VideoWriter object 63 | fourcc = cv2.VideoWriter_fourcc(*'XVID') 64 | 65 | time_in_sec = 2 66 | max_length = 20*time_in_sec #### multiplied by 20, which is cv2 fps 67 | percent_check_on_store_video_deque = int(0.7 * max_length) 68 | store_video_deque = collections.deque(maxlen = max_length) 69 | for i in range(store_video_deque.maxlen): 70 | store_video_deque.append(False) 71 | #print(store_video_deque[i]) 72 | 73 | index=1 74 | make_new_video_file = True 75 | import os 76 | #dropbox_path = "/home/pi/opencv-security-cam" 77 | dropbox_path = "/home/pi/object_detection_cv2_tf_dn/dropbox_sync_folder_4_videos" 78 | 79 | while (cap.isOpened()): 80 | ret, image_np = cap.read() 81 | # print(ret) 82 | 83 | 84 | if (ret==True): 85 | 86 | #cv2.imshow('object detection', cv2.resize(image_np, (1200,600))) 87 | 88 | #Load a cascade file for detecting faces 89 | face_cascade = cv2.CascadeClassifier('/home/pi/object_detection_cv2_tf_dn/opencv-security-cam/haarcascade_frontalface_default.xml') 90 | 91 | #Convert to grayscale 92 | gray = cv2.cvtColor(image_np,cv2.COLOR_BGR2GRAY) 93 | 94 | #Look for faces in the image using the loaded cascade file 95 | faces = face_cascade.detectMultiScale(gray, 1.3, 5) 96 | 97 | print ("Found "+str(len(faces))+" face(s)") 98 | 99 | #Draw a rectangle around every found face 100 | for (x,y,w,h) in faces: 101 | cv2.rectangle(image_np,(x,y),(x+w,y+h),(255,255,0),2) 102 | 103 | # #Save the result image 104 | ## cv2.imwrite('result.jpg',image_np) 105 | #cv2.imshow('object detection1', cv2.resize(image_np, (800,600))) 106 | 107 | 108 | if (len(faces)>0): 109 | store_video_deque.append(True) 110 | else: 111 | store_video_deque.append(False) 112 | 113 | true_count = store_video_deque.count(True) 114 | print(store_video_deque.count(True), percent_check_on_store_video_deque) 115 | 116 | if(true_count > percent_check_on_store_video_deque): 117 | if(make_new_video_file): 118 | sudr.sync_folder() 119 | #video_name = "video"+str(index)+".mp4" 120 | video_name = "video_"+str(datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))+".mp4" 121 | video_name = os.path.join(dropbox_path, video_name) 122 | #### be careful about image shape dimension, must match with last column in cv2.VideoWriter 123 | out1 = cv2.VideoWriter(video_name,fourcc, 20.0, (cap.read()[1].shape[1],cap.read()[1].shape[0])) 124 | make_new_video_file = False 125 | 126 | cv2.imwrite("image_saved.png",image_np) 127 | 128 | #### sending email using smtplib 129 | seus.attached_text_and_image("image_saved.png") 130 | #### sending msg using twilio 131 | ####smut.send_msg() 132 | 133 | 134 | print(video_name) 135 | out1.write(image_np) 136 | #cv2.imshow('object detection2', cv2.resize(image_np, (800,600))) 137 | 138 | else: 139 | 140 | if not (make_new_video_file): 141 | index=index+1 142 | make_new_video_file = True 143 | #cv2.destroyAllWindows() 144 | 145 | if cv2.waitKey(25) & 0xFF == ord('q'): 146 | cv2.destroyAllWindows() 147 | cap.release() 148 | break 149 | else: 150 | break 151 | 152 | 153 | 154 | # When everything done, release the capture 155 | cap.release() 156 | cv2.destroyAllWindows() 157 | out1.release() 158 | seus.quit_server() 159 | -------------------------------------------------------------------------------- /sending_email_using_smtplib.py: -------------------------------------------------------------------------------- 1 | import smtplib 2 | 3 | server = smtplib.SMTP('smtp.gmail.com',587) 4 | #server.connect("smtp.gmail.com", 25) 5 | server.ehlo() 6 | server.starttls() 7 | server.ehlo() 8 | server.login("sunny......@gmail.com", "give_password") 9 | 10 | #sender = 'sunny.....@gmail.com' 11 | #receivers = ['sunny.ch.....@city.ac.uk'] 12 | # 13 | #message = """From: sunny-gmail 14 | #To: sunny-city 15 | #Subject: --new video detected-- 16 | # 17 | #Check the new video.""" 18 | 19 | from email.mime.text import MIMEText 20 | from email.mime.multipart import MIMEMultipart 21 | from email.mime.image import MIMEImage 22 | 23 | 24 | fromaddr = "sunny......@gmail.com" 25 | toaddr = "sunny.ch.....@city.ac.uk" 26 | 27 | 28 | def attached_text_and_image(image): 29 | msg = MIMEMultipart() 30 | msg['From'] = fromaddr 31 | msg['To'] = toaddr 32 | body = "Check the new video." 33 | msg.attach(MIMEText(body, 'plain')) 34 | msg['Subject'] = "--new video detected--" 35 | 36 | #msgAlternative = MIMEMultipart('alternative') 37 | # Create the body of the message (a plain-text and an HTML version). 38 | text = "Hi!\nHow are you?\nHere are the links you wanted:\n\nwindows-dell: 192.168.0.70:5000\nor\nrasp-pi: 192.168.0.85:5000" 39 | html = """\ 40 | 41 | 42 | 43 |

Hi!
44 | How are you?\n
45 | Here is the global streaming link using localtunnel 46 |

47 | 48 | 49 | """ 50 | # Record the MIME types of both parts - text/plain and text/html. 51 | part1 = MIMEText(text, 'plain') 52 | part2 = MIMEText(html, 'html') 53 | 54 | # Attach parts into message container. 55 | # According to RFC 2046, the last part of a multipart message, in this case 56 | # the HTML message, is best and preferred. 57 | msg.attach(part1) 58 | msg.attach(part2) 59 | 60 | with open(image, 'rb') as fp: 61 | img = MIMEImage(fp.read()) 62 | msg.attach(img) 63 | 64 | text = msg.as_string() 65 | server.sendmail(fromaddr, toaddr, text) 66 | 67 | 68 | def quit_server(): 69 | server.quit() 70 | -------------------------------------------------------------------------------- /sending_messages_using_twilio.py: -------------------------------------------------------------------------------- 1 | 2 | from twilio.rest import Client 3 | 4 | def send_msg(): 5 | # Your Account SID from twilio.com/console 6 | account_sid = "ACc2e9f381a58e......................" 7 | # Your Auth Token from twilio.com/console 8 | auth_token = "3fd4d393b72c......................." 9 | 10 | client = Client(account_sid, auth_token) 11 | 12 | message = client.messages.create( 13 | to="+447438........", 14 | from_="+44124......", 15 | body="--new video received--") 16 | -------------------------------------------------------------------------------- /sync_using_dropbox_rpi.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | 3 | def sync_folder(): 4 | 5 | upload = "/home/pi/object_detection_cv2_tf_dn/Dropbox-uploader/dropbox_uploader.sh upload /home/pi/object_detection_cv2_tf_dn/dropbox_sync_folder_4_videos/ /" 6 | print('sync_dropbox_activated') 7 | subprocess.call ([upload], shell=True) 8 | print('sync_dropbox_finished') 9 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Video Streaming Demonstration 4 | 5 | 6 |

Video Streaming Demonstration

7 | 8 | 9 | --------------------------------------------------------------------------------