|
12 | 12 | executable = true; |
13 | 13 | text = '' |
14 | 14 | #!/bin/bash |
15 | | - |
| 15 | +
|
| 16 | + # Backup existing config if present |
| 17 | + if [ -f "$HOME/.config/rclone/rclone.conf" ]; then |
| 18 | + cp "$HOME/.config/rclone/rclone.conf" "$HOME/.config/rclone/rclone.conf.backup-$(date +%Y%m%d%H%M%S)" |
| 19 | + fi |
| 20 | +
|
| 21 | + # Check if rclone configuration exists |
| 22 | + if [ ! -f "$HOME/.config/rclone/rclone.conf" ]; then |
| 23 | + echo "Error: No rclone configuration found at $HOME/.config/rclone/rclone.conf" |
| 24 | + echo "Please run 'rclone config' to set up your Google Drive remote before mounting." |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | +
|
| 28 | + # Check if gdrive remote exists |
| 29 | + if ! rclone listremotes | grep -q "^gdrive:$"; then |
| 30 | + echo "Error: No 'gdrive:' remote found in rclone configuration." |
| 31 | + echo "Please run 'rclone config' to set up your Google Drive remote before mounting." |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | +
|
16 | 35 | # Stop any existing rclone processes |
17 | 36 | pkill -f "rclone mount gdrive:" 2>/dev/null || true |
18 | | - |
| 37 | +
|
19 | 38 | # Create mount directory in /vagrant |
20 | 39 | mkdir -p $HOME/google-drive |
21 | | - |
| 40 | +
|
22 | 41 | # Create a local cache directory for better performance |
23 | 42 | mkdir -p $HOME/.cache/rclone |
24 | | - |
| 43 | +
|
25 | 44 | # Mount with highly optimized settings for better performance |
26 | 45 | rclone mount gdrive: $HOME/google-drive \ |
27 | 46 | --daemon \ |
|
49 | 68 | --stats 0 \ |
50 | 69 | --log-level INFO \ |
51 | 70 | --log-file=$HOME/rclone-gdrive.log |
52 | | - |
| 71 | +
|
53 | 72 | echo "Google Drive mounted at $HOME/google-drive with optimized settings" |
54 | 73 | ''; |
55 | 74 | }; |
|
68 | 87 | ExecStop = "${config.home.homeDirectory}/.bin/unmount-gdrive"; |
69 | 88 | Restart = "on-failure"; |
70 | 89 | RestartSec = "30s"; |
71 | | - Environment = [ |
72 | | - "PATH=${lib.makeBinPath [pkgs.rclone pkgs.fuse pkgs.coreutils]}" |
73 | | - ]; |
| 90 | + Environment = |
| 91 | + [ "PATH=${lib.makeBinPath [ pkgs.rclone pkgs.fuse pkgs.coreutils ]}" ]; |
74 | 92 | }; |
75 | 93 |
|
76 | | - Install = { |
77 | | - WantedBy = ["default.target"]; |
78 | | - }; |
| 94 | + Install = { WantedBy = [ "default.target" ]; }; |
79 | 95 | }; |
80 | 96 |
|
81 | 97 | # Create unmount script |
82 | 98 | home.file.".bin/unmount-gdrive" = { |
83 | 99 | executable = true; |
84 | 100 | text = '' |
85 | 101 | #!/bin/bash |
86 | | - |
| 102 | +
|
87 | 103 | # Unmount Google Drive (from home directory) |
88 | 104 | fusermount -u $HOME/google-drive |
89 | | - |
| 105 | +
|
90 | 106 | echo "Google Drive unmounted" |
91 | 107 | ''; |
92 | 108 | }; |
|
96 | 112 | executable = true; |
97 | 113 | text = '' |
98 | 114 | #!/bin/bash |
99 | | - |
100 | | - if pgrep -f "rclone mount gdrive:" > /dev/null; then |
| 115 | +
|
| 116 | + # First check the mount point directly - most reliable method |
| 117 | + if mountpoint -q "$HOME/google-drive" 2>/dev/null; then |
101 | 118 | echo "✅ Google Drive is mounted at $HOME/google-drive" |
102 | 119 | echo "Cache directory: $HOME/.cache/rclone" |
103 | 120 | echo "Log file: $HOME/rclone-gdrive.log" |
104 | 121 | |
105 | | - # Mount status |
106 | | - mountpoint -q $HOME/google-drive && echo "✅ Mount point verified" || echo "❌ Mount point not active" |
107 | | - |
108 | 122 | # Check disk usage of cache |
109 | 123 | echo -e "\nCache usage:" |
110 | 124 | du -sh $HOME/.cache/rclone 2>/dev/null || echo "Cache not yet created" |
|
113 | 127 | echo -e "\nRecent log entries:" |
114 | 128 | tail -n 5 $HOME/rclone-gdrive.log 2>/dev/null || echo "No log entries yet" |
115 | 129 | else |
116 | | - echo "❌ Google Drive is not mounted" |
| 130 | + # Try several methods to detect the rclone process |
| 131 | + if ps aux | grep -v grep | grep -q "[r]clone.*gdrive:"; then |
| 132 | + echo "⚠️ Rclone process found but mount point is not active" |
| 133 | + else |
| 134 | + echo "❌ Google Drive is not mounted" |
| 135 | + echo "No rclone process for gdrive found" |
| 136 | + fi |
| 137 | + |
| 138 | + # Check if mount directory exists |
| 139 | + if [ ! -d "$HOME/google-drive" ]; then |
| 140 | + echo "Mount directory does not exist. Run mount-gdrive to create and mount it." |
| 141 | + fi |
117 | 142 | fi |
118 | 143 | ''; |
119 | 144 | }; |
120 | 145 |
|
121 | 146 | # Add zsh aliases for easy mounting/unmounting |
122 | 147 | programs.zsh.shellAliases = { |
123 | | - "mount-gdrive" = "$HOME/.bin/mount-gdrive"; |
124 | | - "unmount-gdrive" = "$HOME/.bin/unmount-gdrive"; |
| 148 | + "gdrive-mount" = "$HOME/.bin/mount-gdrive"; |
| 149 | + "gdrive-unmount" = "$HOME/.bin/unmount-gdrive"; |
125 | 150 | "gdrive-status" = "$HOME/.bin/gdrive-status"; |
126 | 151 | }; |
127 | 152 | } |
0 commit comments