I have attached 32x32 sized .png images which I made (edited) to reflect Floppy, HDD, CD, USB, file system, mounted/not-mounted and the Tiny Core backup device. Based on gnome, Mint-X and the TC forums favicon. (: I have mine in ~/.local/share/icons/ .
- /etc/sysconfig/backup_device gets read to indicate the Tiny Core drive. This hasn't been thought through very well yet.
- If ImageMagic is loaded, the script now creates .png images from .ico files (/tmp/idesk-mount/*) for removable media (CD, USB drives) if there exists an AUTORUN.INF file.
- Instead of naming icon config files in ~/.idesktop/ just by the device names, they are now prefixed with idesk-mount- , so they can safely be deleted by the script and rewritten. Otherwise, drives which are not attached anymore would still be displayed after reboot if a backup was made while they were attached.
#!/bin/sh
# idesk-mount.sh for Tiny Core Linux
# Creates icon files for iDesk to u/mount devices listed in /mnt.
# (c) Misalf 2015
#
WIDTH=32
HEIGHT=32
X_POS_INIT=16
X_POS="$X_POS_INIT"
Y_POS_INIT=64
Y_POS="$Y_POS_INIT"
#X_GAP=48
X_GAP=$((WIDTH+X_POS_INIT))
#Y_GAP=64
Y_GAP=$((HEIGHT+X_POS_INIT+X_POS_INIT))
ICON_PATH="$HOME/.local/share/icons"
ICON_BG="$ICON_PATH/idesk-mount-bg-mounted.png"
ICON_CD="$ICON_PATH/optical.png"
ICON_FD="$ICON_PATH/floppy.png"
ICON_HDD="$ICON_PATH/hdd.png"
ICON_HDD_LINUX="$ICON_PATH/hdd-linux.png"
ICON_HDD_DOS="$ICON_PATH/hdd-dos.png"
ICON_HDD_WIN="$ICON_PATH/hdd-win.png"
# FILEMGR See ~/.profile
if [ -z "$FILEMGR" ]; then
if [ "$(which xfe)" ]; then
FILEMGR="xfe"
elif [ "$(which pcmanfm)" ]; then
FILEMGR="pcmanfm"
elif [ "$(which mc)" ]; then
FILEMGR="mc"
elif [ "$(which urxvt)" ]; then
FILEMGR="urxvt -cd"
elif [ "$(which aterm)" ]; then
# FILEMGR="aterm -cd" # Nope.
FILEMGR="(cd /mnt; aterm) &"
fi
fi
[ -d "$HOME/.idesktop" ] || mkdir -p "$HOME/.idesktop"
rm -f "$HOME"/.idesktop/idesk-mount-*.lnk 2>/dev/null
BACKUP_DEVICE=$(cat /etc/sysconfig/backup_device)
BACKUP_DEVICE="${BACKUP_DEVICE%%/*}"
f_icon_newline() {
if [ -n "$2" ]; then
if [ "$1" != "$2" ]; then
Y_POS=$((Y_POS+Y_GAP))
[ "$X_POS" -gt "$X_POS_INIT" ] && X_POS=$X_POS_INIT
fi
fi
}
f_icon_autorun() {
# iDesk cannot use image files in .ico format
# so we convert them to PNG via ImageMagick, if available.
if [ "$(which convert)" ]; then
if [ "$(ls /mnt/"$i"/autorun.inf 2>/dev/null)" ]; then
ICONICO="$(grep -i icon /mnt/"$i"/autorun.inf | sed -r 's/[i|I]con=//g' | sed 's/\\/\//g' | dos2unix)"
if [ -e "/mnt/$i/$ICONICO" ]; then
[ -d "/tmp/idesk-mount" ] || mkdir -p "/tmp/idesk-mount"
ICONTMP="/tmp/idesk-mount/$i.png"
ICOINDEX=$(convert -identify "/mnt/$i/$ICONICO" /dev/null | grep "$WIDTH"x"$HEIGHT" | awk '{printf "%s", $1}')
if [ -n "$ICOINDEX" ]; then
ICOINDEX="${ICOINDEX#\/mnt\/$i\/$ICONICO[}"
ICOINDEX="${ICOINDEX/]}"
else
# TODO: Need to check for alternate (higher) resolution image inside .ico file.
# For now just 'guessing'.
ICOINDEX=3
fi
[ -n "$1" ] || ICON="$ICON_BG"
convert "/mnt/$i/$ICONICO[$ICOINDEX]" -geometry "$WIDTH"x"$HEIGHT" "$ICONTMP" && \
convert -composite "$ICON" "$ICONTMP" "$ICONTMP" && \
[ -e "$ICONTMP" ] && ICON="$ICONTMP"
fi
fi
fi
}
f_icon_image() {
[ "$MOUNTED" = "-mounted" ] && DEVFS="$FSTYPE_MNT" || DEVFS="$FSTYPE_TAB"
case $i in
sr*)
ICON="${ICON_CD/.png/$MOUNTED.png}"
f_icon_autorun "$ICON"
f_icon_newline "${i:1:1}" "${PREV_DEV:1:1}"
;;
fd*) ICON="${ICON_FD/.png/$MOUNTED.png}" ;;
*)
case $DEVFS in
ext*) ICON="${ICON_HDD_LINUX/.png/$MOUNTED.png}" ;;
*fat*|msdos) ICON="${ICON_HDD_DOS/.png/$MOUNTED.png}" ;;
ntfs*) ICON="${ICON_HDD_WIN/.png/$MOUNTED.png}" ;;
fuseblk)
ICON="${ICON_HDD_WIN/.png/$MOUNTED.png}"
[ -n "$FSTYPE_TAB" ] && FSTYPE_MNT="$FSTYPE_TAB"
;;
*) ICON="${ICON_HDD/.png/$MOUNTED.png}" ;;
esac
REMOVABLE=$(cat /sys/block/"${i:0:3}"/removable)
if [ "$REMOVABLE" = "1" ]; then
ICON="${ICON/hdd-/removable-}"
f_icon_autorun
fi
[ "$BACKUP_DEVICE" = "$i" ] && ICON="${ICON/.png/-tinycore.png}"
f_icon_newline "${i:2:1}" "${PREV_DEV:2:1}"
;;
esac
}
f_icon_file() {
{
echo "table Icon"
echo " Caption: $CAPTION"
echo " ToolTip.Caption: $i${FSSIZE}${FSTYPE} ${LABEL}"
echo " Icon: $1"
echo " Width: $WIDTH"
echo " Height: $HEIGHT"
echo " X: $X_POS"
echo " Y: $Y_POS"
echo " Command[0]: sudo $MOUNTCMD /dev/$i ; $(basename "$0")"
[ -n "$FILEMGR" ] && \
echo " Command[1]: $FILEMGR /mnt/$i"
echo "end"
} > "$ICONFILE"
}
for i in /mnt/*
do
i="$(echo "$i" | sed 's/\/mnt\///g')"
ICONFILE="$HOME/.idesktop/idesk-mount-$i.lnk"
FSTYPE_TAB=$(grep "$i" /etc/fstab | awk '{printf "%s\n", $3}')
[ -z "$FSTYPE_TAB" ] && continue
LABEL="\"$(blkid -s LABEL -o value /dev/"$i")\""
FSSIZE_FULL=$(df -h | grep "$i" | awk '{printf "%s", $2}')
FSSIZE_USED=$(df -h | grep "$i" | awk '{printf "%s", $3}')
FSTYPE_MNT=$(df -T | grep "$i" | awk '{printf "%s\n", $2}')
if [ -n "$FSTYPE_MNT" ]; then
MOUNTED="-mounted"
CAPTION="[$i]"
MOUNTCMD="umount"
f_icon_image
FSTYPE=" ($FSTYPE_MNT)"
if [ "$FSSIZE_FULL" = "$FSSIZE_USED" ]; then
FSSIZE=" - ${FSSIZE_FULL}"
else
FSSIZE=" - ${FSSIZE_USED}/${FSSIZE_FULL}"
fi
else
MOUNTED=""
CAPTION=" $i "
MOUNTCMD="mount"
f_icon_image
[ "$FSTYPE_TAB" = "auto" ] && FSTYPE="" || FSTYPE=" ($FSTYPE_TAB)"
FSSIZE=""
fi
f_icon_file "$ICON"
PREV_DEV="$i"
X_POS=$((X_POS+X_GAP))
done
killall idesk >/dev/null 2>&1
/usr/local/bin/idesk >/dev/null 2>&1 &