#!/bin/bash
#
#set -x


V_PRG_NAME="spotify-easyrpm"
V_CONFIG_FILE="${HOME}/.${V_PRG_NAME}"

V_SYS_ARCH="$(uname -i)"

V_PKGNAME="spotify-client"

V_TOPDIR=$(rpm --eval '%{_topdir}')
V_SOURCES_DIR="${V_TOPDIR}/SOURCES"
V_SPECS_DIR="${V_TOPDIR}/SPECS"
V_RPMS_DIR="${V_TOPDIR}/RPMS"
V_BUILDROOT_DIR="${V_TOPDIR}/BUILDROOT"

V_SNAP_EXTRACT_DIR="${V_SOURCES_DIR}/spotify-snap"

SYSTEMD_UNIT_DIR="${HOME}/.local/share/systemd/user"
SYSTEMD_UNIT="${SYSTEMD_UNIT_DIR}/${V_PRG_NAME}.service"
SYSTEMD_TIMER="${SYSTEMD_UNIT_DIR}/${V_PRG_NAME}.timer"
V_LOCAL_REPO="/var/cache/${V_PRG_NAME}"


f_logo() {
clear
cat <<EOF

┌─┐┌─┐┌─┐┌┬┐┬┌─┐┬ ┬   ┌─┐┌─┐┌─┐┬ ┬┬─┐┌─┐┌┬┐
└─┐├─┘│ │ │ │├┤ └┬┘───├┤ ├─┤└─┐└┬┘├┬┘├─┘│││
└─┘┴  └─┘ ┴ ┴└   ┴    └─┘┴ ┴└─┘ ┴ ┴└─┴  ┴ ┴
Version: 3.0.7
EOF
sleep 2
cat <<EOF
Spotify RPM tool for openSUSE / SLE
SUPPORT: https://github.com/megamaced/spotify-easyrpm/issues

MODE: ${V_RUN_MODE}
CHANNEL: ${PREF_CHANNEL}
EOF
}


f_help() {
cat <<EOF

${V_PRG_NAME} is a script which can download the latest Spotify snap package from snapcraft.io
repository and convert it into an RPM. It is also capable of installing, scheduling and storing
the RPMs in a local filesystem repo for installing Spotify updates alongside regular system updates


 ${V_PRG_NAME}

  - Regular prompt based mode to create an RPM and optionally install and create an update schedule

 ${V_PRG_NAME} --quiet

  - Create the RPM
  - Install the Spotify RPM
  - Set up a daily scheduled update job
  - Set up a local filesystem repo

 ${V_PRG_NAME} --set-channel edge

  - Set either "edge" or "stable" version of Spotify client

 ${V_PRG_NAME} --create-schedule

  - If you previously opted out creating an automated update schedule but now desire it

 ${V_PRG_NAME} --remove-schedule

  - Removes the schedule and local repo if present

 ${V_PRG_NAME} --clean-repo

  - Cleans up old versions from the local filesystem repo


EOF
 exit 0
}


f_error() {
echo "$1" 1>&2
echo "Please submit bug report to https://github.com/megamaced/spotify-easyrpm/issues"
f_cleanup
exit 1
}


f_cleanup() {
rm "${V_SOURCES_DIR:?}"/*.snap > /dev/null 2>&1
rm -rf "${V_SNAP_EXTRACT_DIR:?}" > /dev/null 2>&1
rm -rf "${V_SOURCES_DIR:?}"/"${V_PKGNAME}"* > /dev/null 2>&1
rm -rf "${V_SPECS_DIR}"/spotify.spec > /dev/null 2>&1
rm -rf "${V_BUILDROOT_DIR:?}"/"${V_PKGNAME}"* > /dev/null 2>&1
}

f_root_check() {
 if [[ "$(id -u)" == "0" ]]; then
  f_error "Do not run as root"
 fi
}


f_arch_check() {
 if [[ "${V_SYS_ARCH}" == x86_64 ]]; then
  V_RPM_ARCH=x86_64
 else
  f_error "Unsupported architecture. Aborting"
 fi
}


f_config() {
if [ -f "${V_CONFIG_FILE}" ]; then
 source "${V_CONFIG_FILE}"
else
 cat << EOF > "${V_CONFIG_FILE}"

# PREFS
PREF_PROMPT_SCHEDULE=YES
PREF_PROMPT_CHANNEL=YES
PREF_CHANNEL=stable

EOF
source "${V_CONFIG_FILE}"
fi

if [ -z "${PREF_CHANNEL}" ]; then
 echo "PREF_CHANNEL=stable" >> "${V_CONFIG_FILE}"
 source "${V_CONFIG_FILE}"
fi
if [[ ! "${PREF_CHANNEL}" == "stable" ]] && [[ ! "${PREF_CHANNEL}" == "edge" ]]; then
 sed -i "s/\(PREF_CHANNEL=\)\(.*\)/\1stable/" "${V_CONFIG_FILE}"
 source "${V_CONFIG_FILE}"
fi
if [ -z "${PREF_PROMPT_CHANNEL}" ]; then
 echo "PREF_PROMPT_CHANNEL=YES" >> "${V_CONFIG_FILE}"
 source "${V_CONFIG_FILE}"
fi
}


f_check_metered() {
  test -n "`(LC_ALL=C.UTF-8 ; export LC_ALL ; nmcli -t -f active,name connection show 2>/dev/null | sed -n 's/^yes://p' | while read ; do nmcli connection show "$REPLY" | grep '^connection\.metered:[[:space:]]*yes' ; done )`"
}

f_release_channel() {
if [[ "${PREF_PROMPT_CHANNEL}" == "YES" ]] && [[ "${V_RUN_MODE}" == "prompt" ]]; then
  while true
   do
    read -rp "Do you wish to download the Spotify stable or edge release (s/e)?" Q_RELEASE_CHANNEL

  case $Q_RELEASE_CHANNEL in
  s )  sed -i "s/\(PREF_PROMPT_CHANNEL=\)\(.*\)/\1NO/" "${V_CONFIG_FILE}"
       sed -i "s/\(PREF_CHANNEL=\)\(.*\)/\1stable/" "${V_CONFIG_FILE}"
       source "${V_CONFIG_FILE}"
       echo "Use --set-channel option to change it again"
       sleep 3
   break;;

  e )  sed -i "s/\(PREF_PROMPT_CHANNEL=\)\(.*\)/\1NO/" "${V_CONFIG_FILE}"
       sed -i "s/\(PREF_CHANNEL=\)\(.*\)/\1edge/" "${V_CONFIG_FILE}"
       source "${V_CONFIG_FILE}"
       echo "Use --set-channel option to change it again"
       sleep 3
   break;;

  esac
 done
 fi 
}

f_download() {
echo "Downloading the latest Spotify snap"
if ! wget -q -P "${V_SOURCES_DIR}"/ "${V_HTTP_REPO}"; then
f_error "Failed to download Spotify. Aborting"
fi
}


f_create_rpmbuild_dirs() {
echo "Creating build dirs in ${V_TOPDIR}"
if ! mkdir -p "${V_TOPDIR}"/{BUILD,BUILDROOT,OTHER,RPMS,SOURCES,SPECS,SRPMS}; then
f_error "Failed to create rpmbuild root. Aborting"
fi
V_RPMBUILD_OWNER_CHECK="$(find "${V_TOPDIR}" -not -user "$(id -u)")"
if [[ -n "${V_RPMBUILD_OWNER_CHECK}" ]]; then
  echo "Detected some directories / files not owned by you. Fixing ${V_RPMBUILD_OWNER_CHECK}"
  for i in ${V_RPMBUILD_OWNER_CHECK}; do
    sudo chown "$(id -u)" "$i"
  done
fi
if [[ ! -f "${HOME}"/.rpmmacros ]]; then
 echo "Creating ${HOME}/.rpmmacros"
 cat << EOF >> "${HOME}"/.rpmmacros
# Generated by ${V_PRG_NAME}
%_topdir ${V_TOPDIR}
EOF
fi
}


f_extract_snap() {
echo "Extracting snap and preparing"
unsquashfs -d "${V_SNAP_EXTRACT_DIR}"  "${V_SOURCES_DIR}"/"${V_HTTP_SNAP}" || f_error "Failed to extract snap"
mkdir -p "${V_SOURCES_DIR}"/"${V_PKGNAME}"/usr/{share/applications,bin}
mv "${V_SNAP_EXTRACT_DIR}"/usr/share/spotify "${V_SOURCES_DIR}"/"${V_PKGNAME}"/usr/share
mv "${V_SNAP_EXTRACT_DIR}"/usr/bin/spotify "${V_SOURCES_DIR}"/"${V_PKGNAME}"/usr/bin
}


f_script_location_check() {
if [[ ! -f /usr/bin/"${V_PRG_NAME}" ]] || ! diff "${0}" /usr/bin/"${V_PRG_NAME}" > /dev/null 2>&1; then
 echo "Copying ${V_PRG_NAME} to /usr/bin/${V_PRG_NAME} for the schedule to work"
 sudo cp "${0}" /usr/bin/"${V_PRG_NAME}"
fi
}


f_schedule_prompt() {
echo "Checking for an existing schedule"
 if [[ ! -f "${SYSTEMD_TIMER}" ]]; then
  if [[ "${V_RUN_MODE}" == "create-schedule" ]] || [[ "${PREF_PROMPT_SCHEDULE}" != "NO" ]]; then
  while true
  do
   read -rp "Do you wish to set up an automated update schedule (y/n)?" Q_SCHEDULE_ANSWER

  case $Q_SCHEDULE_ANSWER in
  y ) f_create_repo
      f_create_systemd_unit
      f_script_location_check
      break;;

  n ) echo "Ok skipping...If you want to create this in the future just run ${V_PRG_NAME} --create-schedule"
      sed -i "s/\(PREF_PROMPT_SCHEDULE=\)\(.*\)/\1NO/" "${V_CONFIG_FILE}"
      break;;

  esac
 done
else
  echo "Skipping schedule prompt as you previously opted out"
 fi
else
  echo "Found existing schedule. Skipping"
  f_update_local_repo
fi
}


f_remove_schedule() {
 if [[ -f "${SYSTEMD_UNIT}" ]]; then
  echo "Removing ${V_PRG_NAME} from your systemd unit files"
  systemctl --user disable spotify-easyrpm
  rm "${SYSTEMD_UNIT}"
  systemctl --user daemon-reload
 fi
 if [[ -f "${SYSTEMD_TIMER}" ]]; then
  echo "Removing ${V_PRG_NAME} from your systemd timers"
  systemctl --user disable spotify-easyrpm.timer
  rm "${SYSTEMD_TIMER}"
  systemctl --user daemon-reload
 fi
}

f_remove_repo() {
 if [[ -f /etc/zypp/repos.d/${V_PRG_NAME}.repo ]]; then
  echo "Removing ${V_PRG_NAME} zypper repo"
  sudo zypper rr "${V_PRG_NAME}"
 fi
 if [[ -d "${V_LOCAL_REPO}" ]]; then
  echo "Removing ${V_PRG_NAME} repo from filesystem"
  sudo rm -r "${V_LOCAL_REPO}"
 fi
}

f_install_build_deps() {
for pkg in rpm-build squashfs jq rpmdevtools hicolor-icon-theme; do
  if ! rpm -q "${pkg}" > /dev/null 2>&1; then
    echo "Installing build dependencies (${pkg})"
    if ! sudo zypper --non-interactive in "${pkg}"; then
      f_error "Failed to install build dependencies (${pkg}). Aborting"
    fi
  fi
done
}

f_prepare_src() {
echo "Preparing RPM src tarball"
f_desktop_entry
tar czf "${V_SOURCES_DIR}"/"${V_PKGNAME}"-"${V_HTTP_VERSION}".tar.gz -C "${V_SOURCES_DIR}"/ "${V_PKGNAME}"
}


f_desktop_entry() {
cat << EOF > "${V_SOURCES_DIR}"/"${V_PKGNAME}"/usr/share/applications/spotify.desktop
[Desktop Entry]
Name=Spotify
GenericName=Music Player
Comment=Spotify streaming music client
Icon=spotify-client
Exec=spotify %U
TryExec=spotify
Terminal=false
Type=Application
Categories=Audio;Music;Player;AudioVideo;Qt;
MimeType=x-scheme-handler/spotify
EOF
}


f_ver_compare() {
V_HTTP_REPO="$(curl -s -H 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/spotify | jq -r '."channel-map"[] | select(.channel.name=='\"$PREF_CHANNEL\"') | .download.url')"
V_HTTP_VERSION="$(curl -s -H 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/spotify | jq -r '."channel-map"[] | select(.channel.name=='\"$PREF_CHANNEL\"') | .version')"
V_HTTP_SNAP="$(basename "${V_HTTP_REPO}")"

# Read repo versions
readarray -t V_REPO_VERSION_NUMS < <( find "${V_LOCAL_REPO}" -type f -name "*.rpm" | sort | cut -f4 -d"-")

# Add installed version if available
if rpm -q "${V_PKGNAME}" > /dev/null 2>&1; then
  V_REPO_VERSION_NUMS+=("$(rpm -q "${V_PKGNAME}" | cut -f3 -d"-")")
fi

echo "Comparing snapcraft.io repo version to installed or local machine repo version (if any)"

# Default to TRUE
V_SNAPISNEWER=TRUE

# Compare versions
V_HIGHEST_VERSION="0"
for V_REPO_VERSION_NUM in "${V_REPO_VERSION_NUMS[@]}"; do
  if rpmdev-vercmp "$V_REPO_VERSION_NUM" "$V_HIGHEST_VERSION" | grep -q " > "; then
    V_HIGHEST_VERSION="$V_REPO_VERSION_NUM"
  fi
done

if rpmdev-vercmp "$V_HTTP_VERSION" "$V_HIGHEST_VERSION" | grep -q " > "; then
  V_SNAPISNEWER=TRUE
else
  V_SNAPISNEWER=FALSE
fi

if [[ "${V_SNAPISNEWER}" == "FALSE" ]]; then
 if [[ "${V_RUN_MODE}" != "prompt" ]]; then
  echo "${V_PKGNAME} ${V_HTTP_VERSION} is already installed or available from local machine repo. Quitting"
  f_cleanup
  exit 0
 else
 while true
  do
   echo "The latest $PREF_CHANNEL version at snapcraft.io is ${V_HTTP_VERSION} which is already installed or available from local machine repo. "
   read -rp "Continue anyway? (y/n)" Q_SAME_VER_CONTINUE
    case $Q_SAME_VER_CONTINUE in

      y ) echo "ok"
      break;;

      n ) f_schedule_prompt
          f_cleanup
          echo "bye"
      exit;;

   esac
 done
 fi
fi
}


f_rpm_spec() {
echo "Writing new build file"

cat << EOF > "${V_SPECS_DIR}"/spotify.spec
#
# spec file for package ${V_PKGNAME}
#
# Copyright (c) 2018 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

Name:   ${V_PKGNAME}
Version:  ${V_HTTP_VERSION}
Release:  0
License:  https://www.spotify.com/legal/end-user-agreement
Summary:  Spotify streaming music client
Vendor:   Spotify AB
Url:    https://www.spotify.com
Source:   %{name}-%{version}.tar.gz
BuildRoot:  %{_tmppath}/%{name}-%{version}-build
BuildRequires: hicolor-icon-theme
Requires: glibc
Requires: hicolor-icon-theme
Requires: libasound2
Requires: libatk-bridge-2_0-0
Requires: libatomic1
Requires: libcurl4
Requires: libgbm1
Requires: libglib-2_0-0
Requires: libgtk-3-0
Requires: mozilla-nss
Requires: libxshmfence1
Requires: libXss1
Requires: libXtst6
Requires: xdg-utils
Requires: libayatana-appindicator3-1
Recommends: libavcodec.so
Recommends: libavformat.so
Suggests: libnotify4
AutoReq:  no

%description

The Spotify desktop client officially supports Linux, but only Debian and
Ubuntu snap. This is an unofficial openSUSE re-packaging of the official
snap package. You can use it without snapd and dependent downloads.


If you are having severe problems with the native Linux client, there are a
few alternatives that you can try:

- Use the official snap (requires snapd is available in the openSUSE Build
  Service).
- Using the web player: https://play.spotify.com/
- Running the native Windows client in Wine (not recommended, but should
  work)

Otherwise, the native Linux client is the recommended way to listen to
Spotify on Linux systems.

%prep
%setup -q -n %{name}

%install
mkdir -p %{buildroot}%{_prefix}
cp -r usr %{buildroot}/
for ICON in %{buildroot}%{_datadir}/spotify/icons/*.png ; do
 FN=\`basename \$ICON\`
 SIZE=\`echo \$ICON | sed 's/.*\\/spotify-linux-\\([0-9]*\\)\\.png\$/\\1/'\`
 mkdir -p %{buildroot}%{_datadir}/icons/hicolor/\${SIZE}x\${SIZE}/apps
 ln -s ../../../../spotify/icons/\$FN %{buildroot}%{_datadir}/icons/hicolor/\${SIZE}x\${SIZE}/apps/spotify-client.png
done

%post
%desktop_database_post

if [ -f "%{_datadir}/icons/hicolor/index.theme" ]; then
  %{_bindir}/gtk-update-icon-cache --quiet --force "%{_datadir}/icons/hicolor"
fi

%postun
%desktop_database_postun

if [ -f "%{_datadir}/icons/hicolor/index.theme" ]; then
  %{_bindir}/gtk-update-icon-cache --quiet --force "%{_datadir}/icons/hicolor"
fi

%files
%defattr(-,root,root)
%{_datadir}/icons/hicolor/*/apps/spotify-client.png
%{_datadir}/spotify
%{_datadir}/applications/spotify.desktop
%{_bindir}/spotify
EOF
}


f_run_build() {
echo "Running rpm build"
if ! rpmbuild -bb --quiet --clean "${V_SPECS_DIR}"/spotify.spec; then
f_error "Spotify RPM failed to build. Aborting"
else
echo "Spotify RPM created in ${V_RPMS_DIR}/${V_RPM_ARCH}/"
fi
}


f_install_prompt() {
if [[ "${V_RUN_MODE}" != "prompt" ]]; then
  f_rpm_install
else
 while true
  do
   read -rp "Do you wish to install the Spotify RPM (y/n)?" Q_RPM_INSTALL

  case $Q_RPM_INSTALL in
  y ) f_rpm_install
   break;;

  n ) echo "OK not installing now"
   break;;

  esac
 done
fi
}


f_rpm_install() {
echo "Installing ${V_PKGNAME}-${V_HTTP_VERSION}"
if ! sudo zypper --non-interactive --no-gpg-checks in "${V_RPMS_DIR}"/"${V_RPM_ARCH}"/"${V_PKGNAME}"-"${V_HTTP_VERSION}"*"${V_RPM_ARCH}".rpm; then
  f_error "Failed to install ${V_PKGNAME}-${V_HTTP_VERSION}"
fi
}


f_create_repo() {
if ! rpm -q createrepo_c > /dev/null 2>&1; then
 echo "Installing CreateRepo for local filesystem repo"
 if ! sudo zypper --non-interactive in createrepo_c; then
 f_error "Failed to install createrepo. Aborting"
 fi
fi
if [[ ! -d "${V_LOCAL_REPO}" ]]; then
 echo "Creating local filesystem repo at ${V_LOCAL_REPO}"
 if ! sudo mkdir -p ${V_LOCAL_REPO}; then
  f_error "Failed to create local filesystem repo at ${V_LOCAL_REPO}. Aborting"
 fi
fi
if ! sudo find ${V_LOCAL_REPO} -type d -exec chmod 777 {} \+; then
 f_error "Failed to chmod ${V_LOCAL_REPO}"
fi
if ! sudo find ${V_LOCAL_REPO} -type f -exec chmod 666 {} \+; then
 f_error "Failed to chmod ${V_LOCAL_REPO}"
fi
f_update_local_repo
if [[ ! -f /etc/zypp/repos.d/${V_PRG_NAME}.repo ]]; then
 echo "Adding local file system repository to zypper"
 if ! sudo zypper ar -G --refresh "${V_LOCAL_REPO}" "${V_PRG_NAME}"; then
  f_error "Failed to add local repo to zypper. Aborting"
 fi
fi
}

f_create_systemd_unit() {
if [[ ! -f "${SYSTEMD_TIMER}" ]]; then
 echo "Creating automated Spotify builds"
 mkdir -p "${SYSTEMD_UNIT_DIR}"
 cat << EOF > "${SYSTEMD_UNIT}"
[Unit]
Description=${V_PRG_NAME} script

[Service]
ExecStart=/usr/bin/${V_PRG_NAME} --scheduled

EOF
 cat << EOF > "${SYSTEMD_TIMER}"
[Unit]
Description=${V_PRG_NAME} timer

[Timer]
OnBootSec=5min
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
EOF
  sed -i "s/\(PREF_PROMPT_SCHEDULE=\)\(.*\)/\1YES/" "${V_CONFIG_FILE}"
fi
systemctl --user daemon-reload
systemctl --user disable "${V_PRG_NAME}"
systemctl --user enable "${V_PRG_NAME}.timer"
}


f_update_local_repo() {
if [[ "${V_RUN_MODE}" != "clean-repo" ]]; then
echo "Moving any Spotify RPMs from your rpmbuild ${V_RPMS_DIR} to your local repo ${V_LOCAL_REPO}"
find "${V_RPMS_DIR}"/"${V_RPM_ARCH}"/ -name "${V_PKGNAME}-*${V_RPM_ARCH}.rpm" -type f -exec mv -t "${V_LOCAL_REPO}" {} \+
fi
if ! createrepo -q "${V_LOCAL_REPO}"; then
 f_error "Failed to create / update local repo. Aborting"
fi
}

f_clean_repo() {
sudo find "${V_LOCAL_REPO}" -type f -name "*.rpm" -exec rm {} \;
f_update_local_repo
echo "done!"
}

f_set_channel() {
if [[ -z $PREF_CHANNEL ]]; then
 f_error "Please specify either 'stable' or 'edge'"
else
 sed -i "s/\(PREF_CHANNEL=\)\(.*\)/\1$PREF_CHANNEL/" "${V_CONFIG_FILE}"
 sed -i "s/\(PREF_PROMPT_CHANNEL=\)\(.*\)/\1NO/" "${V_CONFIG_FILE}"
 echo "done!"
fi
}

f_main() {
while [ "$1" != "" ]; do
  case "$1" in
    -h | --help )       V_RUN_MODE="help"
                        f_logo
                        f_help
                        ;;
    --quiet )           V_RUN_MODE="quiet"
                        f_logo
                        f_install_build_deps
                        f_create_rpmbuild_dirs
                        f_release_channel
                        f_ver_compare
                        f_download
                        f_extract_snap
                        f_prepare_src
                        f_rpm_spec
                        f_run_build
                        f_install_prompt
                        f_create_repo
                        f_create_systemd_unit
                        f_script_location_check
                        break
                        ;;
    --scheduled | -scheduled )  V_RUN_MODE="scheduled"
                        if f_check_metered ; then break ; fi
                        f_release_channel
                        f_ver_compare
                        f_download
                        f_extract_snap
                        f_prepare_src
                        f_rpm_spec
                        f_run_build
                        f_update_local_repo
                        break
                        ;;
    --create-schedule ) V_RUN_MODE="create-schedule"
                        f_logo
                        f_schedule_prompt
                        break
                        ;;
    --remove-schedule ) V_RUN_MODE="remove-schedule"
                        f_logo
                        f_remove_schedule
                        f_remove_repo
                        break
                        ;;
    --clean-repo )      V_RUN_MODE="clean-repo"
                        f_logo
                        f_clean_repo
                        break
                        ;;
    --set-channel )     V_RUN_MODE="set-channel"
                        shift
                        PREF_CHANNEL="$1"
                        f_logo
                        f_set_channel
                        break
                        ;;
    * )                 V_RUN_MODE="invalid"
                        f_logo
                        echo "Unrecognised option. Run --help for more info"
                        exit 1
    esac
    shift
done
if [[ -z "${V_RUN_MODE}" ]]; then
V_RUN_MODE="prompt"
 f_logo
 f_install_build_deps
 f_create_rpmbuild_dirs
 f_release_channel
 f_ver_compare
 f_download
 f_extract_snap
 f_prepare_src
 f_rpm_spec
 f_run_build
 f_install_prompt
 f_schedule_prompt
fi
}


### EXECUTION BEGINS ###


f_root_check
f_arch_check
f_config
f_cleanup
f_main "$@"
f_cleanup
