#!/bin/bash dbhost="localhost" dbuser="kodi" dbpassword="kodi" kodihome="/home/kodi" if [[ $# -lt 2 ]] || [[ $# -gt 2 ]] then echo "Usage: ${0##*/} old_path new_path" echo "Escape special characters in paths or enclose in double quotes" exit 0 fi echo -e "Updating Kodi media sources \nfrom '$1' \nto '$2'" read -r -p "Are you sure? [y/N] " response response=${response,,} # tolower if [[ ! "$response" =~ ^(yes|y)$ ]] then exit 0 fi #find highest numeric MyVideos / MyMusic db videodb=$(mysql -h$dbhost -u$dbuser -p$dbpassword -e "show databases like 'MyVideos%';" 2>/dev/null | sort -g -r | head -1) audiodb=$(mysql -h$dbhost -u$dbuser -p$dbpassword -e "show databases like 'MyMusic%';" 2>/dev/null | sort -g -r | head -1) texturedb=$(ls $kodihome/.kodi/userdata/Database/Textures* | sort -g -r | head -1) echo "Databases to adjust: $videodb $audiodb "$(basename $texturedb)" ..." # Escaping paths for MySQL/SQLite3 inserts printf -v from "%q" "$1" printf -v to "%q" "$2" # updating databases echo "Updating mysql databases from '$1' to '$2' ..." #exit 0 mysql -h$dbhost -u$dbuser -p$dbpassword 2>/dev/null <