summaryrefslogtreecommitdiff
path: root/scripts/iot-hal-backend.post
blob: 063b01760f3f88bb3fc35af5491ffd9d16d82951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh
echo "############### iot-hal-backend.post ################"

if [ -d /hal ]; then
	echo "Initialize rpmdb for HaL Backend"
	mkdir -p /hal/lib/rpm
	cp /var/lib/rpm/Packages /hal/lib/rpm/
	rpm --rebuilddb --dbpath=/hal/lib/rpm
fi

check_building_block() {
	PKG=`/usr/bin/rpm -qR $1 | /usr/bin/uniq | /bin/grep -v "^rpmlib" | /bin/grep -v ".\+\.so\..\+" | /bin/grep -v "^\/" | /bin/grep -v "=" | /bin/grep -v "(.\+)"`
	for pkgs in ${PKG}; do
		INSTALLED=`/usr/bin/rpm -q $pkgs`
		RET=$?
		if [[ $pkgs =~ "building-blocks" ]]; then
			check_building_block $pkgs
		elif [ $RET -eq 0 ]; then
			PATH=`/usr/bin/rpm -ql $INSTALLED | /bin/grep -v "^\/hal\/"`
			if [ "$PATH" ]; then
				echo "WARNING!!! $INSTALLED packages was installed to wrong path"
				for wrong_path in $PATH; do
					echo $wrong_path
				done
			fi
			echo -e $INSTALLED >> /hal/list/hal-backend-list.ini
		fi
	done
}


#FIXME: Need to check how to parse specific package
BACKEND_PACKAGE=("hal-backend-device-common");

create_backend_dependency_file() {
	echo "Creating Backend Dependency List"

	PKG=`/usr/bin/rpm -qa`
	/usr/bin/mkdir -p /hal/temp
	/usr/bin/mkdir -p /hal/etc/rpm/

	for packages in ${PKG}; do
		/usr/bin/rpm -qP $packages > /hal/temp/${packages}
	done

	for lists in ${BACKEND_PACKAGE[@]}; do
		/usr/bin/grep -lr $lists /hal/temp/ | /bin/sed "s/\/hal\/temp\\///" >> /hal/list/hal-backend-list.ini
	done

	while read line; do
		/usr/bin/rpm -qR --qf "%{NAME} [%{REQUIRENAME} %{REQUIREVERSION}] " $line | /bin/grep -v "\/bin\/" | /bin/grep -v "rpmlib" | /bin/grep -v "\/sbin\/" | /bin/grep -v "config(" > /hal/list/${line}.ini
	done < /hal/list/hal-backend-list.ini

	LIST=`/usr/bin/ls /hal/list/`
	for lists in ${LIST}; do
		while read line; do
			/usr/bin/grep -lr $line /hal/temp/ | /bin/sed "s/\/hal\/temp\\///" >> /hal/etc/rpm/temp.ini
		done < /hal/list/$lists

		if [ -e /hal/etc/rpm/temp.ini ]; then
			/usr/bin/sort -u /hal/etc/rpm/temp.ini > /hal/etc/rpm/$lists
			/usr/bin/rm /hal/etc/rpm/temp.ini
		else
			/usr/bin/touch /hal/etc/rpm/$lists
		fi
	done

	for packages in ${PKG}; do
		FOUND=0
		while read line; do
			if [ $line == $packages ]; then
				FOUND=1
				break
			fi
		done < /hal/list/hal-backend-list.ini

		if [ $FOUND -eq 0 ]; then
			/usr/bin/rpm -e --justdb $packages --nodeps --noscripts --dbpath=/hal/lib/rpm
		fi
	done

	/usr/bin/rm -rf /hal/temp
	/usr/bin/rm -rf /hal/list
	/usr/bin/rm -rf /hal/etc/rpm/hal-backend-list.ini
	echo "Finished to Create Backend Dependency List"
}

#Supported Target's list
TARGET=("RPI3" "RPI4" "ARTIK530" "VIM3" "C4");

PKGGROUP=`/usr/bin/rpm -qa | /bin/grep package-groups`
if [ $PKGGROUP ]; then
	for target in ${TARGET[@]}; do
		RET=`/usr/bin/rpm -qa | /usr/bin/grep $target`
		RET=$?
		if [ $RET -eq 0 ]; then
			break;
		fi
	done

	case $target in
	RPI3)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend RPI3"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	RPI4)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend RPI4"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	ARTIK530)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend ARTIK530"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	VIM3)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend VIM3"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	C4)
		BACKEND=`/usr/bin/xmlstarlet sel -t -v '//group[name = "IoT Hal Backend C4"]/packagelist/packagereq' -n /usr/share/package-groups/group.xml`
	;;
	esac

	/usr/bin/mkdir -p /hal/list/

	#Get HAL Backend Package List#
	PKG=`/usr/bin/rpm -q $BACKEND`
	echo "Create Hal Backend Packages List"
	for packages in ${PKG}; do
		check_building_block $packages
	done

	create_backend_dependency_file

	#Create exportdb file to update a rpmdb of core image
	/usr/bin/rpmdb --dbpath=/hal/lib/rpm --exportdb > /hal/etc/hal-rpmdb.ini
fi

build_ts=$(/bin/date -u +%s)
build_date=$(/bin/date -u --date @$build_ts +%Y%m%d_%H%M%S)
build_time=$(/bin/date -u --date @$build_ts +%H:%M:%S)

/bin/sed -ri \
	-e 's|@BUILD_ID[@]|@BUILD_ID@|g' \
	-e "s|@BUILD_DATE[@]|$build_date|g" \
	-e "s|@BUILD_TIME[@]|$build_time|g" \
	-e "s|@BUILD_TS[@]|$build_ts|g" \
	/etc/tizen-build.conf

/etc/make_info_file.sh hal