Skip to content

Instantly share code, notes, and snippets.

@StefanoBelli
Last active June 22, 2016 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanoBelli/4e86ddb71cdbde100b2f to your computer and use it in GitHub Desktop.
Save StefanoBelli/4e86ddb71cdbde100b2f to your computer and use it in GitHub Desktop.
[portage] Automatically add ebuild to portage tree
#!/bin/sh
LPORTDIR=/usr/portage #Change this if it is not your tree
GETCATEGORY=$1 #Category (such as x11-themes)
GETNAME=$2 #Name (such as numix-icon-theme)
FULLNAME=""
DIRTREE=""
CHECKDIR=""
## VARIOUS USEFUL FUNCITONS ##
function msg()
{
printf "\033[33m*\033[0m $@\n"
}
function succ()
{
printf "\033[32m*\033[0m $@\n"
}
function warn()
{
printf "\033[33m*\033[0m $@\n"
}
function err()
{
printf "\033[31m*\033[0m $@\n"
}
function ask()
{
printf "\033[35m*\033[0m $@ "
}
## ##
# script <category> <name>
if [[ $# < 2 ]] || [[ $# > 2 ]];
then
err "Non-valid usage!"
err "Usage: $0 <category> <name>"
exit 2
fi
#Check before adding
function pre_checks()
{
if which ebuild 2>/dev/null >>/dev/null;
then
succ "Ebuild ... Found"
else
err "Ebuild ... Not found"
exit 3
fi
if [ -d $LPORTDIR ];
then
succ "Portage tree ... Found"
else
err "Portage tree ... Not found"
exit 4
fi
if FULLNAME=$(ls ${GETNAME}* 2>/dev/null) ;
then
echo ""
else
FULLNAME="nullebuild"
err "Cannot find ebuild!"
fi
if [ -f $FULLNAME ];
then
succ "$FULLNAME ... Found"
else
err "Ebuild ... Not found"
exit 8
fi
DIRTREE=${LPORTDIR}/${GETCATEGORY}/${GETNAME}
if [ -d $DIRTREE ];
then
msg "${DIRTREE} ... found"
CHECKDIR="yes"
else
CHECKDIR="no"
fi
succ ">>> Checking phase passed... Adding ${GETCATEGORY}/${GETNAME}"
}
#Add to portage tree
function add()
{
if [[ $CHECKDIR == "yes" ]];
then
ask "An ebuild called ${GETCATEGORY}/${GETNAME} may exist. Would you like to continue? [y/N]:"
read CHOICE
if [[ $CHOICE == "y" ]] || [[ $CHOICE == "Y" ]];
then
echo ""
elif [[ $CHOICE == "n" ]] || [[ $CHOICE == "N" ]];
then
warn "Good choice!"
exit 9
else
exit 11
fi
elif [[ $CHECKDIR == "no" ]];
then
warn "Continue..."
fi
msg "Creating ${LPORTDIR}/${GETCATEGORY}/${GETNAME}"
if mkdir -p ${LPORTDIR}/${GETCATEGORY}/${GETNAME} 2>/dev/null;
then
succ "Created directory ... ok"
else
err "Error while creating directory ... fail"
exit 6
fi
msg "Copying ebuild ..."
if cp -f $FULLNAME ${LPORTDIR}/${GETCATEGORY}/${GETNAME} 2>/dev/null;
then
succ "Ebuild copied ... ok"
else
err "Ebuild copying ... fail"
exit 45
fi
msg "Creating ebuild manifest ..."
cd ${LPORTDIR}/${GETCATEGORY}/${GETNAME}
if ebuild $FULLNAME digest 2>/dev/null;
then
succ "Created Manifest ... ok"
else
err "Error while creating Manifest ... fail"
exit 30
fi
msg "Now just execute "
msg "emerge ${GETCATEGORY}/${GETNAME}"
succ ">>> Done"
}
if [ $(id -u) -eq 0 ];
then
msg ">>> Checking before adding... ${GETCATEGORY}/${GETNAME}"
pre_checks
msg ">>> Adding to portage tree... ${GETCATEGORY}/${GETNAME}"
add
else
err "You must be root"
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment