Created
November 11, 2014 12:53
-
-
Save rindeal/12434603203ac7d25712 to your computer and use it in GitHub Desktop.
OpenWrt external storage package linker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# modified by ddxx0n | |
COMMAND=$1 | |
PACKAGE=$2 | |
setdest () { | |
for i in `grep dest /etc/opkg.conf | cut -d ' ' -f 3`; do | |
if [ -f $i/usr/lib/opkg/info/$PACKAGE.list ]; then | |
DEST=$i | |
fi | |
done | |
if [ "x$DEST" = "x" ]; then | |
echo "Can not locate $PACKAGE." | |
echo "Check /etc/opkg.conf for correct dest listings"; | |
echo "Check name of requested package: $PACKAGE" | |
exit 1 | |
fi | |
} | |
addlinks () { | |
setdest; | |
cat $DEST/usr/lib/opkg/info/$PACKAGE.list | while read LINE; do | |
SRC=$LINE | |
DST=`echo $SRC | sed "s|$DEST||"` | |
DSTNAME=`basename $DST` | |
DSTDIR=`echo $DST | sed "s|$DSTNAME\$||"` | |
if [ -f "$SRC" ]; then | |
echo -n "Linking $DST ... " | |
if [ ! -e "$DST" ]; then | |
if [ ! -d "$DSTDIR" ]; then | |
mkdir -p "$DSTDIR" | |
fi | |
# if [ `echo $SRC | grep bin/` ] || | |
if [ `echo $SRC | grep /lib/python` ] || [ `echo $SRC | grep /lib/perl` ] || [ `echo $SRC | grep /lib/php/PEAR` ]; then | |
echo "skipped" | |
else | |
echo "ok" | |
ln -sf "$SRC" "$DST" | |
fi | |
else | |
echo "warning: already exists" | |
fi | |
else | |
if [ ! -d "$SRC" ]; then | |
echo -n "Creating $DST ... " | |
if [ ! -e $DST ]; then | |
echo "ok" | |
mkdir -p $DST | |
else | |
echo "warning: already exists" | |
fi | |
else | |
echo "error: source $SRC does not exist" | |
fi | |
fi | |
done | |
} | |
removelinks () { | |
setdest; | |
cat $DEST/usr/lib/opkg/info/$PACKAGE.list | while read LINE; do | |
SRC=$LINE | |
DST=`echo $LINE | sed "s|$DEST||"` | |
DSTNAME=`basename $DST` | |
DSTDIR=`echo $DST | sed "s|$DSTNAME\$||"` | |
if [ -f $DST ]; then | |
echo -n "Unlinking $DST ... " | |
if [ -h $DST ]; then | |
echo "ok" | |
rm -f $DST | |
else | |
echo "warning: regular file" | |
fi | |
test -d $DSTDIR && rmdir $DSTDIR 2>/dev/null | |
else | |
echo -n "Removing $DST ... " | |
if [ -d $DST ]; then | |
rmdir $DST | |
if [ $? = 0 ]; then | |
echo "ok" | |
else | |
echo "warning: not empty" | |
fi | |
else | |
echo "error: does not exist" | |
fi | |
fi | |
done | |
} | |
mountdest () { | |
if [ ! -d $PACKAGE ]; then | |
echo "Mount point does not exist" | |
exit 1 | |
fi | |
for i in $PACKAGE/usr/lib/opkg/info/*.list; do | |
$0 add `basename $i .list` | |
done | |
touch /etc/flags/usb_mounted | |
} | |
umountdest () { | |
if [ ! -d $PACKAGE ]; then | |
echo "Mount point does not exist" | |
exit 1 | |
fi | |
for i in $PACKAGE/usr/lib/opkg/info/*.list; do | |
$0 remove `basename $i .list` | |
done | |
rm -f /etc/flags/usb_mounted | |
} | |
case "$COMMAND" in | |
add) | |
addlinks | |
;; | |
remove) | |
removelinks | |
;; | |
mount) | |
mountdest | |
;; | |
umount) | |
umountdest | |
;; | |
*) | |
echo "Usage: $0 " | |
echo " Commands: add, remove, mount, umount" | |
echo " Targets: , " | |
echo "Example: $0 add linux-kernel" | |
echo "Example: $0 remove linux-kernel" | |
echo "Example: $0 mount /usr/local/openwrt" | |
echo "Example: $0 umount /usr/local/openwrt" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment