cornucopia: bump SRCREV
[openembedded.git] / recipes / opkg / update-alternatives-merge.inc
blob69813c61d842db298b91d7526961073ddf711289
1 # Moves all entries from /usr/lib/ipkg/alternatives to /usr/lib/opkg/alternatives
2 # If it exists in both it use file with more lines
4 pkg_postinst_${PN}_append () {
5         alternatives_dir_old="${prefix}/lib/ipkg/alternatives"
6         alternatives_dir_new="${prefix}/lib/opkg/alternatives"
7         # if ${prefix}/lib/ipkg is already link (probably to ${prefix}/lib/opkg), then nothing needs to be merged and definitely we don't want "rm -rf ${alternatives_dir_old}" to happen
8         if [ ! -h ${prefix}/lib/ipkg -a -e "${alternatives_dir_old}" ] ; then
9                 if [ ! -e "${alternatives_dir_new}" ] ; then
10                         mkdir -p "${alternatives_dir_new}";
11                 fi
12                 echo "Old alternatives directory ${alternatives_dir_old} exists, moving entries to new one ${alternatives_dir_new}"
13                 echo "Creating backup copy of both ${alternatives_dir_old}-backup and ${alternatives_dir_new}-backup"
14                 cp -Ra "${alternatives_dir_old}" "${alternatives_dir_old}-backup"
15                 cp -Ra "${alternatives_dir_new}" "${alternatives_dir_new}-backup"
17                 cd ${alternatives_dir_old}
18                 for alt_file in * ; do
19                         if [ ! -e "${alternatives_dir_new}/${alt_file}" ] ; then
20                                 echo "Moving old '${alternatives_dir_old}/${alt_file}' to '${alternatives_dir_new}/${alt_file}'";
21                                 mv -f "${alternatives_dir_old}/${alt_file}" "${alternatives_dir_new}/${alt_file}"
22                         else
23                                 OLD_LINES=`wc -l ${alternatives_dir_old}/${alt_file} | cut -d/ -f 1`;
24                                 NEW_LINES=`wc -l ${alternatives_dir_new}/${alt_file} | cut -d/ -f 1`;
25                                 if [ $OLD_LINES -gt $NEW_LINES ] ; then
26                                         echo "Replacing '${alternatives_dir_new}/${alt_file}' with '${alternatives_dir_old}/${alt_file}'";
27                                         mv -f "${alternatives_dir_old}/${alt_file}" "${alternatives_dir_new}/${alt_file}"
28                                 elif [ $OLD_LINES -eq $NEW_LINES ] ; then
29                                         if diff -q "${alternatives_dir_new}/${alt_file}" "${alternatives_dir_old}/${alt_file}" >/dev/null ; then
30                                                 echo "'${alternatives_dir_new}/${alt_file}' is the same"
31                                         else
32                                                 echo "WARN: You have to update manually if needed. Please check: diff '${alternatives_dir_old}-backup/${alt_file}' '${alternatives_dir_new}-backup/${alt_file}'"
33                                         fi
34                                 else
35                                         echo "WARN: '${alternatives_dir_old}/${alt_file}' is shorter than new one, ignoring, but please check and update manually if needed"
36                                 fi
37                         fi
38                 done
39                 rm -rf ${alternatives_dir_old}
40                 echo "Merge finished, old directory '${alternatives_dir_old}' is removed"
41         fi