Hello 😉
avant la sortie du client officiel, voici (en libre) un script bash qui crée un point de montage sur hubic (le service de stockage online d'OVH, cf
www.ovh.fr/hubiC/)
wget http://ubunt.u.free.fr/hubicmount
chmod ugo+rx hubicmount
sudo mv hubicmount /usr/bin
ce script requiert l'installation de wdfs (monte des filesystem webdav en userspace, c'est à dire sans besoin de root 😉)
wget http://ubunt.u.free.fr/installwdfs.sh
chmod u+x installwdfs.sh
sudo ./installwdfs.sh
Voici l'utilisation
./hubicmount -l <email> -p <passwd> -o umask=022 -o uid=1000 $HOME/hubic
et pour démonter:
fusermount -u $HOME/hubic
(NB : remplacer $HOME/hubic par votre point de montage)
comme il n'a pas besoin de root, on peut monter son disque hubic via le crontab de l'utilisateur et faire des rsync dessus pour gérer soi meme les sauvegardes 😃
#!/bin/bash
# Name : hubicmount
# Copyright (C) 2012 cosmobob
# from http://www.protocol-hacking.org/post/2012/01/29/Hubic%2C-maintenant-vraiment-ubiquitous
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
MAIN_HOST="https://ws.ovh.com"
HOST_NAS_LOGIN="$MAIN_HOST/cloudnas/r0/ws.dispatcher/nasLogin"
HOST_GET_NAS="$MAIN_HOST/cloudnas/r0/ws.dispatcher/getNas"
HOST_GET_CREDENTIALS="$MAIN_HOST/cloudnas/r0/ws.dispatcher/getCredentials"
HUBIC_LOGIN=""
HUBIC_PASSWORD=""
MOUNTPOINT=""
WDFS_OPTS=()
VERBOSE="False"
DEBUG="False"
EXEC=$(basename "$0")
DEPENDENCIES=('wdfs' 'fusermount')
check_dependencies()
{
for package in "${DEPENDENCIES[@]}" ; do
VAL=$(whereis "$package" | awk ' $2!="" { print $2 }')
if [ "x$VAL" == "x" ]; then
echo "Missing dependency : $package"
echo "Install package $package before using $EXEC"
fi
done
}
trace_debug()
{
if [ "x$DEBUG" == "xTrue" ] ; then
echo "$1" 1>&2
fi
}
function urlencode()
{
EncodeEOL="no"
echo "$@" | awk '
BEGIN {
EOL = "%0A" # "end of line" string (encoded)
split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ")
hextab [0] = 0
for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0
if ("'"$EncodeEOL"'" == "yes") EncodeEOL = 1; else EncodeEOL = 0
}
{
encoded = ""
for ( i=1; i<=length ($0); ++i ) {
c = substr ($0, i, 1)
if ( c ~ /[a-zA-Z0-9.-]/ ) {
encoded = encoded c # safe character
} else if ( c == " " ) {
encoded = encoded "+" # special handling
} else {
# unsafe character, encode it as a two-digit hex-number
lo = ord [c] % 16
hi = int (ord [c] / 16);
encoded = encoded "%" hextab [hi] hextab [lo]
}
}
if ( EncodeEOL ) {
printf ("%s", encoded EOL)
} else {
print encoded
}
}
END {
#if ( EncodeEOL ) print ""
}
'
}
function myparse()
{
echo "$@" | awk -F "," '
BEGIN {
val=0
}
{
OFS="\t"
for (i=1; i<=NF; i++)
{
buffer=""
for ( j=1; j<=length ($i); ++j )
{
c = substr ($i, j, 1)
if ( c == "{" )
{
if ( length(buffer) > 0 ) {
print val, buffer
}
val=val+1
buffer=""
}
else if ( c == "}" )
{
if ( length(buffer) > 0 ) {
print val, buffer
}
val=val-1
buffer=""
}
else
{
buffer=buffer c
}
}
if ( length(buffer) > 0 ) {
print val, buffer
}
}
}
' | sed 's/\":/\t/g;s/\"//g'
}
# 1 host
# 2 login
# 3 password
function postNasLogin()
{
DATA="session=¶ms={\"email\":\"""$(urlencode $2)""\",\"password\":\"""$(urlencode $3)""\"}"
trace_debug "$DATA"
RET=$(wget -q -O - --header "Content-type: application/x-www-form-urlencoded" --post-data=$DATA $1)
trace_debug "$RET"
myparse "$RET" | awk -F "\t" '
BEGIN {
last_1=""
}
$1==1 { last_1=$2 }
last_1=="answer" && $1==2 && $2=="id" { print $3 }
'
}
# 1 host
# 2 id
function postGetNas()
{
DATA="session=""$2"
trace_debug "$DATA"
RET=$(wget -q -O - --header "Content-type: application/x-www-form-urlencoded" --post-data=$DATA $1)
trace_debug "$RET"
myparse "$RET" | awk -F "\t" '
BEGIN {
last_1=""
}
$1==1 { last_1=$2 }
last_1=="answer" && $1==2 && $2=="url" { print $3 }
'
}
# 1 host
# 2 id
function postGetCredentials()
{
DATA="session=""$2"
trace_debug "$DATA"
RET=$(wget -q -O - --header "Content-type: application/x-www-form-urlencoded" --post-data=$DATA $1)
trace_debug "$RET"
myparse "$RET" | awk -F "\t" '
BEGIN {
last_1=""
}
$1==1 { last_1=$2 }
last_1=="answer" && $1==2 && ( $2=="secret" || $2=="username" ) { OFS="\t" ; print $2, $3 }
'
}
usage()
{
cat << EOF
usage: $EXEC [options] mountpoint
ex: $EXEC -l login -p password /mnt/hubic
REQUIRED OPTIONS:
-l Hubic login email
-p Hubic password
OTHER OPTIONS:
-h Show this message
-o Option to pass to wdfs (ex: -o umask=022)
-v Verbose mode
NOTE:
Please use fusermount -u mountpoint to unmount.
EOF
}
# 1 username
# 2 password
# 3 url
# Ok if there are spaces in mountpoint ;)
function create_commandline()
{
WDFS_OPTS=("-o" "username=$1" "-o" "password=$2" "${WDFS_OPTS[@]}" "$3" "$MOUNTPOINT")
First="True"
for val in "${WDFS_OPTS[@]}" ; do
if [ "x$First" == "xTrue" ] ; then
printf "%s" $val
First="False"
else
printf "\0%s" $val
fi
done;
}
##################################################################################################################################
##################################################################################################################################
##################################################################################################################################
##################################################################################################################################
RET=$(check_dependencies)
if [ "x$RET" != "x" ]; then
echo "$RET"
exit
fi
SHOW_USAGE="False"
while getopts "l:p:o:hv" OPTION
do
case "$OPTION" in
h)
SHOW_USAGE="True"
;;
l)
HUBIC_LOGIN=$OPTARG
;;
p)
HUBIC_PASSWORD=$OPTARG
;;
v)
VERBOSE="True"
;;
o)
WDFS_OPTS=("${WDFS_OPTS[@]}" '-o' "$OPTARG")
;;
esac
done
MOUNTPOINT="${!OPTIND}"
if [ "x$SHOW_USAGE" == "xTrue" ] ; then
usage
exit
elif [ "x$HUBIC_LOGIN" == "x" -o "x$HUBIC_PASSWORD" == "x" ]; then
echo "Missing login or password."
usage
exit
elif [ "x$MOUNTPOINT" == "x" ]; then
echo "Missing mountpoint."
usage
exit
fi
SESSION_ID=$(postNasLogin $HOST_NAS_LOGIN $HUBIC_LOGIN $HUBIC_PASSWORD)
trace_debug "session_id: $SESSION_ID"
if [ "x$SESSION_ID" != "x" ] ; then
URL_RET=$(postGetNas $HOST_GET_NAS $SESSION_ID)
CREDENTIALS=$(postGetCredentials $HOST_GET_CREDENTIALS $SESSION_ID)
trace_debug "credentials"
trace_debug "$CREDENTIALS"
USERNAME=$(echo "$CREDENTIALS" | awk -F "\t" ' $1=="username" { print $2 }')
PASSWORD=$(echo "$CREDENTIALS" | awk -F "\t" ' $1=="secret" { print $2 }')
if [ "x$VERBOSE" == "xTrue" ]; then
echo -n "wdfs "
create_commandline $USERNAME $PASSWORD $URL_RET | xargs -0 -n1 -I {} echo -n {}" "
echo
fi
create_commandline $USERNAME $PASSWORD $URL_RET | xargs -0 wdfs
else
echo "Unable to login to hubic" 1>&2
fi