-
Notifications
You must be signed in to change notification settings - Fork 2
/
bmm-media_share
executable file
·146 lines (127 loc) · 4.93 KB
/
bmm-media_share
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
#!/bin/bash
## A better way to choose media to share with friends or backup
## checklist select of folders to copy to another set location
## Tarso Galvao 06/04/23 Debian 11
## 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
copy_media (){
if ! command -v $BANNER >> /dev/null; then echo -e "${WARN}BASH MEDIA MANAGER${NC}"; else eval $BANNER; fi
echo -e "${HEAD}Media Share${NC}"
echo '----------------------------------------------------------'
dep_check rsync; ## TODO: check for rsync (dest should have rsync too... how to confirm?)
echo -e "${WARN}Now running: ${OK}rsync -avzP ${WARN}$source ${OK}$dest${NC}"
echo '----------------------------------------------------------'
echo -e "\n${ERROR}Press ${WARN}'Control + C'${ERROR} to abort.${NC}"
for (( i=3; i>0; i--)); do sleep 1 & printf " $i \r"; wait; done
## start syncing
eval $(echo -e "rsync -avzP $source $dest") | dialog --colors --no-lines --backtitle "\Z7Bash Media Manager" --progressbox 42 76;
dialog --colors --no-lines \
--backtitle "\Z7Bash Media Manager" \
--infobox "Task complete." 3 19
read
}
## get lines chosen and print dir name in quotes for cp/rsync command
get_selections () { #$1-folder_content.txt $2-line number $3-media rootfolder
dir_list="$1" #list of all folders on dirs
line_choice=$2 #list of all lines (folders) chosen
i=0 #reset start line to read
while read line; do
((i++))
test $i = $line_choice && echo "$3\"$line\" "; #list of choices for array
done < "$dir_list"
}
## create checklist with directory(root_dir) contents
create_checklist () {
## create a file in root folder with its folders
if [ -f $1.folder_content.txt ]; then rm $1.folder_content.txt;
else eval $(touch $1.folder_content.txt); fi
ls $1 >> $1.folder_content.txt
## create dynamic options for each dir
c=0 #reset counter
while IFS=$'\n' read -r line; do c=$(expr $c + 1); options+=($c "$line" off); done < $1.folder_content.txt
## print options (dialog checklist)
checklist=(dialog --no-lines --separate-output --colors \
--backtitle "\Z7Bash Media Manager" \
--title "Media Share" \
--checklist "Select content(s):" 22 76 16)
choices=$("${checklist[@]}" "${options[@]}" 2>&1 >/dev/tty)
clear
## create array with choice results
if [ "$choices" != "" ]; then
for choice in $choices
do #get_selections() $1-folder_content.txt $2-line number $3-rootfolder
source+=$(get_selections $1.folder_content.txt $choice $1);
done
else #return to launcher
echo -e "${ERROR}No selection, aborting...${NC}"; sleep 2;
clear && eval bmm-launcher; exit 1;
fi
## set destination (user input dialog)
dest=$(dialog --no-lines --colors \
--backtitle "\Z7Bash Media Manager" \
--title "Media Share" \
--inputbox "Enter destination full path: \n \
(ex.: /full/path/to/dir/ or user@ip.ad.dr.ess:/location/ )" 10 40 \
3>&1 1>&2 2>&3 3>&-)
clear
## copy CHOICES to DESTINATION
if [ "$dest" != "" ]; then
copy_media $source $dest;
clear && eval bmm-launcher; exit 0;
else #return to launcher
echo -e "${ERROR}No destination, aborting...${NC}"; sleep 2;
clear && eval bmm-launcher; exit 1;
fi
}
## choose media type to share (interactive mode)
main_menu () {
root_dir=$(dialog --no-lines --stdout --colors \
--backtitle "\Z7Bash Media Manager" \
--title "Media Share" \
--menu 'Select media source:' 0 0 0 \
$AUDIOROOT 'Audio/Music' \
$SERIESROOT 'Series' \
$MOVIESROOT 'Movies' \
$CONCERTSROOT 'Concerts' \
$STANDUPROOT 'Stand-up' \
Quit '')
## Exit on Quit or Cancel || Execute chosen script.
if [ $root_dir = 'Quit' ] || [ $? -ne 1 ]; then
clear && eval bmm-launcher; exit 0;
else
dir_check "$root_dir"
create_checklist $root_dir;
fi
}
## STARTUP OPTIONS
if [ "$1" = '-a' ] || [ "$1" = '--audio' ]; then
create_checklist $AUDIOROOT;
elif [ "$1" = '-s' ] || [ "$1" = '--series' ]; then
create_checklist $SERIESROOT;
elif [ "$1" = '-m' ] || [ "$1" = '--movies' ]; then
create_checklist $MOVIESROOT;
elif [ "$1" = '-c' ] || [ "$1" = '--concerts' ]; then
create_checklist $CONCERTSROOT;
elif [ "$1" = '-u' ] || [ "$1" = '--stand-up' ]; then
create_checklist $STANDUPROOT;
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 Share"
echo -e "${OK}Easily share server media to other devices.\n${NC}"
echo -e "Use with no arguements to enter the GUI."
echo -e "USAGE: bmm-media_share [-arg] [--arg]\n"
echo -e " -a [--audio] -> Choose AUDIO to share."
echo -e " -s [--series] -> Choose SERIES to share."
echo -e " -m [--movies] -> Choose MOVIES to share."
echo -e " -c [--concerts] -> Choose CONCERTS to share."
echo -e " -u [--stand-up] -> Choose STAND-UP to share."
echo -e " -h [--help] -> Shows this screen."
else
main_menu;
fi