Project

General

Profile

Issue #2028 » fix-permissions.sh

Ama Agne, 05/20/2020 12:01 PM

 
1
file_list=$1
2
# This only works if each file that's found in the working directory's
3
# tree has a unique basename.
4
# 
5
# The parsing is for output as found here:
6
# https://redmine.replicant.us/projects/replicant/wiki/GT-I9300EFSContent
7
# Some ls programs format the date differently.
8
#
9
# The directories mode bits, owner and group will not be changed.
10
(OLD_IFS="$IFS"; \
11
 IFS='
12
'; \
13
 for line in $(IFS=$OLD_IFS; \
14
	    cat $file_list \
15
		| grep '^[-d]' \
16
		| grep -v ' \.\.$' \
17
		| grep -v ' \.$') ; \
18
 do (IFS=$OLD_IFS; \
19
     file_name=$(echo $line | cut -d ' ' -f 9); \
20
     file=$(find . -name "$file_name"); \
21
     owner=$(echo $line | cut -d ' ' -f 3); \
22
     group=$(echo $line | cut -d ' ' -f 4); \
23
     user_bits=$(echo $line | cut -c 2-4 | tr -d '-'); \
24
     group_bits=$(echo $line | cut -c 5-7 | tr -d '-'); \
25
     others_bits=$(echo $line | cut -c 8-10 | tr -d '-'); \
26
     if [ -z "$file" ]; \
27
     then echo "$file_name not found."; \
28
	  echo "The line was:"; \
29
	  echo "$line"; \
30
     else \
31
	 chmod  u=$user_bits,g=$group_bits,o=$others_bits $file; \
32
	 chown  $owner $file; \
33
	 chgrp  $group $file; \
34
     fi; \
35
     ); \
36
 done; \
37
 IFS=$OLD_IFS)
(2-2/3)