|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Initialize the input variable |
| 4 | +number="0" |
| 5 | + |
| 6 | +# Print main menu |
| 7 | +clear |
| 8 | +echo Google Drive for Raspbian |
| 9 | +echo ------------------------- |
| 10 | +echo Options: |
| 11 | +echo 1. Install/Re-install Google Drive |
| 12 | +echo 2. Uninstall Google Drive |
| 13 | +echo 3. Mount Google Drive |
| 14 | +echo 4. Unmount Google Drive |
| 15 | +echo 5. Add auto-mount |
| 16 | +echo 6. Remove auto-mount |
| 17 | +echo 7. Exit Installer |
| 18 | +echo |
| 19 | + |
| 20 | +# Get user input |
| 21 | +read -p "Input Number: " number |
| 22 | + |
| 23 | +# If user inputs 1, install GDFS |
| 24 | +if (( $number == "1" )); then |
| 25 | + |
| 26 | + echo Initializing... |
| 27 | + |
| 28 | + # Set active directory |
| 29 | + cd /home/pi |
| 30 | + |
| 31 | + echo Cleaning up old assets... |
| 32 | + |
| 33 | + # Unmount & delete GDFS mount location if it exists |
| 34 | + sudo umount /mnt/gdrivefs |
| 35 | + sudo rmdir /mnt/gdrivefs |
| 36 | + sudo rm /mnt/gdrivefs |
| 37 | + |
| 38 | + # Delete Google Drive auth token if it exists |
| 39 | + sudo rm /home/pi/.gdfs/creds |
| 40 | + |
| 41 | + # Delete Google Drive symbolic link in home directory if it exists |
| 42 | + sudo rm "/home/pi/Google Drive" |
| 43 | + |
| 44 | + # Remove autostart entry if it exists |
| 45 | + sudo rm /etc/profile.d/mount-gdfs.sh |
| 46 | + |
| 47 | + echo Installing updates... |
| 48 | + |
| 49 | + # Make sure pip3 is installed |
| 50 | + sudo apt-get install python3-pip |
| 51 | + |
| 52 | + # Install necessary python packages |
| 53 | + sudo pip3 install google-api-python-client -U |
| 54 | + sudo pip3 install gdrivefs -U |
| 55 | + |
| 56 | + # Notify user of new auth window |
| 57 | + echo Authorizing Google Drive... |
| 58 | + echo Please follow the instructions to sign in to your Google Drive account: |
| 59 | + |
| 60 | + # Give user some time to read the message |
| 61 | + sleep 3 |
| 62 | + |
| 63 | + # Initialise authKey variable |
| 64 | + authKey="" |
| 65 | + |
| 66 | + # Get GDFS auth token link |
| 67 | + gdfstool auth_get_url |
| 68 | + |
| 69 | + # Ask user to input authorization key |
| 70 | + echo Please input the authorization key retrieved from the above link |
| 71 | + read -p "Authorization Key: " authKey |
| 72 | + |
| 73 | + # Record authKey |
| 74 | + echo Authorizing... |
| 75 | + gdfstool auth_write "$authKey" |
| 76 | + |
| 77 | + # Create GDFS mount location |
| 78 | + echo Creating folders... |
| 79 | + sudo mkdir /mnt/gdrivefs |
| 80 | + |
| 81 | + # Allow GDFS to run without root |
| 82 | + echo Modifying permissions... |
| 83 | + sudo chmod 777 /mnt/gdrivefs |
| 84 | + |
| 85 | + echo Mounting drive files... |
| 86 | + |
| 87 | + # Mount GDFS |
| 88 | + gdfs /home/pi/.gdfs/creds /mnt/gdrivefs |
| 89 | + |
| 90 | + # Create symbolic link |
| 91 | + ln -s "/mnt/gdrivefs" "/home/pi/Google Drive" |
| 92 | + |
| 93 | + echo Listing files... |
| 94 | + echo _______________________________ |
| 95 | + |
| 96 | + # Initialize confirmation variable |
| 97 | + confirm="y" |
| 98 | + |
| 99 | + # List files in drive |
| 100 | + ls "/home/pi/Google Drive" |
| 101 | + |
| 102 | + # Ask user for success confirmation |
| 103 | + read -p "Is this correct (Y/n)? " confirm |
| 104 | + |
| 105 | + # If user confirms, continue |
| 106 | + if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then |
| 107 | + |
| 108 | + # Ask user for auto-mount confirmation |
| 109 | + read -p "Mount on user login (Y/n)? " confirm |
| 110 | + if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then |
| 111 | + |
| 112 | + # Add autostart entry |
| 113 | + sudo sh -c 'echo "#!/bin/sh |
| 114 | +gdfs /home/pi/.gdfs/creds /mnt/gdrivefs" >> /etc/profile.d/mount-gdfs.sh' |
| 115 | + |
| 116 | + # Make autostart entry executable |
| 117 | + sudo chmod +x /etc/profile.d/mount-gdfs.sh |
| 118 | + |
| 119 | + # Exit script |
| 120 | + echo Installation successful... |
| 121 | + echo If no files show up in the Google Drive folder, |
| 122 | + echo make sure to refresh the file manager by pressing Ctrl+R |
| 123 | + read -p "Press enter to exit..." |
| 124 | + |
| 125 | + fi |
| 126 | + |
| 127 | + # If user declines, cancel |
| 128 | + else |
| 129 | + |
| 130 | + # Exit script |
| 131 | + echo Installation failed! |
| 132 | + read -p "Press enter to exit..." |
| 133 | + |
| 134 | + fi |
| 135 | + |
| 136 | +fi |
| 137 | + |
| 138 | +# If user inputs 2, uninstall GDFS |
| 139 | +if (( $number == "2" )); then |
| 140 | + |
| 141 | + echo Uninstalling... |
| 142 | + |
| 143 | + # Unmount & delete GDFS mount location |
| 144 | + sudo umount /mnt/gdrivefs |
| 145 | + sudo rmdir /mnt/gdrivefs |
| 146 | + sudo rm /mnt/gdrivefs |
| 147 | + |
| 148 | + # Delete Google Drive auth token |
| 149 | + sudo rm /home/pi/.gdfs/creds |
| 150 | + |
| 151 | + # Delete Google Drive symbolic link in home directory |
| 152 | + sudo rm "/home/pi/Google Drive" |
| 153 | + |
| 154 | + # Remove autostart entry |
| 155 | + sudo rm /etc/profile.d/mount-gdfs.sh |
| 156 | + |
| 157 | + # Uninstall gdrivefs |
| 158 | + sudo pip3 uninstall gdrivefs |
| 159 | + |
| 160 | + # Exit script |
| 161 | + echo Uninstallation successful! |
| 162 | + read -p "Press enter to exit..." |
| 163 | + |
| 164 | +fi |
| 165 | + |
| 166 | +# If user inputs 3, mount GDFS |
| 167 | +if (( $number == "3" )); then |
| 168 | + |
| 169 | + # Mount GDFS |
| 170 | + echo Mounting GDFS... |
| 171 | + gdfs /home/pi/.gdfs/creds /mnt/gdrivefs |
| 172 | + |
| 173 | + # Exit script |
| 174 | + echo GDFS mounted! |
| 175 | + read -p "Press enter to exit..." |
| 176 | + |
| 177 | +fi |
| 178 | + |
| 179 | +# If user inputs 4, unmount GDFS |
| 180 | +if (( $number == "4" )); then |
| 181 | + |
| 182 | + # Unmount GDFS |
| 183 | + echo Unmounting GDFS... |
| 184 | + sudo umount /mnt/gdrivefs |
| 185 | + |
| 186 | + # Exit script |
| 187 | + echo GDFS unmounted! |
| 188 | + read -p "Press enter to exit..." |
| 189 | + |
| 190 | +fi |
| 191 | + |
| 192 | +# If user inputs 5, make GDFS mount on startup |
| 193 | +if (( $number == "5" )); then |
| 194 | + |
| 195 | + # Remove autostart entry if it exists |
| 196 | + sudo rm /etc/profile.d/mount-gdfs.sh |
| 197 | + |
| 198 | + # Add new autostart entry |
| 199 | + sudo sh -c 'echo "#!/bin/sh |
| 200 | +gdfs /home/pi/.gdfs/creds /mnt/gdrivefs" >> /etc/profile.d/mount-gdfs.sh' |
| 201 | + |
| 202 | + # Make autostart entry executable |
| 203 | + sudo chmod +x /etc/profile.d/mount-gdfs.sh |
| 204 | + |
| 205 | + # Exit script |
| 206 | + echo Auto-mount added! |
| 207 | + read -p "Press enter to exit..." |
| 208 | + |
| 209 | +fi |
| 210 | + |
| 211 | +# If user inputs 6, make GDFS not mount on startup |
| 212 | +if (( $number == "6" )); then |
| 213 | + |
| 214 | + # Remove autostart entry |
| 215 | + sudo rm /etc/profile.d/mount-gdfs.sh |
| 216 | + |
| 217 | + # Exit script |
| 218 | + echo Auto-mount removed! |
| 219 | + read -p "Press enter to exit..." |
| 220 | + |
| 221 | +fi |
| 222 | + |
| 223 | +# Exit the installer |
| 224 | +echo Goodbye! |
| 225 | +sleep 1s |
| 226 | +clear |
0 commit comments