From f84f970a9d7fc64bf554b0daeca03e17a5f0bb6d Mon Sep 17 00:00:00 2001 From: Locutus73 Date: Sat, 2 Feb 2019 18:29:08 +0100 Subject: [PATCH] Version 1.0 --- gdrive.sh.inc | 96 ++++++++++++++++++++++++++++++++++++++++ gdrive_saves_download.sh | 31 +++++++++++++ gdrive_saves_upload.sh | 31 +++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 gdrive.sh.inc create mode 100644 gdrive_saves_download.sh create mode 100644 gdrive_saves_upload.sh diff --git a/gdrive.sh.inc b/gdrive.sh.inc new file mode 100644 index 0000000..a05491e --- /dev/null +++ b/gdrive.sh.inc @@ -0,0 +1,96 @@ +# 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 3 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, see . + +# Copyright 2019 Alessandro "Locutus73" Miele + +# You can download the latest version of this script from: +# https://github.com/MiSTer-devel/Scripts_MiSTer + +# Version 1.0 - 2019-02-02 - First commit + + + +if [ ! -f /media/fat/linux/$GDRIVE_COMMAND ] +then + echo "Downloading $GDRIVE_COMMAND" + RELEASES_PAGE="$(curl -sLf $GDRIVE_URL/releases)" + case $? in + 0) + RELEASE_URLS=$(echo "$RELEASES_PAGE" | grep -o "href=[\"\'][^\"\']*drive_armv7[\"\']" | sed "s/href=//g" | sed "s/[\"\']//g") + MAX_VERSION="" + MAX_RELEASE_URL="" + for RELEASE_URL in $RELEASE_URLS + do + CURRENT_VERSION=$(echo "$RELEASE_URL" | grep -o '/v[0-9]*\.[0-9]*\.[0-9]*/') + if [[ "$CURRENT_VERSION" > "$MAX_VERSION" ]] + then + MAX_VERSION=$CURRENT_VERSION + MAX_RELEASE_URL=$RELEASE_URL + fi + done + curl -L "https://github.com$MAX_RELEASE_URL" -o "/media/fat/linux/$GDRIVE_COMMAND" + ;; + 60) + echo "CA certificates need" + echo "to be fixed for" + echo "using $GDRIVE_COMMAND." + echo "Please fix them i.e." + echo "using security_fixes.sh" + exit 2 + ;; + *) + echo "No Internet connection." + exit 1 + ;; + esac +fi + +if [ ! -f "$BASE_PATH/.gd/credentials.json" ] +then + if [ "$SSH_CLIENT" == "" ] + then + echo "This script must be run" + echo "from a SSH terminal" + echo "once for performing" + echo "Google Drive" + echo "authentication." + exit 3 + fi + if ! /media/fat/linux/$GDRIVE_COMMAND init "$BASE_PATH" + then + echo "Google Drive authentication failed." + curl -q https://google.com &>/dev/null + case $? in + 0) + exit 3 + ;; + 60) + echo "CA certificates need" + echo "to be fixed for" + echo "using $GDRIVE_COMMAND." + echo "Please fix them i.e." + echo "using security_fixes.sh" + exit 2 + ;; + *) + echo "No Internet connection" + exit 1 + ;; + esac + fi +fi + +/media/fat/linux/$GDRIVE_COMMAND $GDRIVE_OPTIONS "$SYNC_PATH" + +echo "Done!" +exit 0 \ No newline at end of file diff --git a/gdrive_saves_download.sh b/gdrive_saves_download.sh new file mode 100644 index 0000000..2b1a128 --- /dev/null +++ b/gdrive_saves_download.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# 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 3 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, see . + +# Copyright 2019 Alessandro "Locutus73" Miele + +# You can download the latest version of this script from: +# https://github.com/MiSTer-devel/Scripts_MiSTer + +# Version 1.0 - 2019-02-02 - First commit + + + +GDRIVE_URL="https://github.com/odeke-em/drive" +GDRIVE_COMMAND="gdrive" +GDRIVE_OPTIONS="pull -exclude-ops delete -ignore-conflict -no-prompt" +BASE_PATH="/media/fat" +SYNC_PATH="$BASE_PATH/saves" + +source "$(dirname $(readlink -f $0))/gdrive.sh.inc" \ No newline at end of file diff --git a/gdrive_saves_upload.sh b/gdrive_saves_upload.sh new file mode 100644 index 0000000..cd152fe --- /dev/null +++ b/gdrive_saves_upload.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# 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 3 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, see . + +# Copyright 2019 Alessandro "Locutus73" Miele + +# You can download the latest version of this script from: +# https://github.com/MiSTer-devel/Scripts_MiSTer + +# Version 1.0 - 2019-02-02 - First commit + + + +GDRIVE_URL="https://github.com/odeke-em/drive" +GDRIVE_COMMAND="gdrive" +GDRIVE_OPTIONS="push -exclude-ops delete -ignore-conflict -no-prompt" +BASE_PATH="/media/fat" +SYNC_PATH="$BASE_PATH/saves" + +source "$(dirname $(readlink -f $0))/gdrive.sh.inc" \ No newline at end of file