Skip to content

Commit b607124

Browse files
committed
move works now
1 parent afb8686 commit b607124

File tree

3 files changed

+128
-23
lines changed

3 files changed

+128
-23
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ Operation completed 40 scans.
3939
35 intact releases.
4040
```
4141
42+
### Anti-features
43+
So this script assumes some things, for example does it assume that you store files in
44+
a flat style - ie: `/path/to/$(movie_storage)/$(movie)` or for music `/path/to/$(music_storage)/$(album)`.
45+
46+
* file storage layout
47+
* movie/music directories containing sub folders like DISK1 and DISK2 is currently being blacklisted aswell.
48+
4249
### TODOs
4350
4451
- [ ] show percentage completion in margin #progressbar

ideal.sh

+117-14
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,35 @@ source lib/helper.sh
1616
menu(){
1717

1818
target=""
19-
move="~/"
20-
write=false
19+
__move=""
20+
__write=false
2121
verbose=false
2222

23-
while getopts ":t:r:mwvh" opt; do
23+
while getopts ":t:r:m:wivh" opt; do
2424
case $opt in
2525
t)
26-
target=$OPTARG
26+
target="$OPTARG"
2727
;;
2828
r)
29-
rlstype=$OPTARG
29+
rlstype="$OPTARG"
3030
;;
3131
m)
32-
if [[ -d $OPTARG ]] && [[ ! -z $OPTARG ]];then
33-
move=$OPTARG
34-
else
35-
move=$move
36-
fi
32+
__move="$OPTARG"
3733
;;
3834
w)
3935
if $OPT;then
40-
write=true
36+
__write=true
37+
printf '%s\n' "Write mode: $__write"
4138
else
42-
write=false
39+
__write=false
40+
fi
41+
;;
42+
i)
43+
if ! [[ $OPT ]];then
44+
__interactive=true
45+
elif [[ $OPT ]];then
46+
__interactive=false
4347
fi
44-
printf "Write mode: $write\n"
4548
;;
4649
h)
4750
helpmsg
@@ -72,13 +75,13 @@ helpmsg(){
7275
# just a simple help screen
7376
# not valid anymore anyways
7477

75-
echo -e "\n"
7678
echo -e "\tideal.sh\n"
7779
echo -e "\tUsage:"
7880
echo -e "\t$0 -t /path/to/target -v\n"
7981

8082
echo -e "\t-m" "\t" "Directory to move broken releases into."
8183
echo -e "\t-w" "\t" "Writable mode, default doesnt touch anything."
84+
echo -e "\t-i" "\t" "When flag is passed interactive mode will be disabled."
8285
echo -e "\t-v" "\t" "Toggles verbose output aka also printing successful."
8386
echo -e "\t-r" "\t" "Specify type of release. ie: mp3 or movie."
8487
echo -e "\t-h" "\t" "Prints this message.\n"
@@ -100,6 +103,8 @@ make_list_of_failed(){
100103
rm $LOGPATH
101104
touch $LOGPATH
102105
fi
106+
107+
printf '%s\n' "--------------------------------[ CORRUPT ]--------------------------------"
103108
for BROKEN in ${failed[@]};do
104109
if [ -d $BROKEN ];then
105110
echo -en "$BROKEN" "\n" >> $LOGPATH
@@ -109,6 +114,7 @@ make_list_of_failed(){
109114
fi
110115
done
111116

117+
printf '%s\n' "-------------------------------[ INCOMPLETE ]------------------------------"
112118
for INCOMPLETE in ${incomplete[@]};do
113119
if [ -d $INCOMPLETE ];then
114120
echo -en "$INCOMPLETE" "\n" >> $LOGPATH
@@ -157,6 +163,88 @@ listfiles() {
157163
}
158164

159165

166+
create_temp_dir(){
167+
168+
# takes $1 param as output directory
169+
# creates two sub dirs within that.
170+
171+
printf '%s\n' "$1"
172+
173+
if [[ ! -d "$1" ]];then
174+
mkdir -p "$1"
175+
fi
176+
177+
if [[ ! -z "$1" ]] && [[ -d $1 ]];then
178+
output="$1"
179+
else
180+
printf '%s\n' "Something wrong with output directory. Quitting."
181+
exit 1
182+
fi
183+
184+
if [[ ! -z $2 ]];then
185+
new="$output/$2"
186+
else
187+
printf '%s\n' "Seems to be missing an argument. Quitting."
188+
exit 1
189+
fi
190+
191+
192+
if [[ ! -d "$new" ]];then
193+
printf '%s\n' "$new does not exist, creating it."
194+
mkdir -p "$new"
195+
fi
196+
197+
198+
}
199+
200+
move_broken(){
201+
202+
OLDIFS=$IFS
203+
IFS=$(echo -en "\n\b")
204+
205+
206+
#mv_opt="-r"
207+
208+
#if [[ "$3" == true ]];then
209+
# mv_opt="-ri"
210+
#elif [[ "$3" == false ]];then
211+
# mv_opt="-r"
212+
#fi
213+
214+
# for all the corrupt releases
215+
if [[ ${#failed[@]} == 0 ]];then
216+
printf '%s\n' "broken rls: ${#failed[@]}"
217+
else
218+
for crpt in "${failed[@]}"; do
219+
if [[ -d "${crpt}" ]];then
220+
printf '%s\n' "Moved $crpt to $__move/broken/"
221+
mv "$crpt" "$__move/broken/"
222+
else
223+
printf '%s\n' "Failed to remove: $crpt"
224+
printf '%s\n' "Did the folder move?"
225+
fi
226+
done
227+
fi
228+
229+
# for all the incomplete releases
230+
if [[ ${#incomplete[@]} == 0 ]];then
231+
printf '%s\n' "incomplete rls: ${#incomplete[@]}"
232+
else
233+
for inco in "${incomplete[@]}"; do
234+
if [[ -d "${inco}" ]];then
235+
printf '%s%s\n' "Moved $inco to $__move/incomplete"
236+
mv "$inco" "$__move/incomplete/"
237+
else
238+
printf '%s\n' "Failed to remove: $inco"
239+
printf '%s\n' "Did the folder move?"
240+
fi
241+
done
242+
fi
243+
244+
245+
IFS=${OLDIFS}
246+
}
247+
160248
runnable(){
161249

162250
OLDIFS=$IFS
@@ -207,3 +295,18 @@ runnable(){
207295

208296
menu "$@"
209297
runnable "$target" "$rlstype"
298+
if [[ ! -z "$__move" ]] && [[ "$__write" == true ]];then
299+
printf '%s\n' "BEFORE $__move"
300+
301+
if [[ ! ${#broken[@]} == 0 ]];then
302+
create_temp_dir "$__move" "broken"
303+
fi
304+
305+
if [[ ! ${#incomplete[@]} == 0 ]];then
306+
create_temp_dir "$__move" "incomplete"
307+
fi
308+
309+
move_broken "${failed[@]}" "${incomplete[@]}" "$__move"
310+
else
311+
printf '%s\n' "Requirements not met."
312+
fi

lib/helper.sh

+4-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ make_lists() {
3333
# m3u
3434
if [ "${xy##*.}" = "m3u" ];then
3535
if [[ $__m3u == true ]];then
36-
printf '%s\n' "Already got a M3U file."
36+
#printf '%s\n' "Already got a M3U file."
3737
continue
3838
else
3939
#printf '%s\n' "M3U = TRUE"
@@ -44,7 +44,7 @@ make_lists() {
4444
# nfo
4545
if [ ${xy##*.} = "nfo" ];then
4646
if [[ $__nfo == true ]];then
47-
printf '%s\n' "Already got a NFO file."
47+
#printf '%s\n' "Already got a NFO file."
4848
continue
4949
else
5050
__nfo=true
@@ -55,7 +55,7 @@ make_lists() {
5555
# sfv
5656
if [ "${xy##*.}" = "sfv" ];then
5757
if [[ $__sfv == true ]];then
58-
printf '%s\n' "Already got a SFV file."
58+
#printf '%s\n' "Already got a SFV file."
5959
continue
6060
else
6161
#printf '%s\n' "SFV = TRUE"
@@ -66,7 +66,7 @@ make_lists() {
6666
# mp3
6767
if [ "${xy##*.}" = "mp3" ];then
6868
if [[ $__mp3 == true ]];then
69-
printf '%s\n' "Already got a mp3 file."
69+
#printf '%s\n' "Already got a mp3 file."
7070
continue
7171
else
7272
__mp3=true
@@ -91,11 +91,6 @@ make_lists() {
9191
files_found=("$directory"/*.''@(sfv|nfo|rar)'')
9292
shopt -u nullglob extglob nocaseglob
9393

94-
#for a in $directory_list;do
95-
# printf '%s\n' "$a"
96-
#done
97-
98-
9994
for xy in "${files_found[@]}";do
10095

10196
# nfo

0 commit comments

Comments
 (0)