Guest User

sssssss

a guest
Sep 27th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #edit:
  4. USENOTIFYOSD=yes #yes or no to use NotifyOSD
  5. #--------------------------
  6.  
  7. #do not edit:
  8. if [[ -e ~/.dropbox/host.db ]]; then
  9. LOCATION="`cat ~/.dropbox/host.db | sed -n 2p | base64 -d`/Public/"
  10. else
  11. #thanks to this: http://forums.dropbox.com/topic.php?id=24265&replies=3#post-152444
  12. LOCATION="`sqlite3 ~/.dropbox/config.db "select * from config where key like '%path%'" | grep "dropbox_path|" | sed -e "s/dropbox\_path|//g"`/Public/"
  13. #<grep "dropbox_path|"> is used just in case
  14. fi
  15.  
  16. #check if Public folder exists:
  17. if [[ ! -e $LOCATION ]]; then
  18.  
  19. notify-send --icon="dropbox" "Error: Dropbox Share" "You don't seem to have a Public folder in your Dropbox directory. Please check your Dropbox folder (maybe you use selective sync?)."
  20. exit 0
  21.  
  22. fi
  23.  
  24.  
  25. #check if dropbox is running:
  26. if ps -e | grep dropbox; then
  27. return
  28. else
  29. if [ $USENOTIFYOSD = yes ]; then
  30. notify-send --icon="dropbox" "Dropbox is not running" "Starting Dropbox..."
  31. else
  32. return
  33. fi
  34. dropbox start
  35. sleep 15
  36. fi
  37.  
  38. #--------------------------
  39.  
  40. #-------------------------- remove emblems for files which have been manually removed from the Dropbox Public folder -------------
  41.  
  42. if [[ ! -e ~/.dropboxshare/history ]]; then
  43. mkdir -p ~/.dropboxshare
  44. touch ~/.dropboxshare/history
  45. fi
  46.  
  47. ISINHISTORY=$(cat ~/.dropboxshare/history | awk -F/ '{print $NF}')
  48. IFS=$'\n'
  49. for PUBLICFILE in $ISINHISTORY; do
  50. ISINDROPBOX=$(ls $LOCATION | grep "$PUBLICFILE")
  51. if [[ ! $ISINDROPBOX ]]; then
  52. REMOVEEMBLEM=$(cat ~/.dropboxshare/history | grep "$PUBLICFILE")
  53. gvfs-set-attribute "$REMOVEEMBLEM" -t unset metadata::emblems
  54.  
  55. if [ -d $REMOVEEMBLEM ]; then
  56. find "$REMOVEEMBLEM" -name 'dropbox-index.html' -exec rm {} \;
  57. fi
  58.  
  59. FORMATFORSEDREMOVEEMBLEM=$(echo $REMOVEEMBLEM | sed -e 's/\//\\\//g')
  60. sed -i "/$FORMATFORSEDREMOVEEMBLEM/d" ~/.dropboxshare/history
  61. else
  62. return
  63. fi
  64. done
  65.  
  66. #------------------------------------------------------------------------------------------------------
  67.  
  68.  
  69. #setting the file emblems needs to be done immediately after the user shares them, or else Nautilus is not refreshed and the emblems do not show up. For this reason, we'll have the "for" loop twice: once for the emblems metadata and a second time for actually sharing the folders and copying the URLs to the clipboad:
  70.  
  71. IFS=$'\n'
  72. for FILENAME in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
  73. do
  74. echo "$FILENAME" >> ~/.dropboxshare/history
  75. #create emblem for the shared files:
  76. gvfs-set-attribute "$FILENAME" -t stringv metadata::emblems dropbox
  77.  
  78. done
  79. #refresh Nautilus. It's a hack, but there is no other way of doing this (really!):
  80. xte 'keydown Control_L' 'key R' 'keyup Control_L'
  81. #xsendkeycode 71 1
  82. #xsendkeycode 71 0
  83.  
  84. if [ $USENOTIFYOSD = yes ]; then
  85. notify-send --icon="dropbox" "Dropbox Share - Uploading" "Please wait while Dropbox uploads your shared files"
  86. else
  87. return
  88. fi
  89.  
  90.  
  91. #ok, now the emblems should be ok, we can start uploading the files to dropbox (creating the symbolic links and copying the public URLs to the clipboard):
  92.  
  93. IFS=$'\n'
  94. for FILENAME in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
  95. do
  96.  
  97. DROPBOXFILE=`echo $FILENAME | awk -F/ '{print $NF}'`
  98. if [ -f $FILENAME ]; then #files
  99.  
  100.  
  101. ln -s "$FILENAME" "$LOCATION"
  102.  
  103. #copy the links to the clipboard:
  104. list="$list `dropbox puburl "$LOCATION"/"$DROPBOXFILE"`"
  105. echo -n $list > ~/.dropboxshare/lasturl
  106. echo -n $list | xclip -selection clipboard
  107.  
  108.  
  109. elif [ -d $FILENAME ]; then #folders
  110.  
  111.  
  112. DROPBOXFILE=`echo $FILENAME | awk -F/ '{print $NF}'`
  113. ln -s "$FILENAME" "$LOCATION"
  114.  
  115. /usr/bin/dropbox-index -R "$LOCATION"/"$DROPBOXFILE" #write dropbox-index.html for each folder we shared (recursively)
  116.  
  117. #copy the links to the clipboard:
  118. list="$list `dropbox puburl "$LOCATION"/"$DROPBOXFILE"`/dropbox-index.html"
  119. echo -n $list > ~/.dropboxshare/lasturl
  120. echo -n $list | xclip -selection clipboard
  121.  
  122. else #something is wrong
  123. return
  124. # notify-send "Something doesnt work" "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" #debugging
  125. fi
  126.  
  127. done
  128.  
  129.  
  130.  
  131. #find out when Dropbox finishes to upload our files; we don't care about the overall Dropbox status, only about our files status. If this part would have been 6 lines upper in the script, it would have been shorter, but each uploaded file would have been in the loop which checks the file status and that slows down the process, especially when uploading many folders.
  132. IFS=$'\n'
  133. for FILENAME in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
  134. do
  135. DROPBOXFILE=`echo $FILENAME | awk -F/ '{print $NF}'`
  136. DROPSTATUS=$(dropbox filestatus "$LOCATION"/"$DROPBOXFILE" | awk -F: '{print $NF}')
  137. while [ $DROPSTATUS = " syncing" ]; do
  138. sleep 5
  139. DROPSTATUS=$(dropbox filestatus "$LOCATION"/"$DROPBOXFILE" | awk -F: '{print $NF}')
  140. done
  141. done
  142. if [ $USENOTIFYOSD = yes ]; then
  143. notify-send --icon="dropbox" "Dropbox Share - DONE!" "Check your clipboard (Ctrl + V)"
  144. exit
  145. else
  146. exit
  147. fi
  148.  
  149.  
Add Comment
Please, Sign In to add comment