Re: [SLUG] shell not following instructions (chmod)

From: Eben King (eben01@verizon.net)
Date: Tue Dec 16 2008 - 11:46:20 EST


On Mon, 15 Dec 2008, Eben King wrote:

> On Mon, 15 Dec 2008, Eben King wrote:
>
>> Why don't the file permissions change? They should all be 644 the second
>> time around, but they remain 755.
>
> Ah crud, it's on vfat. No permissions. Lemme move it...

Got around it. Here's the script I used, minus the comments and unused
code:

#! /bin/sh

STAGEDIR=/media/disk/pdb-temp # if this is on vfat the chmod won't work
cd "$STAGEDIR" || exit
TARDIR=/media/TRANSFER_2/pdb # where the tar files are
SQUASHFS=/misc/torrent/pdb.squashfs
for firstletter in $(\ls -1 "$TARDIR"/*.bz2 | sed -e 's@^.*/@@' -e 's@\..*$@@' | cut -c 1 | sort -u) ; do
     for file in "$TARDIR"/${firstletter}*.tar.bz2 ; do
         echo $file
         tar xjf "$file" || exit # pbzip would be faster but it crashes randomly
     done
     chmod 755 ./${firstletter}*
     chmod 644 ./${firstletter}*/*
     pa $firstletter
     $TARDIR/rename-files ./$firstletter
     mksquashfs $firstletter $SQUASHFS -all-root -info -no-progress -no-sparse -no-recovery -keep-as-directory || break
     rm -r ./${firstletter}*
done
cd -

"pa" ("put away", I'd written it before) is:

#!/bin/sh

if [ "z$1" = z-ln ] ; then
     MV=ln
     shift
else
     MV=mv
fi

while [ $# -gt 0 ] ; do # args left
         dirname="$1"
         [ \( -f $1 \) -a \( ! -e $1.0 \) ] && mv "$1" "$1".0
         [ $(echo "${dirname}"?* | wc -l) -ge 1 ] && {
                 [ -e "$dirname" ] || mkdir "$dirname"
                 $MV -v -- "${dirname}"?* "$dirname"
         }
         shift
done

"rename-files" is:

#! /bin/sh

while [ $# -gt 0 ] ; do
     arg="$1"
     find "$arg" -type f -name \*.pdb\* \
     | while read file ; do
         echo "$file" | grep -qi 'pdb$' && continue
         newname=$(echo $file | sed 's/^\(.*\)\(.[Pp][Dd][Bb]\)\(.*\)$/\1-\3\2/')
         mv $file $newname
     done
     shift
done

It took 3h42m to run, the final size was 9.0 GiB, and the source data was
7.3 GiB. Not bad expansion for instant accessibility.

-- 
A well-lovd and corrctly traind domstc cnine is gnrlly slobbry, excitbl,
noisy, scatologically obsessed, xenophobic, pathetically unjudgmental,
embrrssngly uninhbtd, unreasnngly dvtd, hrtbrkngly dpndnt and wretchedly
craven.  All othr knds of dog cmpre unfvrbly wth ths picture. - PB, AFCA
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:05:14 EDT