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