aboutsummaryrefslogtreecommitdiff
path: root/bin/mount_dev
blob: cba8c82b09a1a112020e3a2a554ccdd5708d1c5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh

DIR="/usr/local/Development/$2"
tput setaf 4
echo "Mounting \"$1:$DIR\" to \"$DIR\"."
tput sgr0

if [ ! -d "$DIR" ]; then
  tput setaf 3
  echo "Directory does not exist, creating now."
  tput sgr0
  sudo mkdir -p "$DIR"
  sudo chown "$USER":"$USER" "$DIR"
fi

# Check if there is an existing mount of the mountpoint
EMOUNT=$(findmnt -l | grep "$DIR")
if [ "$EMOUNT" ]; then
  source="$(awk '{split($0, a); print a[2]}' <<< $EMOUNT)"
  fs="$(awk '{split($0, a); print a[3]}' <<< $EMOUNT)"
  tput setaf 1
  echo "\"$source\" mounted on mountpoint using \"$fs\" already."
  tput sgr0
  exit 1
fi

if [ "$(ls -A $DIR)" ]; then
  tput setaf 1
  echo "Mountpoint is not empty, exiting..."
  tput sgr0
  exit 1
fi

sshfs -C -o cache_timeout=80000,auto_cache,reconnect "$1":"$DIR" "$DIR"

if [ ! -f "/media/$2" ]; then
  sudo mkdir -p /media/$2
  sudo chown "$USER":"$USER" "/media/$2"
fi
if [ "$(ls -A /media/$2)" ]; then
  tput setaf 1
  echo "\"/media/$2\" exists, will not create symlink to mountpoint"
  tput sgr0
else
  sudo mount --bind --verbose "$DIR" "/media/$2"
fi

tput setaf 4
echo "Caching files"
tput sgr0
for file in $(find "$DIR"); do
    cat $file > /dev/null  2>&1
done

tput setaf 2
echo "Done"
tput sgr0