+process_distbcond() {
+ # apply bconds from ~/.distbcond to spec
+ # The file structure is like gentoo's package.use:
+ # ---
+ # * -selinux
+ # samba -mysql -pgsql
+ # w32codec-installer license_agreement
+ # php +mysqli
+ # ---
+
+ local distbcond=$HOME/.distbcond
+
+ echo "Updating .distbcond"
+ wget -q --no-check-certificate $DISTBCOND_URL -O "$distbcond"
+ if [ $? -ne 0 ]; then
+ Exit_error err_distbcond_update
+ fi
+ DISTBCOND_MD5=$(grep -E "^# MD5 " "$distbcond" | cut -d ' ' -f 3)
+ DISTBCOND_MD5_LOCAL=$(grep -v -E "^#" "$distbcond" | md5sum | cut -d ' ' -f 1)
+ if [ "$DISTBCOND_MD5" != "$DISTBCOND_MD5_LOCAL" ]; then
+ rm -f "$distbcond"
+ Exit_error err_distbcond_update
+ fi
+
+ SN=${SPECFILE%%\.spec}
+
+ local bcond_avail=$(find_spec_bcond $SPECFILE)
+
+ while read pkg flags; do
+ # ignore comments
+ [[ "$pkg" == \#* ]] && continue
+
+ # any package or current package?
+ if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
+ for flag in $flags; do
+ local opt=${flag#[+-]}
+
+ # use only flags which are in this package.
+ if [[ $bcond_avail = *${opt}* ]]; then
+ if [[ $flag = -* ]]; then
+ sed -i -r -e '/^%bcond_(with|without)\s+'$opt'/s/^%bcond_(with|without)/%bcond_with/g;' "$1"
+ elif [[ $flag = +* ]]; then
+ sed -i -r -e '/^%bcond_(with|without)\s+'$opt'/s/^%bcond_(with|without)/%bcond_without/g;' "$1"
+ fi
+ fi
+ done
+ fi
+ done < $distbcond
+ update_shell_title "parse ~/.distbcond: DONE!"
+}
+