67 lines
1.3 KiB
Bash
Executable File
67 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
root_dir="/home/$USER/DownloadsMusic"
|
|
share_dir="/home/$USER/music_share"
|
|
|
|
check_dir(){
|
|
|
|
if [[ ! -d $root_dir ]]; then
|
|
echo -e "Creando directorio root"
|
|
mkdir $root_dir
|
|
fi
|
|
if [[ ! -d $share_dir ]]; then
|
|
echo -e "Creando directorio share"
|
|
mkdir $share_dir
|
|
fi
|
|
}
|
|
|
|
|
|
check_zip(){
|
|
flac_ex=$(ls $root_dir | grep -i .flac)
|
|
zip_ex=$(ls $root_dir | grep -i .zip)
|
|
if [[ -z $zip_ex && -z $flac_ex ]];then
|
|
echo "No se encontraron archivos"
|
|
exit 1
|
|
fi
|
|
if [[ -z $flac_ex ]]; then
|
|
echo "No se encontraron archivos con la extensión '.flac'"
|
|
else
|
|
echo "Exportando .flac"
|
|
mv $root_dir/*.flac $share_dir
|
|
fi
|
|
if [[ -z $zip_ex ]]; then
|
|
echo "No se encontraron archivos con la extensión '.zip'"
|
|
else
|
|
state="True"
|
|
echo "Exportando .zip"
|
|
mv $root_dir/*.zip $share_dir
|
|
export_music "$state" "$IP"
|
|
fi
|
|
}
|
|
|
|
|
|
export_music(){
|
|
local state=$1
|
|
cd $share_dir
|
|
if [[ "$state" == "True" ]]; then
|
|
cd $share_dir
|
|
unzip -o '*.zip'
|
|
fi
|
|
rsync -r --no-g --no-p -v --include='*/' --include='*.m4a' --include='*.jpg' --include='*.flac' --include='*.lrc' --exclude='*' -e "ssh -p $PORT" $share_dir/. user@$IP:/server/music
|
|
rm -rf $share_dir/**
|
|
}
|
|
|
|
main() {
|
|
check_dir
|
|
if [[ -z $1 ]]; then
|
|
IP=""
|
|
PORT="22"
|
|
else
|
|
IP=$1
|
|
PORT=$2
|
|
fi
|
|
check_zip
|
|
}
|
|
|
|
main "$@"
|