-
Notifications
You must be signed in to change notification settings - Fork 2
/
bmm-media_permissions
executable file
·177 lines (162 loc) · 5.86 KB
/
bmm-media_permissions
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
## Fix/modify permissions of media files to work
## with arr* software or use manual custom entries.
## Uses 2775 for folders and 664 for files as standard.
## Tarso Galvao 08/04/23 Debian 11 (Based on Snortt's script)
## load enviroment variables
if [ -f $HOME/bmm/.env ]; then
. $HOME/bmm/.env
else
echo -e "FATAL ERROR: .env not found.$\n
Use bmm-setup_enviroment to create one.\nAborting...";
exit 1;
fi
## DO STUFF ($1-path $2-user $3-group)
fix_permissions () {
if ! command -v $BANNER >> /dev/null; then echo -e "${WARN}BASH MEDIA MANAGER${NC}"; else eval "$BANNER"; fi
echo -e "${HEAD}Media Permissions${NC}"
for _dir in "$1"
do
echo '----------------------------------------------------------'
echo -e "Processing path: $_dir..."
sudo chown -R "$2":"$3" "${_dir}" && echo -e "${WARN}Ownership: ${HEAD}$2:$3 ${OK}OK${NC}"
echo 'Processing folders...'
sudo find "${_dir}" -type d -exec chmod 2775 {} \; && echo -e "${WARN}Folders: ${OK}OK${NC}"
echo 'Processing files...'
sudo find "${_dir}" -type f -exec chmod 664 {} \; && echo -e "${WARN}Files: ${OK}OK${NC}"
done
}
## user input entries (Custom)
custom_entry () {
## get path
path=$(dialog --no-lines --colors \
--backtitle "\Z7Bash Media Manager" \
--title "Media Permissions" \
--inputbox "Enter full path: \n \
( ex.: /full/path/to/dir/ )" 10 40 \
3>&1 1>&2 2>&3 3>&-)
clear #check path:
if [ "$path" == "" ]; then echo -e "${ERROR}No path, aborting...${NC}"; sleep 2;
clear && eval bmm-launcher; exit 1; fi
## get user
user=$(dialog --no-lines --colors \
--backtitle "\Z7Bash Media Manager" \
--title "Media Permissions" \
--inputbox "Enter user: \n \
( ex.: dietpi or 1000 )" 10 40 \
3>&1 1>&2 2>&3 3>&-)
clear #check user:
if [ "$user" == "" ]; then echo -e "${ERROR}No user, aborting...${NC}"; sleep 2;
clear && eval bmm-launcher; exit 1; fi
## get group
group=$(dialog --no-lines --colors \
--backtitle "\Z7Bash Media Manager" \
--title "Media Permissions" \
--inputbox "Enter group: \n \
( ex.: dietpi or 1000 )" 10 40 \
3>&1 1>&2 2>&3 3>&-)
clear #check group:
if [ "$group" == "" ]; then echo -e "${ERROR}No group, aborting...${NC}"; sleep 2;
clear && eval bmm-launcher; exit 1; fi
## execute with user input args
fix_permissions "$path" "$user" "$group"
}
main_menu () {
checklist=(dialog --no-lines --colors \
--backtitle "\Z7Bash Media Manager" \
--separate-output --checklist "Select a preset: (use spacebar)" 22 76 16)
options=(1 "Audio $AUDIO_OWNER:$GROUP" off
2 "Series $SERIES_OWNER:$GROUP" off
3 "Movies $MOVIES_OWNER:$GROUP" off
4 "Concerts $CONCERTS_OWNER:$GROUP" off
5 "Stand-up $STANDUP_OWNER:$GROUP" off
6 "Custom" off)
choices=$("${checklist[@]}" "${options[@]}" 2>&1 >/dev/tty)
clear
for choice in $choices
do
case $choice in
1)
fix_permissions "$AUDIOROOT" "$AUDIO_OWNER" "$GROUP"
;;
2)
fix_permissions "$SERIESROOT" "$SERIES_OWNER" "$GROUP"
;;
3)
fix_permissions "$MOVIESROOT" "$MOVIES_OWNER" "$GROUP"
;;
4)
fix_permissions "$CONCERTSROOT" "$CONCERTS_OWNER" "$GROUP"
;;
5)
fix_permissions "$STANDUPROOT" "$STANDUP_OWNER" "$GROUP"
;;
6)
custom_entry
;;
esac
done
## return on done or no entry
dialog --colors --no-lines \
--backtitle "\Z7Bash Media Manager" \
--infobox "Task complete. Press Enter to continue or Esc to exit." 3 50
# Capture the exit status of the previous command
status=$?
# Check the exit status and act accordingly
if [ $status -eq 0 ]; then
# User pressed Enter to continue
read -n 1 -s key
if [ "$key" = $'\x1b' ]; then
# User pressed Esc, so exit
clear
exit 0
else
# User pressed Enter, continue with bmm-launcher
clear
eval bmm-launcher
exit 0
fi
else
# Handle the case where dialog or another command failed
echo "Error: Task could not be completed."
exit 1
fi
}
## STATUP OPTIONS
if [ "$1" = '-a' ] || [ "$1" = '--audio' ]; then
fix_permissions "$AUDIOROOT" "$AUDIO_OWNER" "$GROUP"
elif [ "$1" = '-s' ] || [ "$1" = '--series' ]; then
fix_permissions "$SERIESROOT" "$SERIES_OWNER" "$GROUP"
elif [ "$1" = '-m' ] || [ "$1" = '--movies' ]; then
fix_permissions "$MOVIESROOT" "$MOVIES_OWNER" "$GROUP"
elif [ "$1" = '-c' ] || [ "$1" = '--concerts' ]; then
fix_permissions "$CONCERTSROOT" "$CONCERTS_OWNER" "$GROUP"
elif [ "$1" = '-u' ] || [ "$1" = '--stand-up' ]; then
fix_permissions "$STANDUPROOT" "$STANDUP_OWNER" "$GROUP"
elif [ "$1" = '-t' ] || [ "$1" = '--target' ]; then
fix_permissions "$2" "$3" "$4"
elif [ "$1" = '-f' ] || [ "$1" = '--full' ]; then
fix_permissions "$AUDIOROOT" "$AUDIO_OWNER" "$GROUP"
fix_permissions "$SERIESROOT" "$SERIES_OWNER" "$GROUP"
fix_permissions "$MOVIESROOT" "$MOVIES_OWNER" "$GROUP"
fix_permissions "$CONCERTSROOT" "$CONCERTS_OWNER" "$GROUP"
fix_permissions "$STANDUPROOT" "$STANDUP_OWNER" "$GROUP"
elif [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
if ! command -v $BANNER >> /dev/null; then echo -e "${WARN}BASH MEDIA MANAGER${NC}"; else eval "$BANNER"; fi
echo -e "${HEAD}Media Permissions"
echo -e "${OK}Fix file/folder permissons for media software.\n${NC}"
echo -e "Use with no arguements to enter the GUI."
echo -e "${WARN}WARNING: This is very slow on big libraries! Consider --target${NC}"
echo -e "USAGE: bmm-media_permissions [-arg] [--arg]\n"
echo -e " -a [--audio] -> Fix all audio permissions."
echo -e " -s [--series] -> Fix all series permissions."
echo -e " -m [--movies] -> Fix all movies permissions."
echo -e " -c [--concerts] -> Fix all concerts permissions."
echo -e " -u [--stand-up] -> Fix all stand-up permissions."
echo -e " -t [--target] -> Manually enter desired settings. (recursive)"
echo -e " Usage: bmm-media_permissions [-t] [--target] /dir/path user group${NC}"
echo -e " -f [--full] -> Fix all media permissions. USE WITH CAUTION."
echo -e " -h [--help] -> Shows this screen."
else
main_menu;
fi