Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | help () |
| 4 | { |
| 5 | base=`basename $0` |
| 6 | echo -e "Usage: $base command" |
| 7 | echo "Avaliable commands:" |
| 8 | echo -e "\texport <file.conf>: export and lock down the AUTOPR values from the PR service into a file for release." |
| 9 | echo -e "\timport <file.conf>: import the AUTOPR values from the exported file into the PR service." |
| 10 | } |
| 11 | |
| 12 | clean_cache() |
| 13 | { |
| 14 | s=`bitbake -e | grep ^CACHE= | cut -f2 -d\"` |
| 15 | if [ "x${s}" != "x" ]; then |
| 16 | rm -rf ${s} |
| 17 | fi |
| 18 | } |
| 19 | |
| 20 | do_export () |
| 21 | { |
| 22 | file=$1 |
| 23 | [ "x${file}" == "x" ] && help && exit 1 |
| 24 | rm -f ${file} |
| 25 | |
| 26 | clean_cache |
| 27 | bitbake -R conf/prexport.conf -p |
| 28 | s=`bitbake -R conf/prexport.conf -e | grep ^PRSERV_DUMPFILE= | cut -f2 -d\"` |
| 29 | if [ "x${s}" != "x" ]; |
| 30 | then |
| 31 | [ -e $s ] && mv -f $s $file && echo "Exporting to file $file succeeded!" |
| 32 | return 0 |
| 33 | fi |
| 34 | echo "Exporting to file $file failed!" |
| 35 | return 1 |
| 36 | } |
| 37 | |
| 38 | do_import () |
| 39 | { |
| 40 | file=$1 |
| 41 | [ "x${file}" == "x" ] && help && exit 1 |
| 42 | |
| 43 | clean_cache |
| 44 | bitbake -R conf/primport.conf -R $file -p |
| 45 | ret=$? |
| 46 | [ $ret -eq 0 ] && echo "Importing from file $file succeeded!" || echo "Importing from file $file failed!" |
| 47 | return $ret |
| 48 | } |
| 49 | |
| 50 | do_migrate_localcount () |
| 51 | { |
| 52 | df=`bitbake -R conf/migrate_localcount.conf -e | \ |
| 53 | grep ^LOCALCOUNT_DUMPFILE= | cut -f2 -d\"` |
| 54 | if [ "x${df}" == "x" ]; |
| 55 | then |
| 56 | echo "LOCALCOUNT_DUMPFILE is not defined!" |
| 57 | return 1 |
| 58 | fi |
| 59 | |
| 60 | rm -rf $df |
| 61 | clean_cache |
| 62 | echo "Exporting LOCALCOUNT to AUTOINCs..." |
| 63 | bitbake -R conf/migrate_localcount.conf -p |
| 64 | [ ! $? -eq 0 ] && echo "Exporting to file $df failed!" && exit 1 |
| 65 | |
| 66 | if [ -e $df ]; |
| 67 | then |
| 68 | echo "Exporting to file $df succeeded!" |
| 69 | else |
| 70 | echo "Exporting to file $df failed!" |
| 71 | exit 1 |
| 72 | fi |
| 73 | |
| 74 | echo "Importing generated AUTOINC entries..." |
| 75 | [ -e $df ] && do_import $df |
| 76 | |
| 77 | if [ ! $? -eq 0 ] |
| 78 | then |
| 79 | echo "Migration from LOCALCOUNT to AUTOINCs failed!" |
| 80 | return 1 |
| 81 | fi |
| 82 | |
| 83 | echo "Migration from LOCALCOUNT to AUTOINCs succeeded!" |
| 84 | return 0 |
| 85 | } |
| 86 | |
| 87 | [ $# -eq 0 ] && help && exit 1 |
| 88 | |
| 89 | case $1 in |
| 90 | export) |
| 91 | do_export $2 |
| 92 | ;; |
| 93 | import) |
| 94 | do_import $2 |
| 95 | ;; |
| 96 | migrate_localcount) |
| 97 | do_migrate_localcount |
| 98 | ;; |
| 99 | *) |
| 100 | help |
| 101 | exit 1 |
| 102 | ;; |
| 103 | esac |