1#!/bin/bash 2 3# 4# Copyright (C) 2011 The Android Open Source Project 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17 18 19 20 21# This script queries a media provider database, and generates a script to 22# approximately recreate the same file system structure on another device, 23# using dummy files. 24 25EXTERNAL=$2 26if [ "$EXTERNAL" == "" ] 27then 28 EXTERNAL="/storage" 29fi 30 31 32if [ "$ANDROID_HOST_OUT" == "" ] 33then 34 echo "Couldn't find sqlite3. Please run envsetup/lunch and build." 35 exit 1 36fi 37 38if [ "$1" == "" ] 39then 40 echo "Usage: $0 <file.db> [external storage root]" 41 exit 2 42fi 43 44if [ ! -f "$1" ] 45then 46 echo "Couldn't find file $1" 47 exit 3 48fi 49 50# generate script to generate directory structure and content 51$ANDROID_HOST_OUT/bin/sqlite3 $1 "select format, media_type, mime_type, _data from files where _data like '"$EXTERNAL"/%';" | { 52 53MKDIRS=/tmp/mkdirs$$ 54CPFILES=/tmp/cpfiles$$ 55 56IFS="|" 57while read format mediatype mimetype data; 58do 59 if [ "$format" == "14337" ] 60 then 61 # jpeg 62 echo "cat /storage/sdcard0/proto.jpg > \"$data\"" >> $CPFILES 63 elif [ "$format" == "14347" ] 64 then 65 # png 66 echo "cat /storage/sdcard0/proto.png > \"$data\"" >> $CPFILES 67 elif [ "$format" == "14343" -a "$mediatype" == "0" ] 68 then 69 # gif 70 echo "cat /storage/sdcard0/proto.gif > \"$data\"" >> $CPFILES 71 elif [ "$format" == "12292" -a "$mediatype" == "0" ] 72 then 73 # txt 74 echo "cat /storage/sdcard0/proto.txt > \"$data\"" >> $CPFILES 75 elif [ "$format" == "12293" -a "$mediatype" == "0" ] 76 then 77 # html 78 echo "cat /storage/sdcard0/proto.html > \"$data\"" >> $CPFILES 79 elif [ "$format" == "12297" ] 80 then 81 # mp3 82 echo "cat /storage/sdcard0/proto.mp3 > \"$data\"" >> $CPFILES 83 elif [ "$format" == "12296" ] 84 then 85 # wav 86 echo "cat /storage/sdcard0/proto.wav > \"$data\"" >> $CPFILES 87 elif [ "$format" == "12299" -a "$mediatype" == "0" ] 88 then 89 # m4v 90 echo "cat /storage/sdcard0/proto.m4v > \"$data\"" >> $CPFILES 91 elif [ "$format" == "12299" -a "$mediatype" == "3" ] 92 then 93 # mp4 94 echo "cat /storage/sdcard0/proto.m4v > \"$data\"" >> $CPFILES 95 elif [ "$format" == "12299" -a "$mediatype" == "2" ] 96 then 97 # m4a 98 echo "cat /storage/sdcard0/proto.m4a > \"$data\"" >> $CPFILES 99 elif [ "$format" == "47492" ] 100 then 101 # 3gp 102 echo "cat /storage/sdcard0/proto.3gp > \"$data\"" >> $CPFILES 103 elif [ "$format" == "47362" -a "$mediatype" == "2" ] 104 then 105 # ogg 106 echo "cat /storage/sdcard0/proto.ogg > \"$data\"" >> $CPFILES 107 elif [ "$format" == "12288" -a "$mediatype" == "0" ] 108 then 109 # unknown type 110 echo "cat /storage/sdcard0/proto.dat > \"$data\"" >> $CPFILES 111 elif [ "$format" == "12289" -a "$mediatype" == "0" ] 112 then 113 # directory, ignore 114 true 115 elif [ "$format" == "12288" -a "$mediatype" == "4" ] 116 then 117 # playlist, ignore 118 true 119 else 120 echo ignored: $format '|' $mediatype '|' $mimetype '|' $data 121 fi 122 echo mkdir -p \"$(dirname $data)\" >> $MKDIRS 123done 124 125sort -u $MKDIRS > mkfiles.sh 126cat $CPFILES >> mkfiles.sh 127rm -rf $MKDIRS $CPFILES 128 129} 130 131# generate playlist files 132$ANDROID_HOST_OUT/bin/sqlite3 $1 "select audio_playlists._data, audio._data from audio_playlists left outer join audio_playlists_map on audio_playlists._id=audio_playlists_map.playlist_id left outer join audio on audio_playlists_map.audio_id=audio._id order by audio_playlists_map.playlist_id,audio_playlists_map.play_order;" | { 133 134IFS="|" 135while read plist entry 136do 137 echo "echo \"$(basename $entry)\" >> \"$plist\"" >> mkfiles.sh 138done 139} 140 141echo mkfiles.sh generated. Now run: 142grep sdcard0\/proto mkfiles.sh |sed 's/cat \/storage\/sdcard0\//adb push /' | sed 's/ > .*/ \/storage\/sdcard0/'|sort -u 143echo adb push mkfiles.sh /storage/sdcard0 144echo adb shell sh /storage/sdcard0/mkfiles.sh 145 146