#!/bin/bash ###################################################################### # # Author: Andrwe Lord Weber # Mail: lord-weber-andrwerenona-studiosorg # Version: 0.7.7 # ###################################################################### ###################################################################### # # script variables and functions # ###################################################################### # Set name of the repository REPONAME="andrwe" # Set all supported architectures ARCH=("i686" "x86_64") # Set repository-root directory in which should exist one folder for # each architecture called like the architecture REPO="/data/repo/pkgs" # Set chroot-root directory in which should exist one folder with an # existing chroot environment for each architecture CHROOT="/data/repo" # Set whether -any packages has there own directory in $REPO # 0 = false # 1 = true ANY_OWN_DIR=0 ###################################################################### # # No changes needed after this line. # ###################################################################### PKGDIR=${PWD} LOCKFILE=/tmp/$(basename ${0}).lock # Check for existence of needed directories [ ! -d "${CHROOT}" ] && echo "The chroot-root directory (${CHROOT}) doesn't exist." && exit 1 [ ! -w "${CHROOT}" ] && echo "The chroot-root directory (${CHROOT}) isn't writeable." && exit 1 [ ! -d "${REPO}" ] && echo "The repository-root directory (${REPO}) doesn't exist." && exit 1 [ ! -w "${REPO}" ] && echo "The repository-root directory (${REPO}) isn't writeable." && exit 1 # Function to build package and copy the resulting file to the # repository directory # Needs architectures to be given as first Parameter function make() { source ./PKGBUILD [ ! -d "${CHROOT}/${1}/root" ] && echo "The chroot environment for the architecture ${1} (${CHROOT}/${1}/root) doesn't exist." && exit 1 [ ! -d "${REPO}/${1}" ] && echo "The repository directory for the architecture ${1} (${REPO}/${1}) doesn't exist." && exit 1 [ ! -w "${REPO}/${1}" ] && echo "The repository directory for the architecture ${1} (${REPO}/${1}) isn't writeable." && exit 1 for pkgfile in *-{any,${1}}.pkg.tar.* do [ -f ${pkgfile} ] && echo -e "\nRemoving old pkg-file ${pkgfile} in $(pwd) ...\n" && sudo rm -v ${pkgfile} && echo -e "\n... done\n" done sudo makechrootpkg -u -c -r ${CHROOT}/${1} copy ${1} } function copy() { source "${PKGDIR}"/PKGBUILD if [ "${arch[0]}" == 'any' ] then subdir=${1} [ ${ANY_OWN_DIR} -eq 1 ] && subdir=any [ -f *-any.pkg.tar.* ] && pkg=`ls *-any.pkg.tar.*` && echo -e "\nCopying package to ${REPO}/${subdir} ...\n" && cp -vr ${pkg}\ ${REPO}/${subdir}/ && echo -e "\n... done\n" && cd ${REPO}/${subdir}/ && echo -e "\nAdding package to repository ...\n" && repo-add ${REPONAME}.db.tar.gz ${pkg}\ && echo -e "\n... done\n" && cd ${PKGDIR} if [ ${subdir} == 'any' ] then for archs in ${ARCH[@]} do ln -s ${REPO}/${subdir}/${pkg} ${REPO}/${archs}/ repo-add ${REPO}/${archs}/${REPONAME}.db.tar.gz ${REPO}/${subdir}/${pkg} done fi else [ -f *-${1}.pkg.tar.* ] && pkg=`ls *-${1}.pkg.tar.*` && echo -e "\nCopying package to ${REPO}/${1} ...\n" && cp -vr ${pkg}\ ${REPO}/${1}/ && echo -e "\n... done\n" && cd ${REPO}/${1}/ && echo -e "\nAdding package to repository ...\n" && repo-add ${REPONAME}.db.tar.gz ${pkg}\ && echo -e "\n... done\n" && cd ${PKGDIR} fi } # Main functionality which checks for all needed variables, pathes and # programs, builds the package and synchronizes with the server using the sync function. function main() { [ -e ${LOCKFILE} ] && echo -e "An instance of $(basename ${LOCKFILE}) is already running.\nIf you are sure it isn't remove ${LOCKFILE}." && exit 1 if [ -f PKGBUILD ] then if [ ! "`grep startdir PKGBUILD`" -a ! "`grep install\=\( PKGBUILD`" ] then touch ${LOCKFILE} if [ "${1}" != "" ] then i=0 archnum=$((${#ARCH[@]} - 1)) if [[ "${1}" == [0-9]* ]] then if [ ${1} -le ${archnum} -a ${1} -ge 0 ] then arch=${ARCH[${1}]} else echo "The given number should be between 0 and ${archnum}" usage && exit 1 fi else echo -e "The given parameter isn't a number.\nIt should be a number between 0 and ${archnum}." usage && exit 1 fi make ${arch} else any=0 for archs in ${ARCH[@]} do if [ ${any} -eq 1 ] then [ ${ANY_OWN_DIR} -eq 1 ] && continue copy ${archs} continue fi source "${PKGDIR}"/PKGBUILD if [ "${arch[0]}" == 'any' ] then make ${archs} any=1 continue fi make ${archs} done fi rm ${LOCKFILE} else echo "PKGBUILD uses wrong variable \$startdir or initializes 'install=(' this would cause malfunction of makechrootpkg. Please correct this." fi else echo "There is no file called PKGBUILD in this directory." usage && exit 1 fi } function usage() { echo -e "This script creates packages for an Arch Linux repository." echo -e "It has to be started in the directory where the PKGBUILD is placed" echo -e "To correctly configure it just open it with an editor like nano or vim and alter the variables in the first section.\n\n" echo -e "You can either start this script without any parameters to build packages for all architectures or" echo -e "give one or more of the following numbers as parameter to build packages for only the(se) architecture:\n" i=0 for arch in ${ARCH} do echo "${i} -> ${arch}" i=$((${i}+1)) done } case "${1}" in -h|--help|-\?|\?|h) usage && exit 1 ;; *) trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT main $@ trap - INT TERM EXIT esac