#!/bin/sh
#Script to make CCR packages mentioned in packages.ccr
#V.-0.1
# AUTHOR - iruel <cockmomgler at gmail dot com>
#aurscript.sh AUTHOR - PDG - sHy [pdg@archlinux.us] , Thanks to Mike Tuffin for his ideas.
arch=$(uname -m)
reponame="custom"
startdir=$(pwd)
#defpath=$(grep PKGDEST /etc/makepkg.conf | cut -d"=" -f2)
defpath="${startdir}/work-${arch}/ccr-packages"
#URL="http://github.com/archbang/ArchBang/raw/master/packages.list.aur"
pacman_conf="${startdir}/overlay/etc/pacman.conf"
error=false
# do UID checking here so someone can at least get usage instructions
if [ "$EUID" != "0" ]; then
echo "error: This script must be run as root."
echo "try using 'sudo ./build-ccr.sh'"
exit 1
fi
# Check if packages.ccr exists in the same directory
if [ ! -f ${startdir}/packages.ccr ]; then
echo "You need to create a 'packages.ccr' file and fill it"
echo "with CCR package names before proceeding."
exit 1
fi
# Prompt the user for a custom package storage path
echo "Your packages will be by default stored in $defpath"
read -p "Would you like to set a custom storage path? (Y/N): "
if [[ "$REPLY" =~ ^[yY] ]]; then
echo "Enter the exact path to your custom package storage location: "
read newpath
mkdir -p $newpath &>/dev/null
echo "Path successfully created if it didn't already exist!"
sed -i "/PKGDEST/d" /etc/makepkg.conf
echo "PKGDEST=$newpath" >> /etc/makepkg.conf
echo "Path changed! Your package location is : $newpath"
echo "Press Enter to continue"
read
cd $newpath
defpath=$newpath
mkdir -p $defpath/ccrbuild &>/dev/null
else
echo "Path not changed! Your package location is still : $defpath"
mkdir -p $defpath &>/dev/null
mkdir -p $defpath/ccrbuild &>/dev/null
sed -i "/PKGDEST/d" /etc/makepkg.conf
echo "PKGDEST=$defpath" >> /etc/makepkg.conf
echo "Press Enter to continue"
read
fi
# Build the packages in defpath
cd $defpath/ccrbuild/
#wget $URL
cp ${startdir}/packages.ccr packages.ccr
for i in $(sed -e 's/\#.*//' -e 's/[ ^I]*$$//' -e '/^$$/ d' packages.ccr); do wget http://chakra-project.org/ccr/packages/$i/$i.tar.gz; done
for a in `ls -1 *.tar.gz`; do tar -zxvf $a; done
rm *.tar.gz
rm packages.ccr
for dir in $defpath/ccrbuild/*
do
(cd $dir && makepkg -rsf --asroot && mv *.pkg.tar.xz ../)
done
repo-add $defpath/${reponame}.db.tar.gz $defpath/*.pkg.tar.xz
echo ""
echo "Cleaning up..."
echo ""
rm -r $defpath/ccrbuild/
chmod -R ugo+rX $defpath
if [ $? = 0 ]; then
echo "A package repository has been successfully created."
echo "However, review the output; some packages may have failed to build."
echo ""
echo "Would you like to automatically add this repository to"
read -p "the profile's pacman.conf? [Y/N]:"
if [[ "$REPLY" =~ ^[yY] ]]; then
echo "
[${reponame}]
Server = file://${defpath}/" >> ${pacman_conf}
else
echo ""
echo "Don't forget to add the below to 'overlay/etc/pacman.conf' manually:"
echo "
[${reponame}]
Server = file://${defpath}/"
fi
echo ""
echo "Would you also like to append 'packages.ccr' to packages.${arch}?"
read -p "(if you've already done this, DO NOT do it again.) [Y/N]:"
if [[ "$REPLY" =~ ^[yY] ]]; then
cat packages.ccr >> packages.${arch}
else
echo "Something went wrong during repository creation. Review the"
echo "above output and try again."
fi