Commit 89c434f5 authored by sebt3's avatar sebt3

Readability

parent 3d3c72d4
......@@ -18,9 +18,25 @@ ENDCFG
fi
}
getRepoInfo() {
awk '$1=="dbp"{x=$2;gsub(".*//","",x);gsub("/","-",x);$1="";print x$0}' "$DBP_HOME/source.list"
}
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
}
getPackageVers() {
awk -F= -v pck=$1 'BEGIN{p=0}$0=="["pck"]"{p=1}/^$/{p=0}p==1&&/Version=/{print $2;exit}' $2
}
getPackageNames() {
awk -F= 'BEGIN{p=""}/^\[/{p=$1;gsub("^.","",p);gsub(".$","",p)}/^Name=/{print p"\t"$2}' $1
}
update() {
[ ! -e "$DBP_HOME/source.list" ] && createDefaultConfig
awk '$1=="dbp"{x=$2;gsub(".*//","",x);gsub("/","-",x);$1="";print x$0}' "$DBP_HOME/source.list"|while read id url comps;do
getRepoInfo|while read id url comps;do
for c in $comps;do
mkdir -p "$DBP_HOME/repos/$id/$c"
echo -n "Updating: $id $c..."
......@@ -34,7 +50,7 @@ update() {
precheck() {
[ ! -e "$DBP_HOME/source.list" ] && update
ok=0
awk '$1=="dbp"{x=$2;gsub(".*//","",x);gsub("/","-",x);$1="";print x$0}' "$DBP_HOME/source.list"|{ while read id url comps;do
getRepoInfo|{ while read id url comps;do
for c in $comps;do
[ ! -e "$DBP_HOME/repos/$id/$c/Packages" ] && ok=1
[ "$DBP_HOME/source.list" -nt "$DBP_HOME/repos/$id/$c/Packages" ] && ok=1
......@@ -48,26 +64,23 @@ precheck() {
list() {
precheck
awk '$1=="dbp"{x=$2;gsub(".*//","",x);gsub("/","-",x);$1="";print x$0}' "$DBP_HOME/source.list"|while read id url comps;do
getRepoInfo|while read id url comps;do
for c in $comps;do
awk 'BEGIN{p=""}/^\[/{p=$1;gsub("^.","",p);gsub(".$","",p)}/^Name=/{n=$0;gsub("^Name=","",n);print p"\t"n}' "$DBP_HOME/repos/$id/$c/Packages"|while read id desc;do
getPackageNames "$DBP_HOME/repos/$id/$c/Packages"|while read id desc;do
printf "%s\033[30G%s\n" "$id" "$desc"
done
done
done
}
getTarget() {
awk -F= '$1=="target"{print $2}' "$DBP_HOME/config"
}
install() {
pck=$1
awk '$1=="dbp"{x=$2;gsub(".*//","",x);gsub("/","-",x);$1="";print x$0}' "$DBP_HOME/source.list"|while read id url comps;do
precheck
getRepoInfo|{ while read id url comps;do
for c in $comps;do
path=$(awk -F= -v pck=$1 'BEGIN{p=0}$0=="["pck"]"{p=1}/^$/{p=0}p==1&&/Download=/{print $2;exit}' "$DBP_HOME/repos/$id/$c/Packages")
path=$(getPackagePath "$pck" "$DBP_HOME/repos/$id/$c/Packages")
if [[ "$path" != "" ]];then
vers=$(awk -F= -v pck=$1 'BEGIN{p=0}$0=="["pck"]"{p=1}/^$/{p=0}p==1&&/Version=/{print $2;exit}' "$DBP_HOME/repos/$id/$c/Packages")
vers=$(getPackageVers "$1" "$DBP_HOME/repos/$id/$c/Packages")
fname="${pck}_${vers}.dbp"
echo -n "Downloading $fname..."
wget -o /dev/null -O "$(getTarget)$fname" "$(echo $url|awk -F/ '{print $1"//"$3}')$path"
......@@ -77,6 +90,7 @@ install() {
done
done
echo "Package \"$pck\" not found"
}
}
showHelp() {
......
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