Commit 3d3c72d4 authored by sebt3's avatar sebt3

Initial version

parents
### Usage
```
dbp_get.sh {install|list|update}
install <pck> : Install given package
update : Update known package lists
list : List all availables packages
```
#!/bin/bash
DBP_HOME=${DBP_HOME:-"$HOME/.dbp_get_sh"}
createDefaultConfig() {
if [ ! -d "$DBP_HOME" ];then
mkdir "$DBP_HOME";
fi
if [ ! -e "$DBP_HOME/source.list" ];then
cat >"$DBP_HOME/source.list" <<ENDCFG
dbp https://pyra-handheld.com/repo opensource proprietary needdata
ENDCFG
fi
if [ ! -e "$DBP_HOME/config" ];then
cat >"$DBP_HOME/config" <<ENDCFG
target=/dragonbox/packages/
ENDCFG
fi
}
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
for c in $comps;do
mkdir -p "$DBP_HOME/repos/$id/$c"
echo -n "Updating: $id $c..."
wget -o /dev/null -O "$DBP_HOME/repos/$id/$c/Packages" "$url/dists/dbprepo/$c/Packages"
touch "$DBP_HOME/repos/$id/$c/Packages"
echo " done"
done
done
}
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
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
done
done
if [ "$ok" -eq 1 ];then
update
fi
}
}
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
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
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
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")
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")
fname="${pck}_${vers}.dbp"
echo -n "Downloading $fname..."
wget -o /dev/null -O "$(getTarget)$fname" "$(echo $url|awk -F/ '{print $1"//"$3}')$path"
echo "done"
exit;
fi
done
done
echo "Package \"$pck\" not found"
}
showHelp() {
cat <<ENDHELP
dbp_get.sh {install|list|update}
install <pck> : Install given package
update : Update known package lists
list : List all availables packages
ENDHELP
}
main() {
case "$1" in
update) update;;
list) list;;
install)install "$2";;
help|*) showHelp;;
esac
}
main "$@"
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