Commit ca62d301 authored by sebt3's avatar sebt3

Added upgrade option

parent 89c434f5
......@@ -4,4 +4,6 @@ dbp_get.sh {install|list|update}
install <pck> : Install given package
update : Update known package lists
list : List all availables packages
list_upgrade : List all upgradables packages
upgrade : Upgrade known package
```
......@@ -25,13 +25,22 @@ getTarget() {
awk -F= '$1=="target"{print $2}' "$DBP_HOME/config"
}
getPackagePath() {
awk -F= -v pck=$1 'BEGIN{p=0}$0=="["pck"]"{p=1}/^$/{p=0}p==1&&/Download=/{print $2;exit}' $2
awk -F= -v pck=$1 'BEGIN{p=0}$0=="["pck"]"{p=1}/^$/{p=0}p==1&&/Download=/{print $2;exit}' "$DBP_HOME/repos/$2/$3/Packages"
}
getPackageVers() {
awk -F= -v pck=$1 'BEGIN{p=0}$0=="["pck"]"{p=1}/^$/{p=0}p==1&&/Version=/{print $2;exit}' $2
getPackageMD5() {
awk -F= -v pck=$1 'BEGIN{p=0}$0=="["pck"]"{p=1}/^$/{p=0}p==1&&/MD5sum=/{print $2;exit}' "$DBP_HOME/repos/$2/$3/Packages"
}
getPackageName() {
awk -F= -v pck=$1 'BEGIN{p=0}$0=="["pck"]"{p=1}/^$/{p=0}p==1&&/Name=/{print $2;exit}' "$DBP_HOME/repos/$2/$3/Packages"
}
getPackageNames() {
awk -F= 'BEGIN{p=""}/^\[/{p=$1;gsub("^.","",p);gsub(".$","",p)}/^Name=/{print p"\t"$2}' $1
awk -F= 'BEGIN{p=""}/^\[/{p=$1;gsub("^.","",p);gsub(".$","",p)}/^Name=/{print p"\t"$2}' "$DBP_HOME/repos/$1/$2/Packages"
}
getPackageMD5s() {
awk -F= 'BEGIN{p=""}/^\[/{p=$1;gsub("^.","",p);gsub(".$","",p)}/^MD5sum=/{print p"\t"$2}' "$DBP_HOME/repos/$1/$2/Packages"
}
getFileMD5() {
md5sum <"$1"|awk '{print $1}'
}
update() {
......@@ -66,7 +75,7 @@ list() {
precheck
getRepoInfo|while read id url comps;do
for c in $comps;do
getPackageNames "$DBP_HOME/repos/$id/$c/Packages"|while read id desc;do
getPackageNames "$id" "$c"|while read id desc;do
printf "%s\033[30G%s\n" "$id" "$desc"
done
done
......@@ -78,13 +87,21 @@ install() {
precheck
getRepoInfo|{ while read id url comps;do
for c in $comps;do
path=$(getPackagePath "$pck" "$DBP_HOME/repos/$id/$c/Packages")
path=$(getPackagePath "$pck" "$id" "$c")
if [[ "$path" != "" ]];then
vers=$(getPackageVers "$1" "$DBP_HOME/repos/$id/$c/Packages")
fname="${pck}_${vers}.dbp"
md=$(getPackageMD5 "$1" "$id" "$c")
fname="${pck}.dbp"
echo -n "Downloading $fname..."
wget -o /dev/null -O "$(getTarget)$fname" "$(echo $url|awk -F/ '{print $1"//"$3}')$path"
echo "done"
wget -o /dev/null -O "$(getTarget)${fname}_new" "$(echo $url|awk -F/ '{print $1"//"$3}')$path"
echo " done"
echo -n "Checking..."
if [[ $(getFileMD5 "$(getTarget)/${fname}_new") == "$md" ]];then
echo " ok"
mv "$(getTarget)/${fname}_new" "$(getTarget)/${fname}"
else
echo " failed";
rm "$(getTarget)/${fname}_new"
fi
exit;
fi
done
......@@ -93,21 +110,55 @@ install() {
}
}
list_upgrade() {
precheck
getRepoInfo|while read id url comps;do
for c in $comps;do
getPackageMD5s "$id" "$c"|while read pck md;do
if [ -e "$(getTarget)/${pck}.dbp" ];then
if [[ $(getFileMD5 "$(getTarget)/${pck}.dbp") != "$md" ]];then
printf "%s\033[30G%s\n" "$pck" "$(getPackageName "$pck" "$id" "$c")"
fi
fi
done
done
done
}
upgrade() {
precheck
getRepoInfo|while read id url comps;do
for c in $comps;do
getPackageMD5s "$id" "$c"|while read pck md;do
if [ -e "$(getTarget)/${pck}.dbp" ];then
if [[ $(getFileMD5 "$(getTarget)/${pck}.dbp") != "$md" ]];then
install "$pck"
fi
fi
done
done
done
}
showHelp() {
cat <<ENDHELP
dbp_get.sh {install|list|update}
$1 {install|list|update}
install <pck> : Install given package
update : Update known package lists
list : List all availables packages
list_upgrade : List all upgradables packages
upgrade : Upgrade known package
ENDHELP
}
main() {
case "$1" in
update) update;;
list) list;;
install)install "$2";;
help|*) showHelp;;
update) update;;
list) list;;
list_upgrade) list_upgrade;;
upgrade) upgrade;;
install) install "$2";;
help|*) showHelp "$0";;
esac
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment