-
Notifications
You must be signed in to change notification settings - Fork 2
/
chia-mount.sh
executable file
·70 lines (57 loc) · 1.58 KB
/
chia-mount.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -euo pipefail
script_root="$(cd "$(dirname "$(readlink "$([[ "${OSTYPE}" == linux* ]] && echo "-f")" "$0")")"; pwd)"
source "${script_root}/lib/utils.sh"
APPNAME=chia-mount
usage() {
if [ $# -eq 0 ]; then
echo ""
echo "${APPNAME}"
echo ""
echo "Usage:"
echo ""
printf "%s\n" " ${APPNAME} <subcommand> [arguments]"
echo ""
echo "Where subcommand is:"
echo ""
echo " add <device> Add device to /etc/fstab and mount it by label."
echo " Be sure to check /etc/fstab and make neccessary"
echo " adjustments. Also create mount point and assign"
echo " access rights to current user. Perform initial"
echo " mounting. *** SHOULD BE CALLED ONCE ***"
echo ""
exit 1
fi
}
do_add() {
[ "$#" -eq 1 ] || fatal "Expected device name"
local dev_name="$1"
local label
label="$(sudo e2label "${dev_name}")"
printf "Disk label: %s\n" "${label}"
local mountpoint
mountpoint="/mnt/${label}"
printf "Creating mountpoint: %s\n" "${mountpoint}"
sudo mkdir -p "${mountpoint}"
echo "Updating /etc/fstab"
printf "LABEL=%s %s auto nosuid,nodev,nofail,noatime 0 0\n" "${label}" "${mountpoint}" | sudo tee -a /etc/fstab
printf "Mounting: %s\n" "${mountpoint}"
sudo mount "${mountpoint}"
echo "Changing files ownership"
sudo chown -R "$(id -u):$(id -g)" "${mountpoint}"
echo "Done."
}
[ "$#" -ge 1 ] || {
usage
exit 1
}
subcommand="$1"
shift
case "$subcommand" in
add)
do_add "$@"
;;
*)
fatal "Unknown subcommand $subcommand"
;;
esac