#!/bin/sh

if [ -f qalculate ]; then
	read -p "Do you wish to copy the binaries to a different location? [yes]: " answer;
	if [ -z "$answer" ] || [ "$answer" = "y" ] || [ $answer = "yes" ]; then
		read -p "Copy binaries to [$HOME/.local/bin]: " execdir;
		if [ -z "$execdir" ]; then
			execdir="$HOME/.local/bin";
		fi
		if [ "$execdir" != "$PWD" ]; then
			if mkdir -p "$execdir"; then
				cp qalc "$execdir/qalc";
				cp qalculate "$execdir/qalculate";
			else
				exit 1;
			fi
		fi
	else
		execdir="$PWD";
	fi
else
	read -p "Location of qalculate binary: " execdir;
	if [ ! -f "$execdir/qalculate" ]; then
		echo "$execdir/qalculate was not found";
		exit 1;
	fi
fi

echo "Installing desktop file in $HOME/.local/share/applications";

mkdir -p "$HOME/.local/share/applications";

echo "[Desktop Entry]
Version=1.0
Name=Qalculate!
GenericName=Calculator
Comment=Powerful and easy to use calculator
TryExec=$execdir/qalculate
Exec=$execdir/qalculate
Icon=qalculate
Terminal=false
Type=Application
StartupNotify=true
StartupWMClass=qalculate
Categories=GTK;Utility;Calculator;Education;Science;Math;
Keywords=calculation;arithmetic;scientific;financial;
" > "$HOME/.local/share/applications/qalculate-gtk.desktop";

echo "Installing icon in $HOME/.local/share/icons";

mkdir -p "$HOME/.local/share/icons";

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<svg width=\"64\" height=\"64\" enable-background=\"new\" version=\"1.0\" xmlns=\"http://www.w3.org/2000/svg\"><title>Yaru Icon Theme Template</title><defs><linearGradient id=\"linearGradient1074-7\" x1=\"152\" x2=\"137.5\" y1=\"156\" y2=\"156\" gradientTransform=\"matrix(.21122 0 0 .26101 2.9547 226.98)\" gradientUnits=\"userSpaceOnUse\"><stop stop-opacity=\"0\" offset=\"0\"/><stop stop-opacity=\".15644\" offset=\"1\"/></linearGradient><linearGradient id=\"linearGradient943-0\" x1=\"216\" x2=\"216\" y1=\"28\" y2=\"284\" gradientTransform=\"matrix(.3041 0 0 .33558 -14.225 215.35)\" gradientUnits=\"userSpaceOnUse\"><stop stop-color=\"#d4279f\" offset=\"0\"/><stop stop-color=\"#fa3da3\" offset=\"1\"/></linearGradient><linearGradient id=\"linearGradient1694-7\" x1=\"38.31\" x2=\"264\" y1=\"270.69\" y2=\"268\" gradientTransform=\"matrix(0 .26101 -.26066 0 72.659 228.03)\" gradientUnits=\"userSpaceOnUse\"><stop stop-color=\"#4d4d4d\" offset=\"0\"/><stop stop-color=\"#4d4d4d\" offset=\"1\"/></linearGradient><filter id=\"filter58449-22\" x=\"-.047999\" y=\"-.048001\" width=\"1.096\" height=\"1.096\" color-interpolation-filters=\"sRGB\"><feGaussianBlur stdDeviation=\"4.4800539\"/></filter><filter id=\"filter58492-9\" x=\"-.012\" y=\"-.012\" width=\"1.024\" height=\"1.024\" color-interpolation-filters=\"sRGB\"><feGaussianBlur stdDeviation=\"1.1200135\"/></filter></defs><g transform=\"translate(0,-236)\"><g display=\"none\"><text id=\"context\" x=\"19.006836\" y=\"-8.2548828\" display=\"inline\" enable-background=\"new\" fill=\"#000000\" font-family=\"'DejaVu Sans'\" style=\"line-height:0%\" xml:space=\"preserve\"><tspan x=\"19.006836\" y=\"-8.2548828\" font-family=\"'DejaVu Sans'\" font-size=\"18px\" style=\"line-height:1.25\">apps</tspan></text><text id=\"icon-name\" x=\"146.48828\" y=\"-8.2548828\" display=\"inline\" enable-background=\"new\" fill=\"#000000\" font-family=\"'DejaVu Sans'\" font-weight=\"bold\" style=\"line-height:0%\" xml:space=\"preserve\"><tspan x=\"146.48828\" y=\"-8.2548828\" font-family=\"'DejaVu Sans'\" font-size=\"18px\" font-weight=\"bold\" style=\"line-height:1.25\">calculator-app</tspan></text><g fill=\"#cdcdcd\"><rect x=\"320\" y=\"236\" width=\"16\" height=\"16\" display=\"inline\" enable-background=\"accumulate\"/><rect x=\"320\" y=\"188\" width=\"24\" height=\"24\" display=\"inline\" enable-background=\"accumulate\"/><rect x=\"320\" y=\"132\" width=\"32\" height=\"32\" display=\"inline\" enable-background=\"accumulate\"/><rect x=\"320\" y=\"60\" width=\"48\" height=\"48\" display=\"inline\" enable-background=\"accumulate\"/><rect x=\"24\" y=\"28\" width=\"256\" height=\"256\" display=\"inline\" enable-background=\"accumulate\"/></g></g><path transform=\"matrix(.26066 0 0 .26101 -12.315 300.2)\" d=\"m243.08-235.5c35.297 0 39.095 3.6254 38.922 38.994v146.01c0.17299 35.368-3.6249 38.994-38.922 38.994h-146.16c-35.297 0-38.922-3.625-38.922-38.994v-146.01c0-35.369 3.6249-38.994 38.922-38.994z\" color=\"#000000\" enable-background=\"accumulate\" filter=\"url(#filter58492-9)\" opacity=\".1\"/><path transform=\"matrix(.26066 0 0 .26101 -12.315 300.2)\" d=\"m243.08-235.5c35.297 0 39.095 3.6254 38.922 38.994v146.01c0.17299 35.368-3.6249 38.994-38.922 38.994h-146.16c-35.297 0-38.922-3.625-38.922-38.994v-146.01c0-35.369 3.6249-38.994 38.922-38.994z\" color=\"#000000\" enable-background=\"accumulate\" filter=\"url(#filter58449-22)\" opacity=\".2\"/><path d=\"m12.948 238.47c-9.2004 0-10.145 0.94632-10.145 10.178v38.11c0 9.2314 0.94492 10.178 10.145 10.178h19.05v-58.465zm42.454 0.14835c5.087 0.49073 5.7676 2.4832 5.7874 9.7026 0.0145-7.2206-0.68834-9.2123-5.7874-9.7026zm5.7874 48.466c-0.0198 7.2194-0.70043 9.2119-5.7874 9.7026 5.0991-0.49029 5.8019-2.482 5.7874-9.7026z\" color=\"#000000\" enable-background=\"accumulate\" fill=\"url(#linearGradient1694-7)\"/><path d=\"m31.998 238.47v58.465h19.048c9.2004 0 10.145-0.9463 10.145-10.178v-38.11c0-9.2314-0.94492-10.178-10.145-10.178z\" enable-background=\"new\" fill=\"url(#linearGradient943-0)\"/><rect x=\"31.998\" y=\"238.99\" width=\"3.0627\" height=\"57.943\" enable-background=\"new\" fill=\"url(#linearGradient1074-7)\" fill-rule=\"evenodd\"/><path d=\"m2.8041 267.7v19.055c-0.0451 9.2313 0.94493 10.178 10.145 10.178h19.048v-29.233z\" enable-background=\"new\" fill=\"#fff\" opacity=\".1\"/><g transform=\"scale(.99933 1.0007)\" enable-background=\"new\" aria-label=\"x\"><path d=\"m23.432 257.17c-0.25214 0.28366-0.40972 0.47276-0.69338 0.85096-0.7249 0.94552-1.1031 1.2607-1.4813 1.2607-0.44124 0-0.72489-0.40972-0.94552-1.2922-0.09455-0.34669-0.09455-0.40973-0.12607-0.50428-0.78793-3.2148-1.1346-4.6645-1.1346-5.1373 1.4183-2.4583 2.5214-3.8136 3.0887-3.8136 0.1891 0 0.47276 0.0945 0.75641 0.25213 0.37821 0.22062 0.59883 0.28366 0.88248 0.28366 0.63034 0 1.0716-0.47276 1.0716-1.1346 0-0.69338-0.53579-1.1661-1.2922-1.1661-1.3868 0-2.5529 1.1346-4.7591 4.507l-0.34669-1.7334c-0.44124-2.1432-0.78793-2.7735-1.6389-2.7735-0.7249 0-1.7334 0.25213-3.6875 0.91399-0.1891 0.063-0.1891 0.063-0.34669 0.12607l0.12607 0.47276c1.2292-0.31517 1.4498-0.34669 1.765-0.34669 0.78793 0 0.97703 0.28366 1.4183 2.1747l0.914 3.8766-2.5844 3.6875c-0.66186 0.94551-1.2607 1.5128-1.6074 1.5128-0.1891 0-0.50428-0.0946-0.81945-0.28366-0.40972-0.22062-0.72489-0.31517-1.0085-0.31517-0.63034 0-1.0716 0.47276-1.0716 1.1031 0 0.81945 0.59883 1.3237 1.5759 1.3237s1.3552-0.28365 2.9311-2.1747c0.85096-1.0401 1.5443-1.9856 2.8365-3.719l0.94552 3.7821c0.40972 1.6389 0.81945 2.1116 1.828 2.1116 1.1977 0 2.0171-0.75641 3.8451-3.593z\" fill=\"#f2f2f2\" stroke-width=\".26083px\" style=\"font-feature-settings:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal\"/></g><g transform=\"scale(.99933 1.0007)\" enable-background=\"new\" aria-label=\"Ω\"><path d=\"m9.6084 285.59h0.41233q0.04458 0.79122 0.46804 1.1032 0.42347 0.31203 1.3484 0.31203h3.0423l-0.02229-0.74665q-1.7719-0.3566-3.2317-1.9725-1.4599-1.6159-1.4599-4.0787 0-2.7303 2.0282-4.6582 2.0393-1.9279 5.3157-1.9279 3.176 0 5.1931 1.8276 2.0171 1.8165 2.0171 4.6582 0 2.3068-1.2593 3.9227-1.2481 1.6047-3.3878 2.2288l-0.11144 0.74665h3.098q1.0587 0 1.393-0.40118 0.34546-0.40119 0.36775-1.0141h0.41233v3.488h-6.2406l0.28974-3.3655q2.8751-0.90266 2.8751-5.3156 0-2.8863-1.4153-4.4242-1.4041-1.5379-3.2986-1.5379-2.0171 0-3.3432 1.6382-1.315 1.627-1.315 4.1678 0 1.8388 0.59063 3.3543 0.59063 1.5044 2.2622 2.1174l0.21173 3.3655h-6.2406z\" fill=\"#f2f2f2\" stroke-width=\".26083px\" style=\"font-feature-settings:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal\"/></g><path d=\"m12.949 238.47c-9.2004 0-10.19 0.94642-10.145 10.178v0.52201c-0.0451-9.2313 0.94494-10.178 10.145-10.178h38.097c9.2004 0 10.145 0.9463 10.145 10.178v-0.52201c0-9.2314-0.94491-10.178-10.145-10.178z\" color=\"#000000\" enable-background=\"accumulate\" fill=\"#fff\" opacity=\".3\"/><path d=\"m12.951 296.93c-9.2004 0-10.19-0.94641-10.145-10.178v-0.52201c-0.0451 9.2313 0.94494 10.178 10.145 10.178h38.097c9.2004 0 10.145-0.9463 10.145-10.178v0.52201c0 9.2314-0.94492 10.178-10.145 10.178z\" color=\"#000000\" enable-background=\"accumulate\" opacity=\".2\"/><path d=\"m39.342 262.17v2.7667h14.462v-2.7667zm0 8.3v2.7667h14.462v-2.7667z\" color=\"#000000\" enable-background=\"accumulate\" fill=\"#fff\"/></g></svg>
" > "$HOME/.local/share/icons/qalculate.svg";

