Skip to content

Instantly share code, notes, and snippets.

@viniciuspires
Created May 14, 2015 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viniciuspires/356d052ee70b937f78ab to your computer and use it in GitHub Desktop.
Save viniciuspires/356d052ee70b937f78ab to your computer and use it in GitHub Desktop.
Bash to fix file permissions in a Debian-like machine (specifically Ubuntu)
#!/bin/bash
ARCHIVE_DIR=/var/cache/apt/archives/
PACKAGES=`ls $ARCHIVE_DIR`
cd /
function changePerms()
{
echo ""
CHOWN="/bin/chown"
CHMOD="/bin/chmod"
PERMS=$1
OWN=`echo $2 | /usr/bin/tr '/' ':'`
PATHNAME=$3
#echo "Changing permissions for $PATHNAME"
echo -e "$CHOWN $OWN $PATHNAME"
#`$CHOWN $OWN $PATHNAME`
#`$CHMOD $MODE $PATHNAME`
}
for PACKAGE in $PACKAGES;
do
echo -e "Getting information for $PACKAGE\n"
FILES=`/usr/bin/dpkg -c "${ARCHIVE_DIR}${PACKAGE}"`
for FILE in "$FILES";
do
FILE_DETAILS=`echo "$FILE" | awk '{print $1"\t"$2"\t"$6}'`
FILE_DETAILS=`echo "$FILE_DETAILS" | tr '\t' '|'`
for DT in $FILE_DETAILS
do
DT=`echo "$DT" | tr '|' '\t'`
changePerms $DT
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment