Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
ipfrec() {
ipfrecint() {
OBJECT_LIST=$(ipfs files ls -l "$1" | rev)
while read -r OBJECT
do
[[ "$OBJECT" == "" ]] && continue
ONAME=$(echo "$OBJECT" | awk '{print substr($0, index($0,$3))}' | rev)
OSIZE=$(echo "$OBJECT" | awk '{print $1}' | rev)
OHASH=$(echo "$OBJECT" | awk '{print $2}' | rev)
if [[ $1 == "/" ]] ; then
SUBPATH="$1$ONAME"
else
SUBPATH="$1/$ONAME"
fi
if [ "$OSIZE" -eq "0" ] ; then
! $FILESONLY && echo -e "dir:\t$OHASH\t$SUBPATH"
if [ "$MAXD" -eq "0" ] ; then
ipfrecint "$SUBPATH"
else
SLASHN=$(echo "$SUBPATH" | awk -F/ '{print NF-1}')
if [ "$SLASHN" -eq "$MAXD" ] ; then
continue
else
ipfrecint "$SUBPATH"
fi
fi
elif [ "$OSIZE" -gt "0" ] ; then
! $DIRSONLY && echo -e "file:\t$OHASH\t$SUBPATH\t$OSIZE"
fi
done < <(echo "$OBJECT_LIST")
}
if [[ $(ipfs 2>/dev/null) == "" ]] ; then
echo "Error: IPFS is either not installed or not in your \$PATH" >&2
return 1
fi
FILESONLY=false
DIRSONLY=false
MAXD="0"
while :; do
case $1 in
-d|--directories)
DIRSONLY=true
;;
-f|--files)
FILESONLY=true
;;
-m|--maxdepth)
shift
MAXD="$1"
REGEX='^[0-9]+$'
if ! [[ $MAXD =~ $REGEX ]] ; then
echo "Error: an alternate argument for option -m needs to be a positive integer (default: 0 = full scan)." >&2
return 1
fi
;;
--)
shift
break
;;
-?*)
echo "Error: invalid option: $1" >&2
return 1
;;
*)
break
esac
shift
done
if $FILESONLY && $DIRSONLY ; then
FILESONLY=false
DIRSONLY=false
fi
if [[ $@ == "" ]] ; then
ipfrecint /
else
for FILESPATH in "$@"
do
ipfrecint "$FILESPATH"
done
fi
}