Skip to content

Instantly share code, notes, and snippets.

@ricardopedias
Last active March 13, 2021 17:38
Show Gist options
  • Save ricardopedias/376355015b19dd0fb2bf770a8ba5ec67 to your computer and use it in GitHub Desktop.
Save ricardopedias/376355015b19dd0fb2bf770a8ba5ec67 to your computer and use it in GitHub Desktop.
Montar GoogleDrive
#!/bin/bash
#
# Site: https://gist.github.com/ricardopedias/376355015b19dd0fb2bf770a8ba5ec67
# Autor: Ricardo Pereira Dias
# Para instalar o rclone: apt install rclone
# Para configurar o rclone: https://rclone.org/drive/
#
# ----------------------------------------------------------------------------------
# Este programa monta e desmonta o diretório do GoogleDrive.
# Para funcionar, é preciso executar antes o comando "rclone config".
#
HOWTO="
Uso: $(basename "$0") [OPÇÕES] [diretório]
OPÇÕES:
-u, --umount Desmonta um diretório montado
-h, --help Mostra a tela de ajuda e sai
EXEMPLOS:
$ google-drive ~/Documentos/GoogleDrive
Monta o drive no diretório especificado
$ google-drive ~/Documentos
Gera automaticamente o diretório ~/Documentos/GoogleDrive e monta o drive
"
UMOUNT="0"
DIR=$(pwd)
DEFAULT="\033[0m"
RED="\033[0;31m"
GREEN="\033[0;32m"
BLUE="\033[0;34m"
RED_LIGHT="\033[1;31m"
GREEN_LIGHT="\033[1;32m"
BLUE_LIGHT="\033[1;34m"
while test -n "$1"
do
case "$1" in
-u | --umount )
UMOUNT=1
;;
-h | --help)
echo "$HOWTO"
exit 0
;;
*)
if [ ! -d "$1" ]
then
echo "Opção inválida: $1"
exit 1
fi
;;
esac
OPTION_DIR=${@%/}
if [ -d "$OPTION_DIR" ]
then
DIR="$OPTION_DIR"
fi
# a opção atual já foi processada, pula para a próxima
shift
done
DRIVE_DIR="$DIR/GoogleDrive"
if [ ! -d "$DRIVE_DIR" ]
then
mkdir "$DRIVE_DIR"
echo -e "${GREEN_LIGHT}Criado diretório $DRIVE_DIR ${DEFAULT}"
fi
# Montagem
if [ "$UMOUNT" == "0" ]
then
rclone mount --daemon GoogleDrive: $DRIVE_DIR
echo -e "${GREEN_LIGHT}Google Drive montado em $DRIVE_DIR ${DEFAULT}"
exit 0;
fi
# Desmontagem
fusermount -uz $DRIVE_DIR 1>/dev/null 2>/dev/null
if [ "$(ls -A $DRIVE_DIR)" ]
then
echo -e "${RED_LIGHT}Não foi possível desmontar o Google Drive de $DRIVE_DIR ${DEFAULT}"
exit 0
fi
echo -e "${GREEN_LIGHT}Google Drive desmontado com sucesso ${DEFAULT}"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment