giovedì 24 marzo 2011

OPKG-LINK

Il seguente script l'ho trovato sul forum di openwrt serve a creare automaticamente dei link simbolici tra l'hd e la memoria flash della fonera, così da rendere disponibili i programmi e le librerie senza creari troppi problemi, ha il difetto di riempire la memoria flash se i pacchetti da linkare sono troppi. L'ho trovato utile in rare occasioni. Funziona solo se il filsystem supporta link simbolici, ad esempio ext3.
vi /usr/bin/opkg-link
incollate il codice:
#!/bin/sh
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'%%'`
test -f "$SRC"
if [ $? = 0 ]; then
test -e "$DST"
if [ $? = 1 ]; then
mkdir -p $DSTDIR
ln -sf $SRC $DST
else
echo "Not linking $SRC to $DST"
echo "$DST Already exists"
fi
else
test -d "$SRC"
if [ $? = 0 ]; then
test -e $DST
if [ $? = 1 ]; then
mkdir -p $DST
else
echo "directory already exists"
fi
else
echo "Source directory $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'%%'`
test -f $DST
if [ $? = 0 ]; then
rm -f $DST
test -d $DSTDIR && rmdir $DSTDIR 2>/dev/null
else
test -d $DST
if [ $? = 0 ]; then
rmdir $DST
else
echo "$DST does not exist"
fi
fi
done
}
mountdest () {
test -d $PACKAGE
if [ $? = 1 ]; 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
}
umountdest () {
test -d $PACKAGE
if [ $? = 1 ]; 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
}
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 kismet-server"
echo "Example: $0 remove kismet-server"
echo "Example: $0 mount /mnt/usb"
echo "Example: $0 umount /mnt/usb"
exit 1
;;
esac
exit 0
chmod +x /usr/bin/opkg-link
così da renderlo eseguibile ;)

Nessun commento:

Posta un commento