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