-
Notifications
You must be signed in to change notification settings - Fork 5
/
pb.sh
executable file
·89 lines (85 loc) · 2.5 KB
/
pb.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
LOGFILE="/mnt/Pocketbook/system/config/nextcloud/logfile.txt"
APPLOCATION="build/Nextcloud.app"
APPDIR="/mnt/Pocketbook/applications/"
############################################################
# Help #
############################################################
Help()
{
# Display Help
echo "Functions to interact with the PB"
echo
echo "Syntax: pb [h|c|l|u]"
echo "options:"
echo "-h Print this Help."
echo "-c Copy the app to the appfolder"
echo "-l Show a logfile, if it exists"
echo "-u Unmount PB"
echo
}
############################################################
# MOUNT #
############################################################
Mount()
{
MOUNTPOINT=$(sudo blkid | awk '/PB/ {print $1;}' | tr -d ':')
if [ -n "$MOUNTPOINT" ]
then
if mount | grep $MOUNTPOINT > /dev/null; then
echo "Already mounted."
else
sudo mount $MOUNTPOINT /mnt/Pocketbook
fi
else
echo "Could not find PB"
fi
}
############################################################
############################################################
# Main program #
############################################################
############################################################
[ $# -eq 0 ] && Help
while getopts ":hclu" o; do
case $o in
h) #Display help
Help
exit;;
l)
Mount
if [ -f "$LOGFILE" ];
then
less $LOGFILE;
while true; do
read -p "Do you want to delete log?" yn
case $yn in
[Yy]* ) sudo rm -r $LOGFILE; break;;
[Nn]* ) exit;;
* ) echo "Y/N";;
esac
done
else
echo "No log file found."
fi
;;
c)
Mount
if [ -d "$APPDIR" ]
then
make
sudo cp $APPLOCATION $APPDIR
fi
;;
u)
if mount | grep /mnt/Pocketbook > /dev/null; then
sudo eject /mnt/Pocketbook
echo "Pocketbook ejected"
else
echo "/mnt/Pocketbook not mounted."
fi
;;
*)
echo "Invalid command. To see available commands add -h."
esac
done