summaryrefslogtreecommitdiff
path: root/syncmusic-interactive
blob: 887c6677604a0337908c671e6b372be78816047e (plain)
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
#!/bin/bash
REMOTE=root@canonical.aberrantflux.xyz
REMOTEDIR=/srv/music
LOCALDIR=$(pwd)
WHITE="\033[37m"
GREEN="\033[32m"
BLUE="\033[35m"
rm /tmp/remotemusiclist
rm /tmp/localmusiclist
rm /tmp/localonlymusicd
rm /tmp/syncmusictorun
echo "Remote directory is at $REMOTE:$REMOTEDIR"
echo "Local dir is at $LOCALDIR"
LOCALDISCOVERED=()
LOCALCOUNT=0

for D in $(ls)
do
	for D2 in $(ls $D)
	do
		LOCALCOUNT=$((LOCALCOUNT+1))
		LOCALDISCOVERED+=($D/$D2)
	done
done

ssh $REMOTE "
cd $REMOTEDIR
REMOTEDISCOVERED=()
REMOTECOUNT=0

for D in \$(ls)
do
	for D2 in \$(ls \$D)
	do
		REMOTECOUNT=\$((REMOTECOUNT+1))
		REMOTEDISCOVERED+=(\$D/\$D2)
	done
done
for (( i = 0 ; i <= \$REMOTECOUNT ; i++ ))
do
	echo \${REMOTEDISCOVERED[\$i]}
done
" > /tmp/remotemusiclist

touch /tmp/localonlymusicd
LOCALONLYCOUNT=0
LOCALONLYMUSIC=()
UNSYNCCOUNT=0
for (( i = 0 ; i <= $LOCALCOUNT-1 ; i++ ))
do
	echo ${LOCALDISCOVERED[$i]} >> /tmp/localmusiclist
	if grep -xq ${LOCALDISCOVERED[$i]} /tmp/remotemusiclist
	then
		echo -e "$WHITE${LOCALDISCOVERED[$i]}"
	else
		UNSYNCCOUNT=$((UNSYNCCOUNT+1))
		LOCALONLYCOUNT=$((LOCALONLYCOUNT+1))
		echo "$UNSYNCCOUNT. ${LOCALDISCOVERED[$i]}" >> /tmp/localonlymusicd
		LOCALONLYMUSIC+=(${LOCALDISCOVERED[$i]})
	fi
done
echo -e $BLUE
cat /tmp/localonlymusicd
REMOTEONLYCOUNT=0
REMOTEONLYMUSIC=()
while read p; do
	if  [[ $p != "" ]]
	then
		if [ $LOCALCOUNT = 0 ] || ! grep -xq $p /tmp/localmusiclist
		then
			UNSYNCCOUNT=$((UNSYNCCOUNT+1))
			REMOTEONLYCOUNT=$((REMOTEONLYCOUNT+1))
			echo -e "$GREEN$UNSYNCCOUNT. $p"
			REMOTEONLYMUSIC+=($p)
		fi
	fi
done < /tmp/remotemusiclist
echo -e $WHITE

echo "Discovered $UNSYNCCOUNT unsynced albums"
if [ $UNSYNCCOUNT = 0 ]
then
	exit
fi
echo "Albums in BLUE are those that are only on the local machine. Albums in GREEN are those that are only on the remote machine. Albums in WHITE are those that are on both"
read -p "Enter the indexes corresponding to the albums you wish to sync, separated by spaces: " INPUT

for j in ${INPUT}
do
	if (( j <= $LOCALONLYCOUNT ))
	then
		FDIR=$LOCALDIR/${LOCALONLYMUSIC[$((j-1))]}
		TDIR=$REMOTE:$REMOTEDIR/${LOCALONLYMUSIC[$((j-1))]}
		COMMAND="rsync -avzP --mkpath $FDIR $TDIR"
		echo "$COMMAND" >> /tmp/syncmusictorun
	else
		FDIR=$REMOTE:$REMOTEDIR/${REMOTEONLYMUSIC[$(($j-$LOCALONLYCOUNT-1))]}
		TDIR=$LOCALDIR/${REMOTEONLYMUSIC[$(($j-$LOCALONLYCOUNT-1))]}
		COMMAND="rsync -avzP --mkpath $FDIR $TDIR"
		echo "$COMMAND" >> /tmp/syncmusictorun
	fi
done
echo "WILL RUN: $(cat /tmp/syncmusictorun)"
read -p "Enter y to confirm: " CONFIRM
if [[ $CONFIRM = y ]]
then
	source /tmp/syncmusictorun
fi
rm /tmp/remotemusiclist
rm /tmp/localmusiclist
rm /tmp/localonlymusicd
rm /tmp/syncmusictorun