#!/bin/zsh

force=no
if [ "$1" = "-f" ]; then
  force=yes
  shift
fi

pkg=$1
version=$2

# Test basique
if [ -z $version ]; then
  echo "Usage: ./$(basename $0) <package> <version>"
  exit 1
fi

if [ "$force" = "yes" ]; then
  mkdir $pkg 2> /dev/null
fi

if [ ! -d $pkg ]; then
  echo "$pkg n'existe pas."
  exit 1
fi

cd $pkg

zsh() {
  wget -c https://www.zsh.org/pub/${pkg}-${version}.tar.xz.asc
  dlsource https://www.zsh.org/pub/${pkg}-${version}.tar.xz
  wget -c https://www.zsh.org/pub/${pkg}-${version}-doc.tar.xz.asc
  dlsource https://www.zsh.org/pub/${pkg}-${version}-doc.tar.xz
}

httpd() {
  wget -c http://www.apache.org/dist/$pkg/${pkg}-${version}.tar.bz2.asc
  dlsource http://www.apache.org/dist/$pkg/${pkg}-${version}.tar.bz2
}

php() {
  wget -c https://www.php.net/distributions/php-${version}.tar.gz.asc || exit 1
  dlsource https://www.php.net/distributions/php-${version}.tar.gz
}

samba() {
  wget -c https://download.samba.org/pub/samba/stable/samba-${version}.tar.asc || exit 1
  wget -c https://download.samba.org/pub/samba/stable/samba-${version}.tar.gz || exit 1
  gzip -cd samba-${version}.tar.gz | gpg --verify samba-${version}.tar.asc - || exit 1
  md5sum samba-${version}.tar.gz > samba-${version}.tar.gz.md5 || exit 1
  cat samba-${version}.tar.gz.md5
}

curl() {
  wget -c https://curl.haxx.se/download/${pkg}-${version}.tar.xz.asc
  dlsource https://curl.haxx.se/download/${pkg}-${version}.tar.xz
  #rm cacert.pem.lz 2> /dev/null ; wget -c http://curl.haxx.se/ca/cacert.pem && lzip cacert.pem
  #md5sum cacert.pem.lz > cacert.pem.lz.md5
  #cat ${pkg}-${version}.tar.xz.md5 cacert.pem.lz.md5
}

pidgin() {
  dlsource https://downloads.sourceforge.net/project/pidgin/Pidgin/${version}/${pkg}-${version}.tar.bz2
}

libssh2() {
  wget -c https://www.libssh2.org/download/libssh2-${version}.tar.gz.asc
  dlsource https://www.libssh2.org/download/libssh2-${version}.tar.gz
}

mariadb() {
  #wget -c ftp://ftp.osuosl.org/pub/${pkg}/${pkg}-${version}/source/${pkg}-${version}.tar.gz.asc
  #dlsource ftp://ftp.osuosl.org/pub/${pkg}/${pkg}-${version}/source/${pkg}-${version}.tar.gz
  #wget -c http://mirror.nodesdirect.com/mariadb/mariadb-${version}/source/mariadb-${version}.tar.gz.asc
  #dlsource http://mirror.nodesdirect.com/mariadb/mariadb-${version}/source/mariadb-${version}.tar.gz
  #wget -c https://mirror.kumi.systems/mariadb/mariadb-${version}/source/mariadb-${version}.tar.gz.asc
  #dlsource https://mirror.kumi.systems/mariadb/mariadb-${version}/source/mariadb-${version}.tar.gz
  wget -c https://mirrors.ircam.fr/pub/mariadb/mariadb-${version}/source/mariadb-${version}.tar.gz.asc
  dlsource https://mirrors.ircam.fr/pub/mariadb/mariadb-${version}/source/mariadb-${version}.tar.gz
}

rclone() {
  dlsource https://downloads.rclone.org/v${version}/rclone-v${version}-linux-amd64.zip || exit 1
  md5sum rclone-v${version}-linux-amd64.zip > rclone-v${version}-linux-amd64.zip.md5
  cat rclone-v${version}-linux-amd64.zip.md5
}

dino() {
  dlsource https://github.com/dino/dino/releases/download/v${version}/dino-${version}.tar.gz
}

msgpack-python() {
  dlsource https://github.com/msgpack/msgpack-python/archive/refs/tags/v${version}.tar.gz
}

llfuse() {
  dlsource https://github.com/python-llfuse/python-llfuse/releases/download/release-${version}/llfuse-${version}.tar.gz.asc
}

chrony() {
  #wget -O chrony-${version}.tar.gz.asc -c https://download.tuxfamily.org/chrony/chrony-${version}-tar-gz-asc.txt
  dlsource https://chrony-project.org/releases/chrony-${version}.tar.gz
}

librewolf() {
  wget -c https://gitlab.com/api/v4/projects/12829184/packages/generic/librewolf/${version}/LibreWolf-${version}.x86_64.tar.bz2.sig
  dlsource https://gitlab.com/api/v4/projects/12829184/packages/generic/librewolf/${version}/LibreWolf-${version}.x86_64.tar.bz2
}

whalebird() {
  dlsource https://github.com/h3poteto/whalebird-desktop/releases/download/${version}/Whalebird-${version}-linux-x64.tar.bz2
}

openssl() {
  wget -c https://www.openssl.org/source/${pkg}-${version}.tar.gz.asc
  dlsource https://www.openssl.org/source/${pkg}-${version}.tar.gz
}

openssh() {
  wget -c https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/${pkg}-${version}.tar.gz.asc
  dlsource https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/${pkg}-${version}.tar.gz
}

Botan() {
  dlsource https://botan.randombit.net/releases/Botan-${version}.tar.xz
}

wiredtiger() {
  dlsource https://source.wiredtiger.com/releases/wiredtiger-${version}.tar.bz2
}

yarn() {
  dlsource https://github.com/yarnpkg/yarn/releases/download/v${version}/yarn-v${version}.tar.gz
}

bind() {
  wget -c http://ftp.isc.org/isc/bind9/${version}/${pkg}-${version}.tar.xz.asc || wget -c http://ftp.isc.org/isc/bind9/${version}/${pkg}-${version}.tar.gz.asc
  dlsource http://ftp.isc.org/isc/bind9/${version}/${pkg}-${version}.tar.xz || dlsource http://ftp.isc.org/isc/bind9/${version}/${pkg}-${version}.tar.gz
}

pulseaudio() {
  wget -c https://freedesktop.org/software/pulseaudio/releases/pulseaudio-${version}.tar.xz.sha256sum
  dlsource https://freedesktop.org/software/pulseaudio/releases/pulseaudio-${version}.tar.xz
}

talloc() {
  wget -c https://www.samba.org/ftp/${pkg}/${pkg}-${version}.tar.asc
  dlsource https://www.samba.org/ftp/${pkg}/${pkg}-${version}.tar.gz
  lzip -cd ${pkg}-${version}.tar.lz | gpg --verify ${pkg}-${version}.tar.asc -
  rm ${pkg}-${version}.tar.asc
}

tdb() {
  wget -c https://www.samba.org/ftp/${pkg}/${pkg}-${version}.tar.asc
  dlsource https://www.samba.org/ftp/${pkg}/${pkg}-${version}.tar.gz
  lzip -cd ${pkg}-${version}.tar.lz | gpg --verify ${pkg}-${version}.tar.asc -
  rm ${pkg}-${version}.tar.asc
}

tevent() {
  wget -c https://www.samba.org/ftp/${pkg}/${pkg}-${version}.tar.asc
  dlsource https://www.samba.org/ftp/${pkg}/${pkg}-${version}.tar.gz
  lzip -cd ${pkg}-${version}.tar.lz | gpg --verify ${pkg}-${version}.tar.asc -
  rm ${pkg}-${version}.tar.asc
}

samba() {
  wget -c https://download.samba.org/pub/${pkg}/stable/${pkg}-${version}.tar.asc
  dlsource https://download.samba.org/pub/${pkg}/stable/${pkg}-${version}.tar.gz
  lzip -cd ${pkg}-${version}.tar.lz | gpg --verify ${pkg}-${version}.tar.asc -
  rm ${pkg}-${version}.tar.asc
}

ffmpeg() {
  wget -c http://ffmpeg.org/releases/${pkg}-${version}.tar.bz2.asc
  dlsource http://ffmpeg.org/releases/${pkg}-${version}.tar.bz2
}

Wget() {
  wget -c https://ftp.gnu.org/gnu/wget/wget-${version}.tar.lz.sig
  dlsource https://ftp.gnu.org/gnu/wget/wget-${version}.tar.lz
}

lftp() {
  wget -c http://lftp.yar.ru/ftp/${pkg}-${version}.tar.xz.asc
  dlsource http://lftp.yar.ru/ftp/${pkg}-${version}.tar.xz
}

libevent() {
  wget -c https://github.com/libevent/libevent/releases/download/release-${version}-stable/libevent-${version}-stable.tar.gz.asc
  dlsource https://github.com/libevent/libevent/releases/download/release-${version}-stable/libevent-${version}-stable.tar.gz
}

x264() {
  dlsource ftp://ftp.videolan.org/pub/videolan/x264/snapshots/${pkg}-snapshot-${version}-2245-stable.tar.bz2
}

mozilla-firefox() {
  cd x86_64
  wget https://ftp.mozilla.org/pub/firefox/releases/$version/linux-x86_64/fr/firefox-${version}.tar.bz2 || exit 1
  md5sum firefox-${version}.tar.bz2 > firefox-${version}.tar.bz2.md5
  #cd ../x86
  #wget https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/$version/linux-i686/fr/firefox-${version}.tar.bz2 || exit 1
  #md5sum firefox-${version}.tar.bz2 > firefox-${version}.tar.bz2.md5
  cd ..
  cat x86_64/firefox-${version}.tar.bz2.md5
  #cat x86{,_64}/firefox-${version}.tar.bz2.md5
}

mozilla-thunderbird() {
  cd x86_64
  wget -c https://ftp.mozilla.org/pub/thunderbird/releases/$version/linux-x86_64/fr/thunderbird-${version}.tar.bz2 || exit 1
  md5sum thunderbird-${version}.tar.bz2 > thunderbird-${version}.tar.bz2.md5
  #cd ../x86
  #wget -c http://download.cdn.mozilla.net/pub/mozilla.org/thunderbird/releases/$version/linux-i686/fr/thunderbird-${version}.tar.bz2 || exit 1
  #md5sum thunderbird-${version}.tar.bz2 > thunderbird-${version}.tar.bz2.md5
  cd ..
  cat x86_64/thunderbird-${version}.tar.bz2.md5
  #cat x86{,_64}/thunderbird-${version}.tar.bz2.md5
}

libuv() {
  wget -c https://dist.libuv.org/dist/v${version}/libuv-v${version}.tar.gz.sign
  dlsource https://dist.libuv.org/dist/v${version}/libuv-v${version}.tar.gz
}

libetpan() {
  dlsource https://github.com/dinhviethoa/libetpan/archive/${version}.tar.gz
}

grisbi() {
  #wget -O grisbi-${version}.tar.bz2.md5 -c https://liquidtelecom.dl.sourceforge.net/project/grisbi/grisbi%20stable/$(echo ${version} | cut -d \. -f 1,2).x/grisbi-${version}.md5
  #dlsource https://liquidtelecom.dl.sourceforge.net/project/grisbi/grisbi%20stable/$(echo ${version} | cut -d \. -f 1,2).x/grisbi-${version}.tar.bz2
  wget https://master.dl.sourceforge.net/project/grisbi/grisbi%20stable/$(echo ${version} | cut  -d \. -f 1,2).x/${version}/grisbi-${version}.tar.bz2.asc
  dlsource https://master.dl.sourceforge.net/project/grisbi/grisbi%20stable/$(echo ${version} | cut  -d \. -f 1,2).x/${version}/grisbi-${version}.tar.bz2
}

gnupg() {
  wget -c https://gnupg.org/ftp/gcrypt/gnupg/gnupg-${version}.tar.bz2.sig
  dlsource https://gnupg.org/ftp/gcrypt/gnupg/gnupg-${version}.tar.bz2
}

claws-mail() {
  wget -c http://www.claws-mail.org/releases/${pkg}-${version}.tar.xz.asc
  dlsource http://www.claws-mail.org/releases/${pkg}-${version}.tar.xz
}

imlib2() {
  dlsource https://deac-fra.dl.sourceforge.net/project/enlightenment/imlib2-src/${version}/imlib2-${version}.tar.gz
}

tmux() {
  dlsource https://github.com/tmux/tmux/releases/download/${version}/${pkg}-${version}.tar.gz
}

mkvtoolnix() {
  wget -c https://mkvtoolnix.download/sources/${pkg}-${version}.tar.xz.sig
  dlsource https://mkvtoolnix.download/sources/${pkg}-${version}.tar.xz
}

smplayer() {
  dlsource https://github.com/${pkg}-dev/${pkg}/releases/download/v${version}/${pkg}-${version}.tar.bz2
}

weechat() {
  wget -c https://weechat.org/files/src/${pkg}-${version}.tar.xz.asc
  dlsource https://weechat.org/files/src/${pkg}-${version}.tar.xz
}

gajim() {
  dlsource https://gajim.org/downloads/$(echo ${version} | cut -d \. -f1,2)/${pkg}-${version}.tar.gz
}

tor() {
  #wget -c https://archive.torproject.org/tor-package-archive/${pkg}-${version}.tar.gz.asc
  #dlsource https://archive.torproject.org/tor-package-archive/${pkg}-${version}.tar.gz
  wget -c https://www.torproject.org/dist/${pkg}-${version}.tar.gz.asc
  dlsource https://www.torproject.org/dist/${pkg}-${version}.tar.gz
}

palemoon() {
  wget -c http://linux.palemoon.org/datastore/release/${pkg}-${version}.linux-x86_64.tar.bz2.sig
  wget -c http://linux.palemoon.org/datastore/release/${pkg}-${version}.linux-x86_64.tar.bz2
  gpg --verify ${pkg}-${version}.linux-x86_64.tar.bz2.sig && rm ${pkg}-${version}.linux-x86_64.tar.bz2.sig
  wget -c http://linux.palemoon.org/datastore/release/${pkg}-${version}.linux-i686.tar.bz2.sig
  wget -c http://linux.palemoon.org/datastore/release/${pkg}-${version}.linux-i686.tar.bz2
  gpg --verify ${pkg}-${version}.linux-i686.tar.bz2.sig && rm ${pkg}-${version}.linux-i686.tar.bz2.sig
}

testdisk() {
  dlsource http://www.cgsecurity.org/${pkg}-${version}.tar.bz2
}

squid() {
  wget -c http://www.squid-cache.org/Versions/v3/3.5/${pkg}-${version}.tar.xz.asc
  dlsource http://www.squid-cache.org/Versions/v3/3.5/${pkg}-${version}.tar.xz
}

mpd() {
  wget http://www.musicpd.org/download/${pkg}/"$(echo $version | cut -d . -f 1,2)"/${pkg}-${version}.tar.xz.sig || exit 1
  dlsource http://www.musicpd.org/download/${pkg}/"$(echo $version | cut -d . -f 1,2)"/${pkg}-${version}.tar.xz
}

keepassxc() {
  wget https://github.com/keepassxreboot/keepassxc/releases/download/${version}/keepassxc-${version}-src.tar.xz.sig || exit 1
  dlsource https://github.com/keepassxreboot/keepassxc/releases/download/${version}/keepassxc-${version}-src.tar.xz
  #wget -O ${pkg}-${version}.tar.gz https://github.com/keepassxreboot/keepassxc/archive/${version}.tar.gz || exit 1
  #gzip -cd ${pkg}-${version}.tar.gz | lzip > ${pkg}-${version}.tar.lz && rm ${pkg}-${version}.tar.gz
  #md5sum ${pkg}-${version}.tar.lz > ${pkg}-${version}.tar.lz.md5
  #cat ${pkg}-${version}.tar.lz.md5
}

ncmpcpp() {
  dlsource http://rybczak.net/${pkg}/stable/${pkg}-${version}.tar.bz2
}

ncmpc() {
  dlsource http://www.musicpd.org/download/${pkg}/"$(echo $version | cut -d . -f 1)"/${pkg}-${version}.tar.xz
}

nghttp2() {
  dlsource https://github.com/${pkg}/${pkg}/releases/download/v${version}/${pkg}-${version}.tar.xz
}

dovecot() {
  main_version="$(echo $version | cut -d . -f 1,2)"
  wget -c https://dovecot.org/releases/${main_version}/${pkg}-${version}.tar.gz.sig
  dlsource https://dovecot.org/releases/${main_version}/${pkg}-${version}.tar.gz
}

dovecot-pigeonhole() {
  [ "$(echo $version | cut -d . -f 1,2)" = "0.4" ] && main_version=2.2
  [ "$(echo $version | cut -d . -f 1,2)" = "0.5" ] && main_version=2.3
  #full_version=${full_version:-2.3.11}
  wget -c https://pigeonhole.dovecot.org/releases/${main_version}/dovecot-${main_version}-pigeonhole-${version}.tar.gz.sig
  dlsource https://pigeonhole.dovecot.org/releases/${main_version}/dovecot-${main_version}-pigeonhole-${version}.tar.gz
}

libgcrypt() {
  wget -c ftp://ftp.gnupg.org/gcrypt/${pkg}/${pkg}-${version}.tar.bz2.sig
  dlsource ftp://ftp.gnupg.org/gcrypt/${pkg}/${pkg}-${version}.tar.bz2
}

python3() {
  dlsource https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz
}

tuxguitar() {
  dlsource https://downloads.sourceforge.net/project/tuxguitar/TuxGuitar/TuxGuitar-${version}/${pkg}-${version}-linux-x86_64.tar.gz
}

feh() {
  wget -c https://feh.finalrewind.org/${pkg}-${version}.tar.bz2.asc
  dlsource https://feh.finalrewind.org/${pkg}-${version}.tar.bz2
}

postfix() {
  wget -O ${pkg}-${version}.tar.gz.sig https://de.postfix.org/ftpmirror/official/${pkg}-${version}.tar.gz.gpg2 || exit 1
  wget -c https://de.postfix.org/ftpmirror/official/${pkg}-${version}.tar.gz || exit 1
  gpg --verify ${pkg}-${version}.tar.gz.sig || exit 1
  rm -f ${pkg}-${version}.tar.gz.sig
  md5sum ${pkg}-${version}.tar.gz > ${pkg}-${version}.tar.gz.md5
  cat ${pkg}-${version}.tar.gz.md5
}

ejabberd() {
  #dlsource https://static.process-one.net/ejabberd/downloads/${version}/${pkg}-${version}.tgz
  dlsource https://github.com/processone/ejabberd/archive/refs/tags/${version}.tar.gz
}

erlang() {
  dlsource https://github.com/erlang/otp/archive/OTP-${version}.tar.gz
}

libass() {
  dlsource https://github.com/libass/libass/releases/download/${version}/libass-${version}.tar.xz
}

mpv() {
  dlsource https://github.com/mpv-player/mpv/archive/v${version}/mpv-${version}.tar.gz
}

libmatroska() {
  dlsource https://dl.matroska.org/downloads/${pkg}/${pkg}-${version}.tar.xz
}

nginx() {
  wget -c http://nginx.org/download/${pkg}-${version}.tar.gz.asc
  dlsource http://nginx.org/download/${pkg}-${version}.tar.gz
}

freenginx() {
  wget -c http://freenginx.org/download/${pkg}-${version}.tar.gz.asc
  dlsource http://freenginx.org/download/${pkg}-${version}.tar.gz
}

libmpdclient() {
  dlsource http://www.musicpd.org/download/libmpdclient/2/${pkg}-${version}.tar.xz
}

meson() {
  wget -c https://github.com/mesonbuild/meson/releases/download/${version}/${pkg}-${version}.tar.gz.asc
  dlsource https://github.com/mesonbuild/meson/releases/download/${version}/${pkg}-${version}.tar.gz
}

ninja() {
  dlsource https://github.com/ninja-build/ninja/archive/v${version}/${pkg}-${version}.tar.gz
}

cve-check-tool() {
  dlsource https://github.com/clearlinux/cve-check-tool/releases/download/v${version}/${pkg}-${version}.tar.xz
}

openjpeg() {
  dlsource https://github.com/uclouvain/openjpeg/archive/v${version}.tar.gz
}

dbus() {
  wget -c https://dbus.freedesktop.org/releases/${pkg}/${pkg}-${version}.tar.gz.asc
  dlsource https://dbus.freedesktop.org/releases/${pkg}/${pkg}-${version}.tar.gz
}

GraphicsMagick() {
  wget -c https://phoenixnap.dl.sourceforge.net/project/graphicsmagick/graphicsmagick/${version}/GraphicsMagick-${version}.tar.zst.sig
  dlsource https://phoenixnap.dl.sourceforge.net/project/graphicsmagick/graphicsmagick/${version}/GraphicsMagick-${version}.tar.zst
}

pgadmin4() {
  wget -c https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v${version}/source/pgadmin4-${version}.tar.gz.asc
  dlsource https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v${version}/source/pgadmin4-${version}.tar.gz
}

gnupg() {
  #wget -c https://gnupg.org/ftp/gcrypt/${pkg}/${pkg}-${version}.tar.bz2.sig
  dlsource https://gnupg.org/ftp/gcrypt/${pkg}/${pkg}-${version}.tar.bz2
}

libebml() {
  dlsource https://dl.matroska.org/downloads/${pkg}/${pkg}-${version}.tar.xz
}

qpdf() {
  dlsource https://downloads.sourceforge.net/project/${pkg}/${pkg}/${version}/${pkg}-${version}.tar.gz
}

libarchive() {
  dlsource http://libarchive.org/downloads/${pkg}-${version}.tar.gz
}

dosfstools() {
  wget -c https://github.com/dosfstools/dosfstools/releases/download/v${version}/${pkg}-${version}.tar.xz.sig
  dlsource https://github.com/dosfstools/dosfstools/releases/download/v${version}/${pkg}-${version}.tar.xz
}

rpcbind() {
  dlsource https://downloads.sourceforge.net/project/${pkg}/${pkg}/${version}/${pkg}-${version}.tar.bz2
}

libtiff() {
  dlsource ftp://download.osgeo.org/${pkg}/tiff-${version}.tar.gz
}

cairo() {
  wget -c https://www.cairographics.org/releases/${pkg}-${version}.tar.xz.sha1
  dlsource https://www.cairographics.org/releases/${pkg}-${version}.tar.xz
}

perl() {
  dlsource http://www.cpan.org/src/5.0/${pkg}-${version}.tar.xz
}

libcroco() {
  dlsource http://ftp.gnome.org/pub/gnome/sources/${pkg}/0.6/${pkg}-${version}.tar.xz
}

libxml2() {
  wget -c ftp://xmlsoft.org/${pkg}/${pkg}-${version}.tar.gz.asc
  dlsource ftp://xmlsoft.org/${pkg}/${pkg}-${version}.tar.gz
}

libxslt() {
  wget -c ftp://xmlsoft.org/${pkg}/${pkg}-${version}.tar.gz.asc
  dlsource ftp://xmlsoft.org/${pkg}/${pkg}-${version}.tar.gz
}

poppler() {
  dlsource https://poppler.freedesktop.org/${pkg}-${version}.tar.xz
}

poppler-data() {
  dlsource https://poppler.freedesktop.org/${pkg}-${version}.tar.gz
}

flex() {
  wget -c https://github.com/westes/flex/releases/download/v${version}/${pkg}-${version}.tar.gz.sig
  dlsource https://github.com/westes/flex/releases/download/v${version}/${pkg}-${version}.tar.gz
}

zlib() {
  wget -c https://zlib.net/${pkg}-${version}.tar.xz.asc
  dlsource https://zlib.net/${pkg}-${version}.tar.xz
}

libyaml() {
  dlsource http://pyyaml.org/download/${pkg}/yaml-${version}.tar.gz
}

libass() {
  dlsource https://github.com/libass/libass/releases/download/${version}/${pkg}-${version}.tar.xz
}

hplip() {
  dlsource http://downloads.sourceforge.net/project/${pkg}/${pkg}/${version}/${pkg}-${version}.tar.gz
}

dhcp() {
  wget -c http://ftp.isc.org/isc/${pkg}/${version}/${pkg}-${version}.tar.gz.asc
  dlsource http://ftp.isc.org/isc/${pkg}/${version}/${pkg}-${version}.tar.gz
}

goaccess() {
  dlsource http://tar.goaccess.io/${pkg}-${version}.tar.gz
}

gd() {
  dlsource https://github.com/libgd/libgd/releases/download/${pkg}-${version}/libgd-${version}.tar.xz
}

redis() {
  dlsource http://download.redis.io/releases/${pkg}-${version}.tar.gz
}

php-redis() {
  dlsource http://pecl.php.net/get/redis-${version}.tgz
}

php-apcu() {
  dlsource http://pecl.php.net/get/apcu-${version}.tgz
}

lame() {
  dlsource https://downloads.sourceforge.net/project/${pkg}/${pkg}/${version}/${pkg}-${version}.tar.gz
}

wxgtk3() {
  dlsource https://github.com/wxWidgets/wxWidgets/releases/download/v${version}/wxWidgets-${version}.tar.bz2
}

gtkspell3() {
  dlsource https://sourceforge.net/projects/gtkspell/files/${version}/${pkg}-${version}.tar.xz
}

LucenePlusPlus() {
  dlsource https://github.com/luceneplusplus/LucenePlusPlus/archive/rel_${version}.tar.gz
}

poedit() {
  dlsource https://github.com/vslavik/poedit/releases/download/v${version}-oss/${pkg}-${version}.tar.gz
}

mldonkey() {
  wget -c https://github.com/ygrek/mldonkey/releases/download/release-$(echo $version | tr . -)/${pkg}-${version}.tar.bz2.asc
  dlsource https://github.com/ygrek/mldonkey/releases/download/release-$(echo $version | tr . -)/${pkg}-${version}.tar.bz2
}

minidlna() {
  dlsource https://downloads.sourceforge.net/project/${pkg}/${pkg}/${version}/${pkg}-${version}.tar.gz
}

gcompris-qt() {
  wget -c http://gcompris.net/download/qt/src/gcompris-qt-${version}.tar.xz.sig
  dlsource http://gcompris.net/download/qt/src/gcompris-qt-${version}.tar.xz
}

qrencode() {
  wget -c -O ${pkg}-${version}.tar.bz2.sha512 https://fukuchi.org/works/${pkg}/${pkg}-${version}.tar.bz2.sha
  dlsource https://fukuchi.org/works/${pkg}/${pkg}-${version}.tar.bz2
}

glabels() {
  dlsource http://ftp.gnome.org/pub/GNOME/sources/glabels/$(echo ${version} | cut -d . -f 1,2)/${pkg}-${version}.tar.xz
}

gnucash() {
  dlsource http://downloads.sourceforge.net/sourceforge/${pkg}/${pkg}-${version}.tar.bz2
}

openldap() {
  dlsource http://www.openldap.org/software/download/OpenLDAP/openldap-release/${pkg}-${version}.tgz
}

rsync() {
  wget -c http://rsync.samba.org/ftp/${pkg}/src/${pkg}-${version}.tar.gz.asc
  dlsource http://rsync.samba.org/ftp/${pkg}/src/${pkg}-${version}.tar.gz
}

php-imagick() {
  dlsource http://pecl.php.net/get/imagick-${version}.tgz
}

nodejs() {
  dlsource https://nodejs.org/dist/v${version}/node-v${version}.tar.xz
}

rubygem-sass() {
  wget https://rubygems.org/downloads/sass-${version}.gem
}

nwjs() {
  #dlsource https://dl.nwjs.io/v${version}/${pkg}-v${version}-linux-x64.tar.gz
  dlsource https://dl.nwjs.io/v${version}/${pkg}-v${version}-linux-ia32.tar.gz
}

Signal-Desktop() {
  dlsource https://github.com/WhisperSystems/Signal-Desktop/archive/v${version}/Signal-Desktop-${version}.tar.gz
}

mpc() {
  dlsource http://www.musicpd.org/download/${pkg}/0/${pkg}-${version}.tar.xz
}

clamav() {
  wget -c http://www.clamav.net/downloads/production/${pkg}-${version}.tar.gz.sig
  dlsource http://www.clamav.net/downloads/production/${pkg}-${version}.tar.gz
}

clamsmtp() {
  dlsource http://thewalter.net/stef/software/${pkg}/${pkg}-${version}.tar.gz
}

proftpd() {
  dlsource ftp://ftp.proftpd.org/distrib/source/${pkg}-${version}.tar.gz
}

filezilla() {
  dlsource https://downloads.sourceforge.net/filezilla/FileZilla_${version}_src.tar.bz2
}

libfilezilla() {
  dlsource https://download.filezilla-project.org/libfilezilla/${pkg}-${version}.tar.bz2
}

libgpg-error() {
  wget -c ftp://ftp.gnupg.org:/gcrypt/libgpg-error/${pkg}-${version}.tar.gz.sig
  dlsource ftp://ftp.gnupg.org:/gcrypt/libgpg-error/${pkg}-${version}.tar.gz
}

lftp() {
  wget -c http://lftp.yar.ru/ftp/${pkg}-${version}.tar.xz.asc
  dlsource http://lftp.yar.ru/ftp/${pkg}-${version}.tar.xz
}

ssr() {
  dlsource https://github.com/MaartenBaert/ssr/archive/${version}/${pkg}-${version}.tar.gz
}

postgrey() {
  dlsource http://postgrey.schweikert.ch/pub/${pkg}-${version}.tar.gz
}

argon2() {
  dlsource https://github.com/P-H-C/phc-winner-argon2/archive/${version}/${pkg}-${version}.tar.gz
}

conky() {
  dlsource https://github.com/brndnmtthws/conky/archive/v${version}/${pkg}-${version}.tar.gz
}

lua() {
  dlsource http://www.lua.org/ftp/${pkg}-${version}.tar.gz
}

rubygem-rack() {
  wget http://rubygems.org/downloads/rack-${version}.gem
}

passenger() {
  wget https://rubygems.org/downloads/passenger-${version}.gem
}

firejail() {
  dlsource https://tenet.dl.sourceforge.net/project/${pkg}/${pkg}/${pkg}-${version}.tar.xz
}

convmv() {
  dlsource https://www.j3e.de/linux/convmv/convmv-${version}.tar.gz
}

progress() {
  dlsource https://github.com/Xfennec/progress/archive/v${version}.tar.gz
}

libzen() {
  dlsource https://github.com/MediaArea/ZenLib/archive/v${version}/ZenLib-${version}.tar.gz
}

libmediainfo() {
  dlsource https://github.com/MediaArea/MediaInfoLib/archive/v${version}/MediaInfoLib-${version}.tar.gz
}

mediainfo() {
  dlsource https://github.com/MediaArea/MediaInfo/archive/v${version}/MediaInfo-${version}.tar.gz
}

qemu() {
  wget -c https://download.qemu.org/qemu-${version}.tar.xz.sig
  dlsource https://download.qemu.org/qemu-${version}.tar.xz
}

iperf3() {
  dlsource https://github.com/esnet/iperf/archive/${version}/iperf-${version}.tar.gz
}

duniter() {
  wget -O duniter-${version}.tar.gz https://git.duniter.org/nodes/typescript/duniter/repository/v${version}/archive.tar.gz
  gzip -cd duniter-${version}.tar.gz | lzip > duniter-${version}.tar.lz
  rm duniter-${version}.tar.gz
}

pcre2() {
  dlsource https://downloads.sourceforge.net/pcre/${pkg}-${version}.tar.bz2
}

vte3() {
  dlsource https://github.com/GNOME/vte/archive/${version}/vte-${version}.tar.gz
}

vala() {
  dlsource https://download.gnome.org/sources/vala/$(echo ${version} | cut -d . -f 1,2)/vala-${version}.tar.xz
}

xcfa() {
  dlsource http://download.tuxfamily.org/xcfaudio/xcfa_download/src/xcfa-${version}.tar.gz
}

byobu() {
  dlsource http://launchpad.net/byobu/trunk/${version}/+download/byobu_${version}.orig.tar.gz
}

libidn2() {
  wget -c https://ftp.gnu.org/gnu/libidn/libidn2-${version}.tar.lz.sig
  dlsource https://ftp.gnu.org/gnu/libidn/libidn2-${version}.tar.lz
}

deltachat() {
  wget -c https://download.delta.chat/desktop/v${version}/DeltaChat-${version}.AppImage
  md5sum DeltaChat-${version}.AppImage > DeltaChat-${version}.AppImage.md5
  cat DeltaChat-${version}.AppImage.md5
}

rdfind() {
  wget https://rdfind.pauldreik.se/rdfind-${version}.tar.gz.asc
  dlsource https://rdfind.pauldreik.se/rdfind-${version}.tar.gz
}

#linux() {
#  #wget -c https://cdn.kernel.org/pub/linux/kernel/v$(echo $version | cut -d . -f 1).x/ChangeLog-${version} || exit 1
#  #wget -c https://cdn.kernel.org/pub/linux/kernel/v$(echo $version | cut -d . -f 1).x/linux-${version}.tar.sign || exit 1
#  #wget -c https://cdn.kernel.org/pub/linux/kernel/v$(echo $version | cut -d . -f 1).x/linux-${version}.tar.xz || exit 1
#
#  if [ -f linux-${version}.tar.zst ]; then
#    echo "linux-${version}.tar.zst existe déjà."
#    exit 1
#  fi
#  wget -c -O linux-${version}.tar.asc https://cdn.kernel.org/pub/linux/kernel/v$(echo $version | cut -d . -f 1).x/linux-${version}.tar.sign || \
#    wget -c https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/snapshot/linux-${version}.tar.asc
#  [ -s linux-${version}.tar.asc ] || rm linux-${version}.tar.asc
#  wget -c https://cdn.kernel.org/pub/linux/kernel/v$(echo $version | cut -d . -f 1).x/linux-${version}.tar.gz || \
#    wget -c https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/snapshot/linux-${version}.tar.gz || exit 1
#
#  gzip -cd linux-${version}.tar.gz | zstd -9 --threads=$(nproc) > linux-${version}.tar.zst || exit 1
#  rm -f linux-${version}.tar.gz
#  if [ -s linux-${version}.tar.asc ]; then
#    zstd -cd linux-${version}.tar.zst | gpg --verify linux-${version}.tar.asc -
#  else
#    #rm linux-${version}.tar.asc
#    tar ft linux-${version}.tar.zst 1> /dev/null && echo OK
#  fi
#  #md5sum linux-${version}.tar.zst > linux-${version}.tar.zst.md5
#  #cat linux-${version}.tar.zst.md5
#}

linux() {
  if [ -z "$(echo $version | cut -d . -f 3)" ]; then
    wget -c https://cdn.kernel.org/pub/linux/kernel/v$(echo $version | cut -d . -f 1).x/linux-${version}.tar.sign || exit 1
    wget -c https://cdn.kernel.org/pub/linux/kernel/v$(echo $version | cut -d . -f 1).x/linux-${version}.tar.gz || exit 1
    gzip -cd linux-${version}.tar.gz | zstd -9 --threads=$(nproc) > linux-${version}.tar.zst || exit 1
    rm -f linux-${version}.tar.gz
    zstd -cd linux-${version}.tar.zst | gpg --verify linux-${version}.tar.sign -
  else
    wget -c https://cdn.kernel.org/pub/linux/kernel/v$(echo $version | cut -d . -f 1).x/patch-${version}.xz
  fi
}

linux-libre() {
  if [ -z "$(echo $version | cut -d . -f 3)" ]; then
    wget -c https://linux-libre.fsfla.org/pub/linux-libre/releases/${version}-gnu/linux-libre-${version}-gnu.tar.sign || exit 1
    wget -c https://linux-libre.fsfla.org/pub/linux-libre/releases/${version}-gnu/linux-libre-${version}-gnu.tar.xz || exit 1
    xz -cd linux-libre-${version}-gnu.tar.xz | zstd -9 --threads=$(nproc) > linux-libre-${version}-gnu.tar.zst || exit 1
    rm -f linux-libre-${version}-gnu.tar.xz
    zstd -cd linux-libre-${version}-gnu.tar.zst | gpg --verify linux-libre-${version}-gnu.tar.sign - || exit 1
  else
    wget -c https://linux-libre.fsfla.org/pub/linux-libre/releases/${version}-gnu/patch-$(echo $version | cut -d . -f 1,2)-gnu-${version}-gnu.xz.sign || exit 1
    wget -c https://linux-libre.fsfla.org/pub/linux-libre/releases/${version}-gnu/patch-$(echo $version | cut -d . -f 1,2)-gnu-${version}-gnu.xz || exit 1
    gpg --verify patch-$(echo $version | cut -d . -f 1,2)-gnu-${version}-gnu.xz.sign || exit 1
  fi
} 

cronie() {
  dlsource https://github.com/cronie-crond/cronie/releases/download/cronie-${version}/cronie-${version}.tar.gz
}

gdal() {
  dlsource https://github.com/OSGeo/gdal/releases/download/v${version}/gdal-${version}.tar.gz
}

exiftool() {
  dlsource https://www.sno.phy.queensu.ca/~phil/exiftool/Image-ExifTool-${version}.tar.gz
}

icecast() {
  dlsource http://downloads.xiph.org/releases/icecast/icecast-${version}.tar.gz
}

libshout() {
  dlsource http://downloads.xiph.org/releases/libshout/libshout-${version}.tar.gz
}

ntp() {
  wget -c http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-${version}.tar.gz.md5
  dlsource http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-${version}.tar.gz
}

spamassassin() {
  wget -c http://www.apache.org/dist/spamassassin/source/Mail-SpamAssassin-${version}.tar.bz2.asc
  dlsource http://www.apache.org/dist/spamassassin/source/Mail-SpamAssassin-${version}.tar.bz2
}

libreoffice() {
  mkdir ${version}
  cd ${version}
  wget -c https://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86_64/LibreOffice_${version}_Linux_x86-64_rpm.tar.gz.asc
  wget -c https://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86_64/LibreOffice_${version}_Linux_x86-64_rpm.tar.gz
  wget -c https://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86_64/LibreOffice_${version}_Linux_x86-64_rpm_helppack_fr.tar.gz.asc
  wget -c https://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86_64/LibreOffice_${version}_Linux_x86-64_rpm_helppack_fr.tar.gz
  wget -c https://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86_64/LibreOffice_${version}_Linux_x86-64_rpm_langpack_fr.tar.gz.asc
  wget -c https://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86_64/LibreOffice_${version}_Linux_x86-64_rpm_langpack_fr.tar.gz
  wget -c http://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86/LibreOffice_${version}_Linux_x86_rpm.tar.gz.asc
  wget -c http://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86/LibreOffice_${version}_Linux_x86_rpm.tar.gz
  wget -c http://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86/LibreOffice_${version}_Linux_x86_rpm_helppack_fr.tar.gz.asc
  wget -c http://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86/LibreOffice_${version}_Linux_x86_rpm_helppack_fr.tar.gz
  wget -c http://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86/LibreOffice_${version}_Linux_x86_rpm_langpack_fr.tar.gz.asc
  wget -c http://downloadarchive.documentfoundation.org/libreoffice/old/${version}/rpm/x86/LibreOffice_${version}_Linux_x86_rpm_langpack_fr.tar.gz
  for asc in *.asc ; do gpg --verify $asc ; done
}

postgresql() {
  wget -c https://ftp.postgresql.org/pub/source/v${version}/postgresql-${version}.tar.bz2.sha256
  dlsource https://ftp.postgresql.org/pub/source/v${version}/postgresql-${version}.tar.bz2
}

jansson() {
  wget -c http://www.digip.org/jansson/releases/jansson-${version}.tar.bz2.asc
  dlsource http://www.digip.org/jansson/releases/jansson-${version}.tar.bz2
}

privoxy() {
  wget -c http://www.privoxy.org/sf-download-mirror/Sources/${version}%20%28stable%29/privoxy-${version}-stable-src.tar.gz.asc
  dlsource http://www.privoxy.org/sf-download-mirror/Sources/${version}%20%28stable%29/privoxy-${version}-stable-src.tar.gz
}

veracrypt() {
  wget -c https://launchpad.net/veracrypt/trunk/${version}/+download/VeraCrypt_${version}_Source.tar.bz2.sig
  dlsource https://launchpad.net/veracrypt/trunk/${version}/+download/VeraCrypt_${version}_Source.tar.bz2
}

sshfs-fuse() {
  wget -c https://github.com/libfuse/sshfs/releases/download/sshfs-${version}/sshfs-${version}.tar.gz.asc
  dlsource https://github.com/libfuse/sshfs/releases/download/sshfs-${version}/sshfs-${version}.tar.gz
}

evince() {
  dlsource http://ftp.gnome.org/pub/GNOME/sources/evince/"$(echo ${version} | cut -d . -f 1,2)"/evince-${version}.tar.xz
}

seahorse() {
  dlsource https://download.gnome.org/sources/seahorse/"$(echo ${version} | cut -d . -f 1,2)"/seahorse-${version}.tar.xz
}

borgbackup() {
  dlsource https://github.com/borgbackup/borg/releases/download/${version}/borgbackup-${version}.tar.gz
}

llfuse() {
  dlsource https://github.com/python-llfuse/python-llfuse/archive/release-${version}.tar.gz
}

python-fuse() {
  dlsource https://github.com/libfuse/python-fuse/archive/v${version}.tar.gz
}

rspamd() {
  dlsource https://github.com/rspamd/rspamd/archive/${version}/rspamd-${version}.tar.gz
}

gramps() {
  wget -c https://github.com/gramps-project/gramps/archive/v${version}/gramps-${version}.zip
  md5sum gramps-${version}.zip > gramps-${version}.zip.md5
  cat gramps-${version}.zip.md5
}

gtksourceview() {
  dlsource http://ftp.gnome.org/pub/GNOME/sources/gtksourceview/$(echo ${version} | cut -d \. -f 1,2)/gtksourceview-${version}.tar.xz
}

glade() {
  dlsource http://ftp.gnome.org/pub/GNOME/sources/glade/$(echo ${version} | cut -d \. -f 1,2)/glade-${version}.tar.xz
}

intel-microcode() {
  dlsource https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files/archive/microcode-${version}.tar.gz
}

cantata() {
  dlsource https://github.com/CDrummond/cantata/releases/download/v${version}/cantata-${version}.tar.bz2
}

copyq() {
  dlsource https://github.com/hluk/CopyQ/archive/v${version}.tar.gz
}

tesseract() {
  dlsource https://github.com/tesseract-ocr/tesseract/archive/${version}.tar.gz
  wget -c -O eng.traineddata-${version} https://github.com/tesseract-ocr/tessdata/raw/master/eng.traineddata
  md5sum eng.traineddata-${version} > eng.traineddata-${version}.md5
  wget -c -O fra.traineddata-${version} https://github.com/tesseract-ocr/tessdata/raw/master/fra.traineddata
  md5sum fra.traineddata-${version} > fra.traineddata-${version}.md5
  wget -c -O spa.traineddata-${version} https://github.com/tesseract-ocr/tessdata/raw/master/spa.traineddata
  md5sum spa.traineddata-${version} > spa.traineddata-${version}.md5
  cat *${version}*.md5
}

pyfuse3() {
  dlsource https://github.com/libfuse/pyfuse3/archive/release-${version}.tar.gz
}

ragel() {
  wget -c https://www.colm.net/files/ragel/ragel-${version}.tar.gz.asc
  dlsource https://www.colm.net/files/ragel/ragel-${version}.tar.gz
}

putty() {
  dlsource https://the.earth.li/~sgtatham/putty/latest/putty-${version}.tar.gz
}

qt() {
  dlsource https://download.qt.io/archive/qt/$(echo ${version} | cut -d \. -f 1,2)/${version}/single/qt-everywhere-src-${version}.tar.xz
}

oniguruma() {
  dlsource https://github.com/kkos/oniguruma/releases/download/v${version}/onig-${version}.tar.gz
}

fail2ban() {
  wget https://github.com/fail2ban/fail2ban/releases/download/${version}/fail2ban-${version}.tar.gz.asc
  dlsource https://github.com/fail2ban/fail2ban/releases/download/${version}/fail2ban-${version}.tar.gz
}

docker() {
  dlsource https://github.com/docker/docker-ce/archive/v${version}/docker-ce-${version}.tar.gz
}

containerd() {
  dlsource https://github.com/containerd/containerd/archive/v${version}/containerd-${version}.tar.gz
}

coturn() {
  dlsource https://github.com/coturn/coturn/archive/${version}/coturn-${version}.tar.gz
}

youtube-dl() {
  wget https://github.com/ytdl-org/youtube-dl/releases/download/${version}/youtube-dl-${version}.tar.gz.sig
  dlsource https://github.com/ytdl-org/youtube-dl/releases/download/${version}/youtube-dl-${version}.tar.gz
}

haveged() {
  dlsource https://github.com/jirka-h/haveged/archive/v${version}.tar.gz
}

xxHash() {
  dlsource https://github.com/Cyan4973/xxHash/archive/v${version}.tar.gz
}

signal-desktop() {
  wget -c https://updates.signal.org/desktop/apt/pool/s/signal-desktop/signal-desktop_${version}_amd64.deb || exit 1
  md5sum signal-desktop_${version}_amd64.deb > signal-desktop_${version}_amd64.deb.md5
  cat signal-desktop_${version}_amd64.deb.md5
}

lagrange() {
  dlsource https://git.skyjake.fi/skyjake/lagrange/releases/download/v${version}/lagrange-${version}.tar.gz
}

prosody() {
  dlsource https://prosody.im/downloads/source/prosody-${version}.tar.gz
}


if [ -z "$(functions $pkg)" ]; then
  echo "$pkg non pris en charge."
  exit 1
fi

$pkg || exit 1
