1eb8dc403SDave Cobbley#!/usr/bin/env bash 2c342db35SBrad Bishop# 392b42cb3SPatrick Williams# Copyright OpenEmbedded Contributors 492b42cb3SPatrick Williams# 5c342db35SBrad Bishop# SPDX-License-Identifier: GPL-2.0-only 6c342db35SBrad Bishop# 7eb8dc403SDave Cobbley 8eb8dc403SDave Cobbleyhelp () 9eb8dc403SDave Cobbley{ 10eb8dc403SDave Cobbley base=`basename $0` 11eb8dc403SDave Cobbley echo -e "Usage: $base command" 12eb8dc403SDave Cobbley echo "Avaliable commands:" 13eb8dc403SDave Cobbley echo -e "\texport <file.conf>: export and lock down the AUTOPR values from the PR service into a file for release." 14eb8dc403SDave Cobbley echo -e "\timport <file.conf>: import the AUTOPR values from the exported file into the PR service." 15eb8dc403SDave Cobbley} 16eb8dc403SDave Cobbley 17eb8dc403SDave Cobbleyclean_cache() 18eb8dc403SDave Cobbley{ 19eb8dc403SDave Cobbley s=`bitbake -e | grep ^CACHE= | cut -f2 -d\"` 20*b9af8750SPatrick Williams # Stop any active memory resident server 21*b9af8750SPatrick Williams bitbake -m 22*b9af8750SPatrick Williams # Remove cache entries since we want to trigger a full reparse 23eb8dc403SDave Cobbley if [ "x${s}" != "x" ]; then 24*b9af8750SPatrick Williams rm -f ${s}/bb_cache*.dat.* 25eb8dc403SDave Cobbley fi 26eb8dc403SDave Cobbley} 27eb8dc403SDave Cobbley 28eb8dc403SDave Cobbleydo_export () 29eb8dc403SDave Cobbley{ 30eb8dc403SDave Cobbley file=$1 31eb8dc403SDave Cobbley [ "x${file}" == "x" ] && help && exit 1 32eb8dc403SDave Cobbley rm -f ${file} 33eb8dc403SDave Cobbley 34eb8dc403SDave Cobbley clean_cache 35eb8dc403SDave Cobbley bitbake -R conf/prexport.conf -p 36eb8dc403SDave Cobbley s=`bitbake -R conf/prexport.conf -e | grep ^PRSERV_DUMPFILE= | cut -f2 -d\"` 37eb8dc403SDave Cobbley if [ "x${s}" != "x" ]; 38eb8dc403SDave Cobbley then 39eb8dc403SDave Cobbley [ -e $s ] && mv -f $s $file && echo "Exporting to file $file succeeded!" 40eb8dc403SDave Cobbley return 0 41eb8dc403SDave Cobbley fi 42eb8dc403SDave Cobbley echo "Exporting to file $file failed!" 43eb8dc403SDave Cobbley return 1 44eb8dc403SDave Cobbley} 45eb8dc403SDave Cobbley 46eb8dc403SDave Cobbleydo_import () 47eb8dc403SDave Cobbley{ 48eb8dc403SDave Cobbley file=$1 49eb8dc403SDave Cobbley [ "x${file}" == "x" ] && help && exit 1 50eb8dc403SDave Cobbley 51eb8dc403SDave Cobbley clean_cache 52eb8dc403SDave Cobbley bitbake -R conf/primport.conf -R $file -p 53eb8dc403SDave Cobbley ret=$? 54eb8dc403SDave Cobbley [ $ret -eq 0 ] && echo "Importing from file $file succeeded!" || echo "Importing from file $file failed!" 55eb8dc403SDave Cobbley return $ret 56eb8dc403SDave Cobbley} 57eb8dc403SDave Cobbley 58eb8dc403SDave Cobbleydo_migrate_localcount () 59eb8dc403SDave Cobbley{ 60eb8dc403SDave Cobbley df=`bitbake -R conf/migrate_localcount.conf -e | \ 61eb8dc403SDave Cobbley grep ^LOCALCOUNT_DUMPFILE= | cut -f2 -d\"` 62eb8dc403SDave Cobbley if [ "x${df}" == "x" ]; 63eb8dc403SDave Cobbley then 64eb8dc403SDave Cobbley echo "LOCALCOUNT_DUMPFILE is not defined!" 65eb8dc403SDave Cobbley return 1 66eb8dc403SDave Cobbley fi 67eb8dc403SDave Cobbley 68*b9af8750SPatrick Williams rm -f $df 69eb8dc403SDave Cobbley clean_cache 70eb8dc403SDave Cobbley echo "Exporting LOCALCOUNT to AUTOINCs..." 71eb8dc403SDave Cobbley bitbake -R conf/migrate_localcount.conf -p 72eb8dc403SDave Cobbley [ ! $? -eq 0 ] && echo "Exporting to file $df failed!" && exit 1 73eb8dc403SDave Cobbley 74eb8dc403SDave Cobbley if [ -e $df ]; 75eb8dc403SDave Cobbley then 76eb8dc403SDave Cobbley echo "Exporting to file $df succeeded!" 77eb8dc403SDave Cobbley else 78eb8dc403SDave Cobbley echo "Exporting to file $df failed!" 79eb8dc403SDave Cobbley exit 1 80eb8dc403SDave Cobbley fi 81eb8dc403SDave Cobbley 82eb8dc403SDave Cobbley echo "Importing generated AUTOINC entries..." 83eb8dc403SDave Cobbley [ -e $df ] && do_import $df 84eb8dc403SDave Cobbley 85eb8dc403SDave Cobbley if [ ! $? -eq 0 ] 86eb8dc403SDave Cobbley then 87eb8dc403SDave Cobbley echo "Migration from LOCALCOUNT to AUTOINCs failed!" 88eb8dc403SDave Cobbley return 1 89eb8dc403SDave Cobbley fi 90eb8dc403SDave Cobbley 91eb8dc403SDave Cobbley echo "Migration from LOCALCOUNT to AUTOINCs succeeded!" 92eb8dc403SDave Cobbley return 0 93eb8dc403SDave Cobbley} 94eb8dc403SDave Cobbley 95eb8dc403SDave Cobbley[ $# -eq 0 ] && help && exit 1 96eb8dc403SDave Cobbley 97eb8dc403SDave Cobbleycase $2 in 98eb8dc403SDave Cobbley*.conf|*.inc) 99eb8dc403SDave Cobbley ;; 100eb8dc403SDave Cobbley*) 101eb8dc403SDave Cobbley echo ERROR: $2 must end with .conf or .inc! 102eb8dc403SDave Cobbley exit 1 103eb8dc403SDave Cobbley ;; 104eb8dc403SDave Cobbleyesac 105eb8dc403SDave Cobbley 106eb8dc403SDave Cobbleycase $1 in 107eb8dc403SDave Cobbleyexport) 108eb8dc403SDave Cobbley do_export $2 109eb8dc403SDave Cobbley ;; 110eb8dc403SDave Cobbleyimport) 111eb8dc403SDave Cobbley do_import $2 112eb8dc403SDave Cobbley ;; 113eb8dc403SDave Cobbleymigrate_localcount) 114eb8dc403SDave Cobbley do_migrate_localcount 115eb8dc403SDave Cobbley ;; 116eb8dc403SDave Cobbley*) 117eb8dc403SDave Cobbley help 118eb8dc403SDave Cobbley exit 1 119eb8dc403SDave Cobbley ;; 120eb8dc403SDave Cobbleyesac 121