-
Notifications
You must be signed in to change notification settings - Fork 0
/
pandebian-share
executable file
·108 lines (89 loc) · 2.72 KB
/
pandebian-share
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# Copyright (c) 2011 Gregor Richards
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# Environment variables:
# PanDebian directories
PANDEBIANS=""
# Shareable directories
SHAREABLE=""
msg() {
zenity --info --text="$*"
}
warning() {
zenity --warning --text="$*"
}
die() {
zenity --error --text="$*"
exit 1
}
question() {
zenity --question --text="$1" --ok-label="$2" --cancel-label="$3"
return $?
}
entry() {
zenity --entry --text="$1" --entry-text="$2"
}
list() {
MSG="$1"
shift
zenity --list --text="$MSG" --column= "$@"
}
save() {
zenity --file-selection --save
}
savedir() {
( cd "$1"; zenity --file-selection --directory )
}
# Figure out the pandebian and shareable directories
for mnt in `cut -d' ' -f 2 /proc/mounts`
do
if [ -e "$mnt/etc/debian_version" ]
then
# Seems to be Debian
PANDEBIANS="$PANDEBIANS $mnt"
elif expr "$mnt" : '/media/[^/]*$' > /dev/null 2> /dev/null
then
if [ "$mnt" != "/media/ram" ]
then
# Probably reasonable to share
SHAREABLE="$SHAREABLE $mnt"
fi
fi
done
if [ ! "$PANDEBIANS" ]
then
die 'I couldn'\''t find PanDebian. Please make sure you mount a PanDebian installation before using PanDebian Share.'
fi
if [ ! "$SHAREABLE" ]
then
die 'I couldn'\''t find any shareable mounts. Sorry!'
fi
SHARE=`list 'Which mount would you like to share?' $SHAREABLE`
if [ ! "$SHARE" ]
then
exit
fi
# Then share it
for mnt in $PANDEBIANS
do
mkdir -p "$mnt$SHARE" || warning 'Failed to create '"$mnt/$SHARE"
mount --bind "$SHARE" "$mnt$SHARE" || warning 'Failed to bind '"$SHARE"' to '"$mnt/$SHARE"
done
msg 'Done. '"$SHARE"' should now be accessible within PanDebian.'