-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_perms
93 lines (81 loc) · 2.23 KB
/
fix_perms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# run me thus: `bash fix_perms`
[[ -r makeln ]] || ( echo "must be in common dir!" && exit 2 )
source functions
set_admin
#########################
# Fix syncing permissions
#########################
syfixperms
#################################################
# Check for weird `git` states
# caused by bogusly restored `git` internal files
#################################################
# written with the help of ChatGPT-4
rebase_merge_dir=.git/rebase-merge
rebase_todo_file=$rebase_merge_dir/git-rebase-todo
if [[ -d $rebase_merge_dir ]]
then
if [[ ! -f $rebase_todo_file ]]
then
function all-files-empty
{
local dir="$1"
[[ -d $dir ]] || die "must supply directory"
local empty=true
for file in "$dir"/*
do
if [[ -s "$file" ]]
then
empty=false
break
fi
done
$empty
}
if all-files-empty $rebase_merge_dir
then
echo "detected bogus $rebase_merge_dir; removing"
/bin/rm -rf $rebase_merge_dir
else
echo "$rebase_merge_dir looks bogus, but some files not emtpy; fix manually"
fi
fi
fi
###############################################
# Remove bogusly restored files outside `.git/`
###############################################
bogus_files="refresh fortunes/buddy.dat fortunes/buddy_*Conflict bin/search bin/syconf-fixperms bin/dbconf*
local/zadash/bin/work-desktop"
for_deletion=""
for file in $bogus_files
do
[[ -e $file ]] && for_deletion="$for_deletion $file"
done
if [[ $for_deletion ]]
then
echo "potential bogus files: $for_deletion"
confirm "remove all those?" && /bin/rm -rf $for_deletion
fi
#########################################
# Force executable files to be executable
#########################################
chmod +x makeln
chmod +x repl-bottom
chmod +x repl-top
chmod +x new_dropbox
chmod +x bin/*
chmod -x bin/tcshrc-DEBUG # exception
(
cd root
chmod +x psync
chmod +x makeln
chmod +x lbin/*
chmod +x sbin/*
find lbin sbin -type f | fgrep -xvf notmine | xargs chgrp $ADMIN
find lbin sbin -type f | fgrep -xvf notmine | xargs chmod g+w
)
#########################################################
# Check with `git` as to any remaining mode discrepancies
#########################################################
# report/fix any remaining issues
bin/sygit-fixperms