autils

Unnamed repository; edit this file 'description' to name the repository.
git clone https://codeberg.org/emmett1/autils
Log | Files | Refs | README | LICENSE

apkg-genabuild (1344B)


      1 #!/bin/sh
      2 #
      3 # script to generate abuild template
      4 
      5 print_help() {
      6 	cat <<EOF	
      7 usage:
      8 	$0 <url> [name]
      9 	
     10 EOF
     11 exit 0
     12 }
     13 
     14 if [ ! "$1" ] || [ "$1" = '-h' ]; then
     15 	print_help
     16 fi
     17 
     18 url=$1
     19 
     20 name=$(echo $1 | rev | cut -d / -f1 | cut -d - -f2- | rev | tr '[:upper:]' '[:lower:]')
     21 version=$(echo $1 | rev | cut -d / -f1 | cut -d - -f1 | rev | sed 's/\.tar.*//' | sed 's/^v//')
     22 
     23 case $url in
     24 	*.pythonhosted.*) name="python-$name";;
     25 	*/pypi.org/*) name="python-$name";;
     26 	*.metacpan.*|*.cpan.*) name="perl-$name";;
     27 	*/refs/tags/*)                 # github tags tarball
     28 			gh=${1%/archive*}      # project url
     29 			name=${gh##*/}         # project name
     30 			verstar=${1##*/}       # version with tar suffix
     31 			vers=${verstar%.tar.*} # version without tar suffix
     32 			version=${vers#v}      # final version without 'v' prefix
     33 			url=$gh/archive/$vers/$name-$verstar;;
     34 	*) name=$name;;
     35 esac
     36 
     37 if [ "$2" ]; then
     38 	name=$2
     39 fi
     40 
     41 # make name lowercase
     42 name=$(echo $name | tr '[:upper:]' '[:lower:]')
     43 
     44 [ -d $name ] && {
     45 	grep ^version= $name/abuild
     46 	echo "port for $name exist"
     47 	exit 1
     48 }
     49 url=$(echo $url | sed "s,$name,\${name},g;s,$version,\${version},g" )
     50 
     51 case $version in
     52 	*.*.*) v=${version%.*}
     53 		url=$(echo $url | sed "s,$v,\${version%\.\*},g" )
     54 esac
     55 
     56 mkdir -p $name
     57 
     58 echo "name=$name
     59 version=$version
     60 release=1
     61 source=\"$url\"" > $name/abuild
     62 
     63 cat $name/abuild
     64 
     65 exit 0