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