Skip to content

Instantly share code, notes, and snippets.

@benzBrake
Last active June 25, 2020 10:41
Show Gist options
  • Select an option

  • Save benzBrake/e2ea71d8dbe228e9521e30761f8abc77 to your computer and use it in GitHub Desktop.

Select an option

Save benzBrake/e2ea71d8dbe228e9521e30761f8abc77 to your computer and use it in GitHub Desktop.
onedrive personal mount shell
#!/bin/bash
# Ryan Lieu <github-benzbrake@woai.ru>
# 2018.06.27
# config start
CID=
USER=
PASSWD=
MOUNTPOINT=/mnt/onedrive
LOGDIR=/var/log/onedrive.log
# config end
# do not modify below
test -z ${LOGDIR} && LOGDIR=/var/log/onedrive.log
test -z ${CID} && echo "CID is not set!" >> ${LOGDIR}
test -z ${USER} && echo "USER is not set!" >> ${LOGDIR}
test -z ${MOUNTPOINT} && echo "MOUNTPOINT is not set!" >> ${LOGDIR}
ping -c1 www.baidu.com 2>&1 >> ${LOGDIR}
RTN=$?
COUNT=0
while (( ${RTN} > 0 ))
do
ping -c1 www.baidu.com 2>&1 >> ${LOGDIR}
RTN=$?
let COUNT=COUNT+1
sleep 5
if test ${COUNT} -gt 10;then
break
fi
done
INSTALLER=yum
! test -z $(command -v apt-get) && INSTALLER=apt-get
if test -z $(command -v expect); then
$INSTALLER -y install expect 2>&1 >> ${LOGDIR}
fi
if test -z $(command -v mount.davfs2); then
if [ $INSTALLER == 'yum' ]; then
$INSTALLER -y install epel-release 2>&1 >> ${LOGDIR}
fi
$INSTALLER -y install davfs2 2>&1 >> ${LOGDIR}
fi
expect <<EOF
spawn mount.davfs -o rw "https://d.docs.live.net/${CID}" ${MOUNTPOINT}
expect "Username: " {
send "$USER"
}
expect "Password: " {
send "$PASSWD"
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment