Skip to content

Commit

Permalink
Complete rewrite - reworked everything
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer2514 authored Jun 7, 2021
1 parent 77f86ea commit 4087bba
Showing 1 changed file with 194 additions and 63 deletions.
257 changes: 194 additions & 63 deletions installGoogleDrive.sh
Original file line number Diff line number Diff line change
@@ -1,86 +1,217 @@
#!/bin/bash

# Initialize the input variable
number="0"

# Print main menu
clear
echo Google Drive for Raspbian
echo -------------------------
echo Options:
echo 1. Install/Re-install Google Drive
echo 2. Uninstall Google Drive
echo 3. Add auto-mount
echo 4. Remove auto-mount
echo 5. Exit Installer
echo
echo 3. Mount Google Drive
echo 4. Unmount Google Drive
echo 5. Add auto-mount
echo 6. Remove auto-mount
echo 7. Exit Installer
echo

# Get user input
read -p "Input Number: " number

# If user inputs 1, install GDFS
if (( $number == "1" )); then
echo Initializing...
cd /home/pi
echo Cleaning up old assets...
sudo umount /mnt/gdrivefs
sudo rmdir /mnt/gdrivefs
sudo rm "/home/pi/Google Drive"
sudo rm /home/pi/.gdfs.creds
sudo sed -i '\|sudo gdfs -\o allow_other /home/pi/.gdfs.creds /mnt/gdrivefs|d' /etc/rc.local
echo Installing updates...
sudo apt-get install python3-pip
sudo pip3 install google-api-python-client -U
sudo pip3 install six -U
sudo pip3 install gdrivefs -U
sudo pip3 install oauth2client -U
echo Creating directories...
sudo mkdir /mnt/gdrivefs
echo Authorizing Google Drive...
authKey=""
echo Please follow the instructions to sign in to your Google Drive account:
sleep 1s
gdfstool auth_get_url
read -p "Authorization Key: " authKey
echo Authorizing...
gdfstool auth -a /home/pi/.gdfs.creds "$authKey"
echo Mounting drive files...
sudo gdfs -o allow_other /home/pi/.gdfs.creds /mnt/gdrivefs
ln -s "/mnt/gdrivefs" "/home/pi/Google Drive"
echo Listing files...
echo _______________________________
confirm="y"
ls "/home/pi/Google Drive"
read -p "Is this correct (Y/n)? " confirm
if (( $confirm == "y" || $confirm == "Y" )); then
read -p "Mount at system startup (Y/n)? " confirm
if (( $confirm == "y" || $confirm == "Y" )); then
sudo sed -i -e '$i \sudo gdfs -o allow_other /home/pi/.gdfs.creds /mnt/gdrivefs' /etc/rc.local
echo Installation successful...
read -p "Press enter to exit..."
fi
else
echo Installation failed!
read -p "Press enter to exit..."
fi

echo Initializing...

# Set active directory
cd /home/pi

echo Cleaning up old assets...

# Unmount & delete GDFS mount location if it exists
sudo umount /mnt/gdrivefs
sudo rmdir /mnt/gdrivefs
sudo rm /mnt/gdrivefs

# Delete Google Drive auth token if it exists
sudo rm /home/pi/.gdfs/creds

# Delete Google Drive symbolic link in home directory if it exists
sudo rm "/home/pi/Google Drive"

# Remove autostart entry if it exists
sudo rm /home/pi/.config/autostart/mountgdfs.desktop

echo Installing updates...

# Make sure pip3 is installed
sudo apt-get install python3-pip

# Install necessary python packages
sudo pip3 install google-api-python-client -U
sudo pip3 install gdrivefs -U

# Notify user of new auth window
echo Authorizing Google Drive...
echo A new browser window will open shortly
echo Please sign in to your Google account to authorize GDFS
echo After authorization is complete, close the browser window to continue

# Give user some time to read the message
sleep 3

# Open new browser window and get GDFS auth token
gdfstool auth_automatic

# Create GDFS mount location
echo Creating folders...
sudo mkdir /mnt/gdrivefs

# Allow GDFS to run without root
echo Modifying permissions...
sudo chmod 777 /mnt/gdrivefs

echo Mounting drive files...

# Mount GDFS
gdfs /home/pi/.gdfs/creds /mnt/gdrivefs

# Create symbolic link
ln -s "/mnt/gdrivefs" "/home/pi/Google Drive"

echo Listing files...
echo _______________________________

# Initialize confirmation variable
confirm="y"

# List files in drive
ls "/home/pi/Google Drive"

# Ask user for success confirmation
read -p "Is this correct (Y/n)? " confirm

# If user confirms, continue
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then

# Ask user for auto-mount confirmation
read -p "Mount on user login (Y/n)? " confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then

# Add autostart entry
echo "[Desktop Entry]
Type=Application
Exec=gdfs /home/pi/.gdfs/creds /mnt/gdrivefs
Name=Mount GDFS
Comment=Mounts Google Drive" >> /home/pi/.config/autostart/mountgdfs.desktop

# Exit script
echo Installation successful...
echo If no files show up in the Google Drive folder,
echo make sure to refresh the file manager by pressing Ctrl+R
read -p "Press enter to exit..."

fi

# If user declines, cancel
else

# Exit script
echo Installation failed!
read -p "Press enter to exit..."

fi

fi

# If user inputs 2, uninstall GDFS
if (( $number == "2" )); then
echo Uninstalling...
sudo umount /mnt/gdrivefs
sudo rmdir /mnt/gdrivefs
sudo rm "/home/pi/Google Drive"
sudo rm /home/pi/.gdfs.creds
sudo sed -i '\|sudo gdfs -\o allow_other /home/pi/.gdfs.creds /mnt/gdrivefs|d' /etc/rc.local
sudo pip3 uninstall gdrivefs
sudo pip3 uninstall oauth2client
echo Uninstallation successful!
read -p "Press enter to exit..."

echo Uninstalling...

# Unmount & delete GDFS mount location
sudo umount /mnt/gdrivefs
sudo rmdir /mnt/gdrivefs
sudo rm /mnt/gdrivefs

# Delete Google Drive auth token
sudo rm /home/pi/.gdfs/creds

# Delete Google Drive symbolic link in home directory
sudo rm "/home/pi/Google Drive"

# Remove autostart entry
sudo rm /home/pi/.config/autostart/mountgdfs.desktop

# Uninstall gdrivefs
sudo pip3 uninstall gdrivefs

# Exit script
echo Uninstallation successful!
read -p "Press enter to exit..."

fi

# If user inputs 3, mount GDFS
if (( $number == "3" )); then
sudo sed -i -e '$i \sudo gdfs -o allow_other /home/pi/.gdfs.creds /mnt/gdrivefs' /etc/rc.local
echo Auto-mount added!
read -p "Press enter to exit..."

# Mount GDFS
echo Mounting GDFS...
gdfs /home/pi/.gdfs/creds /mnt/gdrivefs

# Exit script
echo GDFS mounted!
read -p "Press enter to exit..."

fi

# If user inputs 4, unmount GDFS
if (( $number == "4" )); then
sudo sed -i '\|sudo gdfs -\o allow_other /home/pi/.gdfs.creds /mnt/gdrivefs|d' /etc/rc.local
echo Auto-mount removed!
read -p "Press enter to exit..."

# Unmount GDFS
echo Unmounting GDFS...
sudo umount /mnt/gdrivefs

# Exit script
echo GDFS unmounted!
read -p "Press enter to exit..."

fi

# If user inputs 5, make GDFS mount on startup
if (( $number == "5" )); then

# Remove autostart entry if it exists
sudo rm /home/pi/.config/autostart/mountgdfs.desktop

# Add new autostart entry
echo "[Desktop Entry]
Type=Application
Exec=gdfs /home/pi/.gdfs/creds /mnt/gdrivefs
Name=Mount GDFS
Comment=Mounts Google Drive" >> /home/pi/.config/autostart/mountgdfs.desktop

# Exit script
echo Auto-mount added!
read -p "Press enter to exit..."

fi

# If user inputs 6, make GDFS not mount on startup
if (( $number == "6" )); then

# Remove autostart entry
sudo rm /home/pi/.config/autostart/mountgdfs.desktop

# Exit script
echo Auto-mount removed!
read -p "Press enter to exit..."

fi

# Exit the installer
echo Goodbye!
sleep 1s
clear

0 comments on commit 4087bba

Please sign in to comment.