#!/bin/bash
#  need lv2 plugins (eg. lv2-calf-plugin)

if [ `id -u` -ne 0 ]; then
  echo "you must be root"
fi

if [ $# -ne 1 ]; then
  echo "usage: $0 <os>"
  echo "  <os> = [centos | suse | ubuntu | ubuntu24 | fedora | mint | debian | arch | debian-older | ubuntu-older | termux]"
fi

dir="$1"


case "$dir" in
"centos")
  yum -y install nasm libavc1394-devel libusbx-devel flac-devel \
    libjpeg-devel libdv-devel libdvdnav-devel libdvdread-devel \
    libtheora-devel libiec61883-devel uuid-devel giflib-devel \
    ncurses-devel ilmbase-devel fftw-devel OpenEXR-devel \
    libsndfile-devel libXft-devel libXinerama-devel libXv-devel \
    xorg-x11-fonts-misc xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 \
    xorg-x11-fonts-ISO8859-1-100dpi xorg-x11-fonts-ISO8859-1-75dpi \
    libpng-devel bzip2-devel zlib-devel kernel-headers libtiff-devel \
    libavc1394 festival-devel libiec61883-devel flac-devel inkscape \
    libsndfile-devel libtheora-devel linux-firmware ivtv-firmware \
    libvorbis-devel texinfo xz-devel lzma-devel cmake udftools git \
    autoconf automake rpm-build jbigkit-devel libvdpau-devel libva-devel \
    alsa-lib-devel gtk2-devel pulseaudio-libs-devel libtool python
    yasm=yasm-1.3.0-3.fc24.x86_64.rpm
    release=http://archives.fedoraproject.org/pub/fedora/linux/releases/24
    url=$release/Everything/x86_64/os/Packages/y/$yasm
    wget -P /tmp $url
    yum -y install /tmp/$yasm
    rm -f /tmp/$yasm
  ;;
#"fedora3*")
#  dnf group install "Development Tools" -- substitute for older versions
#  dnf -y --best --allowerasing -- substitute for older versions
#  ... rpm-build lzma-sdk-devel libtool ...
# fedora for newest versions
"fedora")
  dnf group install development-tools
  dnf -y --best \
    install nasm yasm libavc1394-devel libusbx-devel flac-devel \
    libjpeg-devel libdv-devel libdvdnav-devel libdvdread-devel \
    libtheora-devel libiec61883-devel esound-devel uuid-devel \
    giflib-devel ncurses-devel ilmbase-devel fftw-devel OpenEXR-devel \
    libsndfile-devel libXft-devel libXinerama-devel libXv-devel \
    xorg-x11-fonts-misc xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 \
    xorg-x11-fonts-ISO8859-1-100dpi xorg-x11-fonts-ISO8859-1-75dpi \
    libpng-devel bzip2-devel zlib-devel kernel-headers libavc1394 \
    festival-devel libdc1394-devel libiec61883-devel esound-devel \
    flac-devel libsndfile-devel libtheora-devel linux-firmware \
    ivtv-firmware libvorbis-devel texinfo xz-devel cmake git \
    ctags patch gcc-c++ perl-XML-XPath libtiff-devel python dvdauthor \
    gettext-devel inkscape udftools autoconf automake numactl-devel \
    jbigkit-devel libvdpau-devel libva-devel gtk2-devel mesa-vdpau-drivers \
    pulseaudio-libs-devel libtool patchelf boost-devel
  ;;
#gtk2 may not be in distro; you can just use Calf plugins without UI
"arch")
    pacman -Syu gtk2 nasm yasm cmake fftw patchelf boost boost-libs \
    base-devel libvdpau libva perl-xml-parser perl-carp libogg texinfo \
    libsndfile
 ;;
"suse" | "leap" | "tumbleweed" | "slowroll")
  zypper -n install nasm gcc gcc-c++ zlib-devel texinfo libpng16-devel \
    freeglut-devel libXv-devel alsa-devel libbz2-devel ncurses-devel \
    libXinerama-devel freetype-devel libXft-devel giflib-devel ctags \
    bitstream-vera-fonts xorg-x11-fonts-core xorg-x11-fonts dejavu-fonts \
    openexr-devel libavc1394-devel festival-devel libjpeg8-devel libdv-devel \
    libdvdnav-devel libdvdread-devel libiec61883-devel libuuid-devel \
    ilmbase-devel fftw3-devel libsndfile-devel libtheora-devel flac-devel \
    libtiff-devel inkscape cmake patch libnuma-devel lzma-devel udftools git \
    yasm autoconf automake rpm-build libjbig-devel libvdpau-devel libva-devel \
    gtk2-devel libusb-1_0-devel libpulse-devel libtool python patchelf \
    libboost_regex-devel libboost_filesystem-devel
    if [[ ! -f /usr/lib64/libtermcap.so && ! -L /usr/lib64/libtermcap.so ]]; then
      ln -s libtermcap.so.2 /usr/lib64/libtermcap.so
    fi
  ;;
#debian 32bit: export ac_cv_header_xmmintrin_h=no
"debian-older")
  apt-get -f -y install apt-file sox nasm yasm g++ build-essential zlib1g-dev \
    texinfo libpng-dev freeglut3-dev libxv-dev libasound2-dev libbz2-dev \
    libncurses5-dev libxinerama-dev libfreetype6-dev libxft-dev libgif-dev \
    libtiff5-dev exuberant-ctags ttf-bitstream-vera xfonts-75dpi xfonts-100dpi \
    fonts-dejavu libopenexr-dev festival libfftw3-dev gdb libusb-1.0-0-dev \
    libdc1394-22-dev libflac-dev libjbig-dev libvdpau-dev libva-dev \
    inkscape libsndfile1-dev libtheora-dev cmake udftools libxml2-utils git \
    autoconf automake debhelper libgtk2.0-dev libpulse-dev python \
    patchelf libboost-filesystem-dev libboost-regex-dev fuse
  ;;
#"ub16-10")
#  apt-get -y install libx264-dev libx265-dev libvpx-dev libmjpegtools-dev
"ubuntu-older" | "mint" | "ub14" | "ub15" | "ub16" | "ub17" | "ub18" )
  apt-get -y install apt-file sox nasm yasm g++ build-essential libz-dev \
    texinfo libpng-dev freeglut3-dev libxv-dev libasound2-dev libbz2-dev \
    libncurses5-dev libxinerama-dev libfreetype6-dev libxft-dev libgif-dev \
    libtiff5-dev exuberant-ctags ttf-bitstream-vera xfonts-75dpi xfonts-100dpi \
    fonts-dejavu libopenexr-dev libavc1394-dev festival-dev fftw3-dev gdb \
    libdc1394-22-dev libiec61883-dev libflac-dev libjbig-dev libusb-1.0-0-dev \
    libvdpau-dev libva-dev libsndfile1-dev libtheora-dev cmake udftools \
    libxml2-utils git inkscape autoconf automake debhelper libgtk2.0-dev \
    libpulse-dev libtool python \
    patchelf libboost-filesystem-dev libboost-regex-dev
  ;;
#ubuntu for newest versions since about 06/2022
"ubuntu")
  apt-get -y install apt-file sox nasm yasm g++ build-essential libz-dev \
    texinfo libpng-dev freeglut3-dev libxv-dev libasound2-dev libbz2-dev \
    libncurses5-dev libxinerama-dev libfreetype6-dev libxft-dev libgif-dev \
    libtiff5-dev exuberant-ctags ttf-bitstream-vera xfonts-75dpi xfonts-100dpi \
    fonts-dejavu libopenexr-dev libavc1394-dev festival-dev fftw3-dev gdb \
    libdc1394-25 libdc1394-dev libiec61883-dev libflac-dev libjbig-dev libusb-1.0-0-dev \
    libvdpau-dev libva-dev libsndfile1-dev libtheora-dev cmake udftools \
    libxml2-utils git inkscape autoconf automake debhelper libgtk2.0-dev \
    libpulse-dev libtool 2to3 python-is-python3 python2-minimal python2 dh-python \
    patchelf libboost-filesystem-dev libboost-regex-dev libxml-parser-perl libimath-dev liblilv-dev
  ;;
#ub24.04 libgtk2.0-dev may not be in distro; you can just use Calf plugins without UI
"ubuntu24")
  apt-get -y install apt-file sox nasm yasm g++ build-essential libz-dev \
    texinfo libpng-dev freeglut3-dev libxv-dev libasound2-dev libbz2-dev \
    libncurses5-dev libxinerama-dev libfreetype6-dev libxft-dev libgif-dev \
    libtiff5-dev exuberant-ctags ttf-bitstream-vera xfonts-75dpi xfonts-100dpi \
    fonts-dejavu libopenexr-dev libavc1394-dev festival-dev lv2-dev libfftw3-dev gdb \
    libdc1394-25 libdc1394-dev libiec61883-dev libflac-dev libjbig-dev libusb-1.0-0-dev \
    libvdpau-dev libva-dev libsndfile1-dev libtheora-dev cmake udftools \
    libxml2-utils git inkscape autoconf automake debhelper libgtk2.0-dev \
    libpulse-dev libtool 2to3 python-is-python3 python3-minimal python3 dh-python \
    patchelf libboost-filesystem-dev libboost-regex-dev libxml-parser-perl libimath-dev liblilv-dev
  ;;
#debian for newest versions since about 06/2022 (add 2to3 package if python issues occur)
"debian")
  apt-get -f -y install apt-file sox nasm yasm g++ build-essential zlib1g-dev \
    texinfo libpng-dev freeglut3-dev libxv-dev libasound2-dev libbz2-dev \
    libncurses5-dev libxinerama-dev libfreetype6-dev libxft-dev libgif-dev \
    libtiff5-dev exuberant-ctags ttf-bitstream-vera xfonts-75dpi xfonts-100dpi \
    fonts-dejavu libopenexr-dev festival libfftw3-dev gdb libusb-1.0-0-dev \
    libdc1394-25 libdc1394-dev libflac-dev libjbig-dev libvdpau-dev libva-dev \
    inkscape libsndfile1-dev libtheora-dev cmake udftools libxml2-utils git \
    autoconf automake debhelper libgtk2.0-dev libpulse-dev python-is-python3  python3 dh-python \
    patchelf libboost-filesystem-dev libboost-regex-dev libxml-parser-perl fuse \
    lv2-dev libsratom-dev libsuil-dev liblilv-dev liba52-dev libtwolame-dev libdv-dev \
    libmp3lame-dev libavc1394-dev libiec61883-dev libavcodec-dev libavformat-dev libavfilter-dev
  ;;
"termux")
pkg in boost-static freetype-static gpac-static gtk2-static liba52-static libandroid-shmem-static \
libmp3lame-static libmpeg2-static libopencore-amr-static libpng-static libsndfile-static \
libtheora-static libtiff-static libtwolame-static libusb-static libvo-amrwbenc-static \
libxdg-basedir-static libxinerama-static libxpm-static libzimg-static python3 alsa-lib pulseaudio \
littlecms-static zlib-static clang texinfo cmake patchelf autoconf automake m4 libtool \
xorg-fonts-75dpi xorg-fonts-alias xorg-fonts-encodings fontconfig xz libiconv
  ;;
*)
  echo "unknown os: $dir"
  exit 1;
  ;;
esac

mkdir -p "/home/$dir/git-repo"
chmod a+rwx -R "/home/$dir/git-repo"

