| 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\"` | 
| Patrick Williams | b9af875 | 2023-01-30 13:28:01 -0600 | [diff] [blame] | 20 |     # Stop any active memory resident server | 
 | 21 |     bitbake -m | 
 | 22 |     # Remove cache entries since we want to trigger a full reparse | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 |     if [ "x${s}" != "x" ]; then | 
| Patrick Williams | b9af875 | 2023-01-30 13:28:01 -0600 | [diff] [blame] | 24 |         rm -f ${s}/bb_cache*.dat.* | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 |     fi | 
 | 26 | } | 
 | 27 |  | 
 | 28 | do_export () | 
 | 29 | { | 
 | 30 |     file=$1 | 
 | 31 |     [ "x${file}" == "x" ] && help && exit 1 | 
 | 32 |     rm -f ${file} | 
 | 33 |  | 
 | 34 |     clean_cache | 
 | 35 |     bitbake -R conf/prexport.conf -p | 
 | 36 |     s=`bitbake -R conf/prexport.conf -e | grep ^PRSERV_DUMPFILE= | cut -f2 -d\"` | 
 | 37 |     if [ "x${s}" != "x" ]; | 
 | 38 |     then | 
 | 39 |        [ -e $s ] && mv -f $s $file && echo "Exporting to file $file succeeded!" | 
 | 40 |        return 0 | 
 | 41 |     fi | 
 | 42 |     echo "Exporting to file $file failed!" | 
 | 43 |     return 1 | 
 | 44 | } | 
 | 45 |  | 
 | 46 | do_import () | 
 | 47 | { | 
 | 48 |     file=$1 | 
 | 49 |     [ "x${file}" == "x" ] && help && exit 1 | 
 | 50 |  | 
 | 51 |     clean_cache | 
 | 52 |     bitbake -R conf/primport.conf -R $file -p | 
 | 53 |     ret=$? | 
 | 54 |     [ $ret -eq 0 ] && echo "Importing from file $file succeeded!" || echo "Importing from file $file failed!" | 
 | 55 |     return $ret | 
 | 56 | } | 
 | 57 |  | 
 | 58 | do_migrate_localcount () | 
 | 59 | { | 
 | 60 |     df=`bitbake -R conf/migrate_localcount.conf -e | \ | 
 | 61 |                 grep ^LOCALCOUNT_DUMPFILE= | cut -f2 -d\"` | 
 | 62 |     if [ "x${df}" == "x" ]; | 
 | 63 |     then | 
 | 64 |         echo "LOCALCOUNT_DUMPFILE is not defined!" | 
 | 65 |         return 1 | 
 | 66 |     fi | 
 | 67 |  | 
| Patrick Williams | b9af875 | 2023-01-30 13:28:01 -0600 | [diff] [blame] | 68 |     rm -f $df | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 |     clean_cache | 
 | 70 |     echo "Exporting LOCALCOUNT to AUTOINCs..." | 
 | 71 |     bitbake -R conf/migrate_localcount.conf -p | 
 | 72 |     [ ! $? -eq 0 ] && echo "Exporting to file $df failed!" && exit 1 | 
 | 73 |  | 
 | 74 |     if [ -e $df ]; | 
 | 75 |     then | 
 | 76 |         echo "Exporting to file $df succeeded!" | 
 | 77 |     else | 
 | 78 |         echo "Exporting to file $df failed!" | 
 | 79 |         exit 1 | 
 | 80 |     fi | 
 | 81 |      | 
 | 82 |     echo "Importing generated AUTOINC entries..." | 
 | 83 |     [ -e $df ] && do_import $df | 
 | 84 |  | 
 | 85 |     if [ ! $? -eq 0 ] | 
 | 86 |     then | 
 | 87 |         echo "Migration from LOCALCOUNT to AUTOINCs failed!" | 
 | 88 |         return 1 | 
 | 89 |     fi | 
 | 90 |  | 
 | 91 |     echo "Migration from LOCALCOUNT to AUTOINCs succeeded!" | 
 | 92 |     return 0 | 
 | 93 | } | 
 | 94 |  | 
 | 95 | [ $# -eq 0 ] && help  && exit 1 | 
 | 96 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 97 | case $2 in | 
 | 98 | *.conf|*.inc) | 
 | 99 |     ;; | 
 | 100 | *) | 
 | 101 |     echo ERROR: $2 must end with .conf or .inc! | 
 | 102 |     exit 1 | 
 | 103 |     ;; | 
 | 104 | esac | 
 | 105 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 106 | case $1 in | 
 | 107 | export) | 
 | 108 |     do_export $2 | 
 | 109 |     ;; | 
 | 110 | import) | 
 | 111 |     do_import $2 | 
 | 112 |     ;; | 
 | 113 | migrate_localcount) | 
 | 114 |     do_migrate_localcount | 
 | 115 |     ;; | 
 | 116 | *) | 
 | 117 |     help | 
 | 118 |     exit 1 | 
 | 119 |     ;; | 
 | 120 | esac |