Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 132 lines (108 sloc) 3.5 KB
#!/bin/bash
source ../../../functions
META[AUTHOR]="Xia Bin<xiabin@deepin.com>"
META[AUTO_CHECK]=false
META[AUTO_FIX]=false
META[VALIDATE_UNTIL]="2016-11-2"
COMMENT description <<EOF
Wrong package version in local system
Local system may had installed some packages
which has different version with http://packages.deepin.com/deepin.
It may be caused local system can't correctly upgrade.
EOF
COMMENT zh description <<EOF
本地安装包与仓库不一致
用户本地安装的部分包可能与仓库不一致或安装了仓库中不存
的包. 由此可能导致系统无法正常更新到合适的版本.
EOF
COMMENT check <<EOF
Using apt-show-versions to detect packages which has
different version in local between http://packages.deepin.com/deepin
EOF
COMMENT zh check <<EOF
通过使用apt-show-versions工具检测出本地包版本与仓库不一致的情况.
EOF
function check()
{
helper_ensure_installed_apt_show_versions
IFS=$'\n' GLOBIGNORE='*'
declare -i newer=0
declare -i other=0
for line in $(apt-show-versions)
do
if [[ ! $(echo $line | grep -E 'newer than version|No available') ]]; then
continue
fi
if [[ $(echo $line | grep -F 'newer than version') ]]; then
newer+=1
echo $line
fi
if [[ $(echo $line | grep -F 'No available') ]]; then
other+=1
echo $line
fi
done
[[ $other == 0 ]] || printf "\nYou have %d packages doesn't in repository\n" $other
[[ $newer == 0 ]] || printf "\nYou have %d packages newer than version in repository\n" $newer
if [[ $other > 0 || $newer > 0 ]]; then
exit 1
fi
}
COMMENT fix <<EOF
1. reinstall packages with corrected version
2. remove the unknown packages
EOF
COMMENT zh fix <<EOF
1. 重新安装仓库中对应的版本.
2. 删除仓库中不存在的包
EOF
function fix()
{
helper_ensure_installed_apt_show_versions
local unknown_packages=()
IFS=$'\n' GLOBIGNORE='*'
for line in $(apt-show-versions)
do
if [[ ! $(echo $line | grep -E 'newer than version|No available') ]]; then
continue
fi
if [[ $(echo $line | grep -F 'newer than version') ]]; then
helper_fix_wrong_version_package $(echo $line | cut -d ':' -f1)
fi
if [[ $(echo $line | grep -F 'No available') ]]; then
unknown_packages+=("$(echo $line | cut -d ':' -f1)")
fi
done
if [[ ${#unknown_packages[@]} > 0 ]]; then
echo "There has some unknown packages wouldn't remove."
echo "You can execute below command to remove this packages"
echo -e "\t apt-get remove ${unknown_packages[@]}"
fi
exit 0
}
# ---------------------internal help functions-------------------
DEBIAN_FRONTEND="noninteractive"
DEBCONF_NONINTERACTIVE_SEEN="true"
function helper_ensure_installed_apt_show_versions()
{
if [[ ! -x /usr/bin/apt-show-versions ]] ; then
echo "Install apt-show-versions ..."
apt-get install apt-show-versions
fi
}
function helper_fix_wrong_version_package()
{
oldV=$(dpkg -s $1 | grep -E '^Version:\s+(.*)' | cut -d ' ' -f2)
newV=$(apt-cache madison $1 | grep -E 'http://packages.deepin.com/deepin(.*)Packages' |head -n1| cut -d '|' -f2 | tr -d ' ')
if [[ $newV != "" ]]; then
printf "Try fix $1 from %s to %s\n" $oldV $newV
apt-get install -y --allow-downgrades -o Dpkg::Options==--force-confold -- $1=$newV
else
printf "Can't find new version of $1"
fi
}
# ---------------------stub main---------------------------
# Please ensure it's the last line,
# otherwise it maybe report command not found for
# internal help functions.
base_main $*
You can’t perform that action at this time.