161 lines
5.7 KiB
Bash
Executable File
161 lines
5.7 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
|
|
# options
|
|
PROJDIR="ccvt"
|
|
DESTDIR="/usr/bin/"
|
|
ORIGBIN="$PWD/bin/ccvt"
|
|
ICONDIR="/usr/share/icons/"
|
|
ICONFIL="$PWD/pix/ccvt.svg"
|
|
DESKDIR="/usr/share/applications/"
|
|
DESKFIL="$PWD/ccvt.desktop"
|
|
SHARDIR="/usr/share/ccvt"
|
|
PICSDIR="$SHARDIR/pix/"
|
|
ORIGPIX="$PWD/pix"
|
|
ORIGGUI="$ORIGBIN-gui"
|
|
#MANPATH="/usr/share/man/man8"
|
|
#ZIPPROG="gzip"
|
|
ROOTCMD="sudo" # default is sudo (because it's more widely used), doas is
|
|
# recommended though: it's safer and more minimalist
|
|
#MKWICMD="makewhatis"
|
|
#MKWIDIR="/usr/share/man"
|
|
DISTCMD="cat /etc/*-release"
|
|
PKGMGR="apt-get update && apt-get install"
|
|
X11="libx11-dev"
|
|
DEPS="curl jq"
|
|
|
|
|
|
# vars
|
|
success=0
|
|
ops=0
|
|
|
|
addSuccess() {
|
|
success=$((success + 1))
|
|
}
|
|
addOp() {
|
|
ops=$((ops + 1))
|
|
}
|
|
|
|
# check dir
|
|
[ "$(basename "$PWD")" != "$PROJDIR" ] && printf "Please make sure that you're in the project directory named \"%b\".\n" "$PROJDIR" && exit 1
|
|
|
|
# check root
|
|
touch /ccvtInstallationRootCheckFile 2> /dev/null &&
|
|
rm /ccvtInstallationRootCheckFile 2> /dev/null &&
|
|
printf "Running as root.\n" &&
|
|
ROOTCMD=""
|
|
|
|
# install dependencies
|
|
! command -v curl || ! command -v jq || ! [ -f "/usr/include/X11/Xlib.h" ] && {
|
|
# determine package manager
|
|
if $DISTCMD | grep "Arch\|Manjaro\|Garuda" ; then PKGMGR="pacman -Syu"
|
|
X11="libx11"
|
|
elif $DISTCMD | grep "OpenMandriva\|RedHat Enterprise\|Fedora"; then PKGMGR="dnf upgrade && dnf install"
|
|
X11="libX11-devel"
|
|
elif $DISTCMD | grep "Chromium\|Chrome\|Gentoo" ; then printf "You're on Gentoo, so I trust you can manage to figure it all out by yourself. Install %b and %b.\n" "$DEPS" "$X11"
|
|
exit 1
|
|
elif $DISTCMD | grep "Void" ; then PKGMGR="xbps-install -Syu"
|
|
X11="libX11-devel"
|
|
elif $DISTCMD | grep "FreeBSD" ; then PKGMGR="pkg install"
|
|
X11="libX11"
|
|
elif $DISTCMD | grep "OpenBSD\|NetBSD" ; then PKGMGR="pkg_add"
|
|
X11="libx11" # not sure if this is its name
|
|
elif $DISTCMD | grep "OS X\|MacOS" ; then if command -v brew; then PKGMGR="brew install"
|
|
else printf "Please install the brew package manager and re-run this script.\n"
|
|
exit 1
|
|
fi
|
|
else
|
|
printf "Unknown distro. Please install %b and %b manually and re-run this script.\n" "$DEPS" "$X11"
|
|
exit 1
|
|
fi
|
|
|
|
# use package manager
|
|
addOp
|
|
$ROOTCMD $PKGMGR $DEPS "$X11" &&
|
|
addSuccess
|
|
}
|
|
|
|
# dowload Nuklear
|
|
addOp
|
|
curl https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/master/nuklear.h > /tmp/nuklear.h &&
|
|
$ROOTCMD mv /tmp/nuklear.h /usr/include/ &&
|
|
printf "Downloaded Nuklear library.\n" &&
|
|
addSuccess
|
|
|
|
|
|
# compile
|
|
addOp
|
|
make &&
|
|
printf "Compiled ccvt.\n" &&
|
|
addSuccess
|
|
|
|
# copy the binary (1)
|
|
addOp
|
|
! [ -d "$DESTDIR" ] && $ROOTCMD mkdir -p "$DESTDIR"
|
|
$ROOTCMD mv "$ORIGBIN" "$DESTDIR" &&
|
|
printf "Copied binary file over to \"%b\".\n" "$DESTDIR" &&
|
|
addSuccess
|
|
|
|
# copy the binary (2)
|
|
addOp
|
|
$ROOTCMD mv "$ORIGGUI" "$DESTDIR" &&
|
|
printf "Copied binary file (GUI) over to \"%b\".\n" "$DESTDIR" &&
|
|
addSuccess
|
|
|
|
# copy manpage
|
|
#addOp
|
|
#$ROOTCMD cp ccvt.1 "$MANPATH" &&
|
|
#printf "Copied manpage over to \"%b\".\n" "$MANPATH" &&
|
|
#addSuccess &&
|
|
#addOp &&
|
|
#$ROOTCMD $ZIPPROG "$MANPATH/ccvt.1" &&
|
|
#printf "%b'd manpage.\n" "$ZIPPROG" &&
|
|
#addSuccess
|
|
|
|
# run makewhatis
|
|
#addOp
|
|
#$ROOTCMD $MKWICMD "$MKWIDIR" &&
|
|
#printf "Ran %b on %b.\n" "$MKWICMD" "$MKWIDIR" &&
|
|
#addSuccess
|
|
|
|
# copy exchange rate updater
|
|
addOp
|
|
$ROOTCMD cp "update-eRates.sh" "$DESTDIR" &&
|
|
printf "Copied update-eRates.sh over to \"%b\".\n" "$DESTDIR" &&
|
|
addSuccess
|
|
|
|
# fetch currency exchange rates
|
|
if [ "$ROOTCMD" != "" ]; then
|
|
addOp
|
|
update-eRates.sh &&
|
|
printf "Fetched latest currency rates.\n" &&
|
|
addSuccess
|
|
else
|
|
printf "Please, run \"update-eRates.sh\" manually, otherwise, ccvt will not be able to work.\n"
|
|
fi
|
|
|
|
# copy icon
|
|
addOp
|
|
! [ -d "$ICONDIR" ] && $ROOTCMD mkdir -p "$ICONDIR"
|
|
$ROOTCMD cp "$ICONFIL" "$ICONDIR" &&
|
|
printf "Copied icon to \"%b\".\n" "$ICONDIR" &&
|
|
addSuccess
|
|
|
|
# copy .desktop file
|
|
addOp
|
|
! [ -d "$DESKDIR" ] && $ROOTCMD mkdir -p "$DESKDIR"
|
|
$ROOTCMD cp "$DESKFIL" "$DESKDIR" &&
|
|
printf "Copied .desktop file to \"%b\".\n" "$DESKDIR" &&
|
|
addSuccess
|
|
|
|
# copy pictures
|
|
addOp
|
|
! [ -d "$PICSDIR" ] && $ROOTCMD mkdir -p "$PICSDIR"
|
|
$ROOTCMD cp -r "$ORIGPIX"/* "$PICSDIR" &&
|
|
printf "Copied pics to \"%b\".\n" "$PICSDIR" &&
|
|
addSuccess
|
|
|
|
# done
|
|
if [ "$success" = "$ops" ]; then printf "Done! Enjoy.\n"
|
|
else printf "Error: installation failed.\n" && exit 1
|
|
fi
|