Add electron eselect and update electron-bin meta a bit to produce cleaner install

This commit is contained in:
rexy712 2019-10-31 12:39:32 -07:00
parent ebcd27f260
commit 53e8a3595b
3 changed files with 121 additions and 5 deletions

View File

@ -0,0 +1,23 @@
# Copyright 2019 rexy712
# Distributed under the terms of the GNU General Public License v3
EAPI=7
DESCRIPTION="Manages versions of electron executables"
HOMEPAGE="https://www.gentoo.org/"
SRC_URI=""
LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""
DEPEND="app-admin/eselect"
RDEPEND=""
S="${FILESDIR}"
src_install() {
insinto /usr/share/eselect/modules
newins "${FILESDIR}"/electron-${PV}.eselect electron.eselect
}

View File

@ -0,0 +1,80 @@
inherit config
DESCRIPTION="Manage electron versions"
MAINTAINER="rexerton.rexy@tutamail.com"
VERSION="2.2"
USR_PATH="${EROOT%/}/usr"
active_slot() {
if [ -h "${USR_PATH}/bin/electron" ];then
readlink "${USR_PATH}/bin/electron" | xargs basename
else
echo "(none)"
fi
}
get_slots() {
local found_slots=()
for slot in $(find "${USR_PATH}/bin" -mindepth 1 -maxdepth 1 \( -type f -o -type l \) -regex "${USR_PATH}"'/bin/electron\(-bin\)?-[1-9][0-9.]+\(-r[1-9]+\)?$');do
[ -x "${slot}" ] && found_slots+=( "${slot##*/}" )
done
echo ${found_slots[@]}
}
describe_list() {
echo "List available electron slots"
}
do_list() {
write_list_start "Available electron slots"
if $(is_output_mode brief);then
echo $(get_slots)
else
i=1
for slot in $(get_slots);do
case "${slot}" in
"$(active_slot)" )
write_kv_list_entry "$i) $(highlight_marker ${slot})";;
*)
write_kv_list_entry "$i) ${slot}";;
esac
i=$((i+1))
done
[ -z "$(get_slots)" ] && write_warning_msg "No slots available."
fi
}
describe_show() {
echo "Get active slot"
}
do_show() {
echo "$(active_slot)"
}
describe_set() {
echo "Set the symlink for the electron application"
}
do_set() {
local selected="$1"
if [ -e "${USR_PATH}/bin/${selected}" ] && [[ "${selected}" =~ ^electron(-bin)?-[1-9][0-9.]+(-r[1-9]+)? ]];then
ln -sf "${USR_PATH}/bin/${selected}" "${USR_PATH}/bin/electron" || die
return
elif [[ "${selected}" =~ ^[1-9][0-9]*$ ]];then
slots=( $(get_slots) )
if [ "${selected}" -le ${#slots[@]} ];then
ln -sf "${USR_PATH}/bin/${slots[$((selected-1))]}" "${USR_PATH}/bin/electron" || die
return
fi
fi
die -q "Not a valid slot"
}
describe_unset() {
echo "Remove electron symlink"
}
do_unset() {
[ -h "${USR_PATH}/bin/electron" ] && rm /usr/bin/electron
}

View File

@ -1,5 +1,5 @@
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# Copyright 2019 rexy712
# Distributed under the terms of the GNU General Public License v3
EAPI=7
@ -50,11 +50,14 @@ RDEPEND="
x11-libs/libXtst
x11-libs/pango
"
DEPEND="app-arch/unzip"
DEPEND="
app-arch/unzip
>=app-eselect/eselect-electron-2.2
"
S="${WORKDIR}"
OPTPATH="opt/${MY_PN}-${VERSION_MAJ}.${VERSION_MIN}"
OPTPATH="opt/${MY_PN}/${PN}-${VERSION_MAJ}.${VERSION_MIN}"
QA_PRESTRIPPED="${OPTPATH}/.*"
pkg_setup() {
@ -74,5 +77,15 @@ src_install() {
# Note: intentionally not using "doins" so that we preserve +x bits
cp -r ./* "${ED}/${OPTPATH}" || die
dosym "../../${OPTPATH}/electron" "/usr/bin/electron-${VERSION_MAJ}.${VERSION_MIN}"
dosym "../../${OPTPATH}/electron" "/usr/bin/${PN}-${VERSION_MAJ}.${VERSION_MIN}"
}
pkg_postinst() {
if [ "$(eselect electron show)" == "(none)" ];then
eselect electron set "${PN}-${VERSION_MAJ}.${VERSION_MIN}"
fi
}
pkg_postrm() {
if [ "$(eselect electron show)" == "(none)" ];then
eselect electron set 1
fi
}