Created
May 14, 2015 18:17
-
-
Save viniciuspires/356d052ee70b937f78ab to your computer and use it in GitHub Desktop.
Bash to fix file permissions in a Debian-like machine (specifically Ubuntu)
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/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