blob: bed97bd8ac36bb5237e8dc17ed8482c9d63cbcc9 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/usr/bin/env bash
Brad Bishopc342db32019-05-15 21:57:59 -04002#
Patrick Williams92b42cb2022-09-03 06:53:57 -05003# Copyright OpenEmbedded Contributors
4#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
6#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007
8help ()
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
17clean_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
25do_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
43do_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
55do_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 Williamsd8c66bc2016-06-20 12:57:21 -050094case $2 in
95*.conf|*.inc)
96 ;;
97*)
98 echo ERROR: $2 must end with .conf or .inc!
99 exit 1
100 ;;
101esac
102
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103case $1 in
104export)
105 do_export $2
106 ;;
107import)
108 do_import $2
109 ;;
110migrate_localcount)
111 do_migrate_localcount
112 ;;
113*)
114 help
115 exit 1
116 ;;
117esac