Skip to content

Commit b750457

Browse files
committed
- add conkyrc_remove to remove all mnttools entries in conkyrc
- use lsblk instead of blkid - add remount
1 parent bdb5a3b commit b750457

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed

mnttools/mnttools

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
COMMENT
1717

18-
version="mnttools v0.4.0"
18+
version="mnttools v0.4.1"
1919
blue='\e[0;34m'; green='\e[0;32m'; red='\e[0;31m'; yellow='\e[0;33m'; bold='\e[1m';none='\e[0m'
2020
function menu {
2121
n=0
@@ -84,35 +84,23 @@ function udevunmount() {
8484
function devicemenu {
8585
mntopts="-o $general_mntopts"
8686
if [[ $1 ]]; then
87-
i=(`sudo blkid -o value "$1"`)
88-
[[ $i ]] || return
89-
DEVNAME=$1
90-
[[ ${i[2]} = ntfs ]] && fs="-t ntfs-3g" || fs="-t ${i[2]}"
91-
[[ $fs =~ vfat|ntfs ]] && mntopts="$mntopts,$winfs_mntopts"
92-
label=${i[0]:=${DEVNAME##*/}}
93-
mntpoint=$mntroot/$label
94-
_mount
95-
return
96-
fi
97-
IFS=$'\n'
98-
d=(`sudo blkid -o list | grep "not mounted"`)
99-
if [[ $d ]]; then
87+
eval "`lsblk -P -o NAME,FSTYPE,LABEL $1`"
88+
[[ $FSTYPE ]] || return
89+
else
90+
IFS=$'\n'
91+
d=(`lsblk -P -o NAME,FSTYPE,LABEL,MOUNTPOINT | grep -e MOUNTPOINT=\"\" | grep -v -e FSTYPE=\"\" | cut -d' ' -f1-3`)
10092
menutitle="Device Menu"
10193
menu ${d[@]} "Main Menu"
10294
IFS=$oIFS
10395
if [[ $choice = "Main Menu" ]]; then mainmenu; return; fi
104-
i=($choice)
105-
DEVNAME=${i[0]}
106-
[[ ${i[1]} = ntfs ]] && fs="-t ntfs-3g" || fs="-t ${i[1]}"
107-
[[ $fs =~ vfat|ntfs ]] && mntopts="$mntopts,$winfs_mntopts"
108-
label=${i[2]:=${DEVNAME##*/}}
109-
mntpoint=$mntroot/$label
110-
_mount
111-
else
112-
IFS=$oIFS
113-
echo -e "${red}Cannot find any not mounted device $none"
114-
mainmenu
96+
eval "$choice"
11597
fi
98+
DEVNAME=/dev/$NAME
99+
[[ $FSTYPE = ntfs ]] && fs="-t ntfs-3g" || fs="-t $FSTYPE"
100+
[[ $fs =~ vfat|ntfs ]] && mntopts="$mntopts,$winfs_mntopts"
101+
label=${LABEL:=${DEVNAME##*/}}
102+
mntpoint=$mntroot/$label
103+
_mount
116104
}
117105

118106
function imagemenu {
@@ -283,7 +271,7 @@ function histsave {
283271

284272
function mainmenu {
285273
menutitle="Main Menu"
286-
menu "Mount devices on this computer" "Mount image file" "Mount Samba share" "Mount SSH" "Mount FTP" "Mount NFS" "Mount from history" "Unmount"
274+
menu "Mount devices on this computer" "Mount image file" "Mount Samba share" "Mount SSH" "Mount FTP" "Mount NFS" "Mount from history" "Unmount" "Remove all entries from conkyrc" "Remount Device"
287275
case $choice in
288276
*devices*) devicemenu ;;
289277
*image*) imagemenu ;;
@@ -293,11 +281,13 @@ function mainmenu {
293281
*NFS) nfsmenu ;;
294282
*history) histmenu ;;
295283
Unmount) unmountmenu ;;
284+
*conkyfc) modconkyrc removeall ;;
285+
Remount*) remountmenu ;;
296286
esac
297287
}
298288

299289
function unmountmenu {
300-
if [ $1 ]; then
290+
if [[ $1 ]]; then
301291
[[ $1 = $mntroot ]] && mntpoint=$1 || mntpoint=`mount | grep "$1" | cut -d' ' -f3`
302292
unmount "$mntpoint"
303293
return
@@ -323,6 +313,23 @@ function unmountmenu {
323313
mainmenu
324314
}
325315

316+
function remountmenu {
317+
if [[ $1 ]]; then
318+
eval "`lsblk -P -o NAME,MOUNTPOINT | grep ${1##*/}`"
319+
else
320+
IFS=$'\n'
321+
d=(`lsblk -P -o NAME,MOUNTPOINT | grep $mntroot`)
322+
menutitle="Remount Device Menu"
323+
menu ${d[@]} "Main Menu"
324+
IFS=$oIFS
325+
if [[ $choice = "Main Menu" ]]; then mainmenu; return; fi
326+
eval "$choice"
327+
fi
328+
unmount "$MOUNTPOINT"
329+
sleep 1
330+
devicemenu "/dev/$NAME"
331+
}
332+
326333
function _mount() { #require: DEVNAME mntpoint mntopts
327334
[[ $DEVNAME && $mntpoint ]] || return 1
328335
if i=`mount | grep -q "$DEVNAME"`; then
@@ -338,7 +345,7 @@ function _mount() { #require: DEVNAME mntpoint mntopts
338345
-t*ftpfs) curlftpfs "$DEVNAME" "$mntpoint" $mntopts; echo "mount command: curlftpfs $DEVNAME $mntpoint $mntopts" ;;
339346
*) $runasroot mount $fs $mntopts "$DEVNAME" "$mntpoint"; echo "mount command: $runasroot mount $fs $mntopts $DEVNAME $mntpoint" ;;
340347
esac
341-
if [[ $? -eq 0 ]]; then
348+
if mount | grep -q "$mntpoint"; then
342349
histsave
343350
modconkyrc add
344351
echo "$DEVNAME is mounted at $mntpoint"
@@ -372,9 +379,12 @@ function modconkyrc {
372379
for i in "${conkyrc[@]}"; do
373380
[[ -f $i ]] || continue
374381
if [[ $1 = add && $DEVNAME = /dev/* ]]; then
375-
echo -e "\${color slate grey}${mntpoint##*/}:\${fs_size $mntpoint} \${color orange}U:\${fs_used $mntpoint} \${color}F:\${fs_free $mntpoint}\n\$color\${fs_bar $mntpoint} \${color orange}\${diskio ${DEVNAME##*/}}" >>"$i"
382+
echo -e "\${color slate grey}${mntpoint##*/}:\${fs_size $mntpoint} \${color orange}U:\${fs_used $mntpoint} \${color}F:\${fs_free $mntpoint} \${if_empty mnttools_entry}\$endif" >>"$i"
383+
echo -e "\$color\${fs_bar $mntpoint} \${color orange}\${diskio ${DEVNAME##*/}} \${if_empty mnttools_entry}\$endif" >>"$i"
376384
elif [[ $1 = remove ]]; then
377-
sed -i "/${mntpoint##*\/}/d" "$i"
385+
sed -i "/${mntpoint##*\/}.*mnttools/d" "$i"
386+
elif [[ $1 = removeall ]]; then
387+
sed -i "/mnttools_entry/d" "$i"
378388
fi
379389
done
380390
}
@@ -421,6 +431,8 @@ $0 unmount [mountpoint|device name] #unmount mountpoint in mount folder
421431
$0 editcfg #create/edit cfg
422432
$0 readme #show readme
423433
$0 tray #show trayicon
434+
$0 conkyrc_remove #remove all mnttools conkyrc entries
435+
$0 remount [mountpoint|device name] #remount device
424436
EOF
425437
exit
426438
}
@@ -458,10 +470,12 @@ case $action in
458470
ftpfs) ftpmenu ;;
459471
samba) smbmenu ;;
460472
device) devicemenu "$2" ;;
473+
remount) remountmenu "$2" ;;
461474
hist) histmenu ;;
462475
unmount) unmountmenu "$2";;
463476
editcfg) [[ -f $cfg ]] || writecfg; xdg-open "$cfg" ;;
464477
readme) readme=`readlink -f "$0"`.readme; cat "$readme" ;;
478+
conkyrc_remove) modconkyrc removeall ;;
465479
-h|*help) usage ;;
466480
*) mainmenu ;;
467481
esac

0 commit comments

Comments
 (0)