1#!/usr/bin/env bash 2# 3# SPDX-License-Identifier: GPL-2.0-only 4# 5 6help () 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 15clean_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 23do_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 41do_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 53do_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 92case $2 in 93*.conf|*.inc) 94 ;; 95*) 96 echo ERROR: $2 must end with .conf or .inc! 97 exit 1 98 ;; 99esac 100 101case $1 in 102export) 103 do_export $2 104 ;; 105import) 106 do_import $2 107 ;; 108migrate_localcount) 109 do_migrate_localcount 110 ;; 111*) 112 help 113 exit 1 114 ;; 115esac 116