summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xxib_env10
-rwxr-xr-xxibuild/build_all.sh105
-rwxr-xr-xxibuild/build_package.sh83
3 files changed, 124 insertions, 74 deletions
diff --git a/xib_env b/xib_env
index 50b6140..60d09ef 100755
--- a/xib_env
+++ b/xib_env
@@ -1,5 +1,11 @@
#!/bin/sh
+export CHECKMARK="✔"
+export CROSSMARK="✘"
+export TABCHAR="╰┈➤ "
+export INFOCHAR=" ~ "
+
+
export MAKEFLAGS="-j$(grep "processor" /proc/cpuinfo | wc -l)"
export XIB_DIR="/var/lib/xib"
@@ -12,6 +18,7 @@ export PUB_KEY="/home/david/.ssh/xi.pub"
export DEVELOPMENT_BUILDFILES="/home/david/docs/proj/xilinux/buildfiles"
export BUILDFILES_GIT_REPO="https://xi.davidovski.xyz/git/buildfiles.git"
+export INSTALLED_PACKAGES="$XIB_CHROOT/installed"
mkdir -p $XIB_DIR $XIB_BUILDFILES $XIB_CHROOT $XIB_EXPORT
@@ -27,5 +34,6 @@ else
fi
fi
+[ -f $INSTALLED_PACKAGES ] || touch $INSTALLED_PACKAGES
-cp /etc/resolv.conf $XIB_CHROOT/etc/resolv.conf
+[ -f $XIB_CHROOT/etc/resolv.conf ] || cp /etc/resolv.conf $XIB_CHROOT/etc/resolv.conf
diff --git a/xibuild/build_all.sh b/xibuild/build_all.sh
index dae63c6..2a1c0be 100755
--- a/xibuild/build_all.sh
+++ b/xibuild/build_all.sh
@@ -6,82 +6,87 @@ PASS="\033[0;32m"
NEUTRAL="\033[0;33m"
RESET="\033[0m"
+# scan and run all postinstall scripts
+#
+run_postinstall () {
+ postinstall="$XIB_CHROOT/var/lib/xipkg/postinstall"
+ if [ -d $postinstall ]; then
+ for file in "$postinstall/*.sh"; do
+ f=$(basename $file)
+
+ # run the postinstall file
+ #
+ chmod 755 $file
+ xichroot "$XIB_CHROOT" "/var/lib/xipkg/postinstall/$f"
+ rm $file
+
+ printf "$PASS run postinstall for $f!\n"
+ done
+ rmdir $postinstall
+ fi
+
+}
+
+# install a single package if it is present
+#
+# $1: the exported .xipkg file
+#
install_package () {
- local exported_pkg=$(find $XIB_EXPORT -wholename "*/$1.xipkg" | head -1 | xargs realpath)
- if [ -f $exported_pkg ]; then
- local checksum=$(md5sum $exported_pkg)
-
- local installed_list="$XIB_CHROOT/installed"
- [ -f $installed_list ] || touch $installed_list
-
- if grep -q "^$checksum$" $installed_list; then
- echo $checksum >> $installed_list
-
- tar -h --no-overwrite-dir -xf $exported_pkg -C $XIB_CHROOT
-
- postinstall="$XIB_CHROOT/var/lib/xipkg/postinstall"
- if [ -d $postinstall ]; then
- for file in "$postinstall/*.sh"; do
- f=$(basename $file)
- chmod 755 $file
- xichroot "$XIB_CHROOT" "/var/lib/xipkg/postinstall/$f"
- rm $file
- printf "$PASS run postinstall for $f!\n"
- done
- rmdir $postinstall
- fi
- printf "$PASS installed to chroot!\n"
- else
- printf "$RESET already installed!\n"
- fi
+ printf "${INFO}${TABCHAR}install "
+ local checksum=$(md5sum $1 | cut -d' ' -f1)
+
+ if grep -q "^${checksum}$" $INSTALLED_PACKAGES; then
+ printf "${RESET}${CHECKMARK}\n"
+ else
+ tar -h --no-overwrite-dir -xf $1 -C $XIB_CHROOT
+ echo $checksum >> $INSTALLED_PACKAGES
+
+ printf "${PASS}${CHECKMARK}\n"
+ return 0
fi
}
+# build a package by its name
+#
build_package () {
- name=$(echo $line | cut -d"+" -f1)
- buildfile=$(find $XIB_BUILDFILES -wholename "*/$name.xibuild" | head -1)
+
+ local name=$(echo $1 | cut -d"+" -f1)
+ local install=$(echo $line | grep -q '+' && echo "true" || echo "false")
+ local buildfile=$(find $XIB_BUILDFILES -wholename "*/$name.xibuild" | head -1)
if [ -f "$buildfile" ]; then
- printf $INFO
- printf "Building$NEUTRAL %s$INFO:\n$RESET" $name
+ printf "${INFO}%s\n${RESET}" $name
+
./build_package.sh $buildfile || return 1
- # Install the package if it is needed for other builds
- if echo $line | grep -q '+'; then
- printf "$INFO\tInstalling..."
- install_package $name
+ # install the package it exists
+ local exported_pkg=$(find $XIB_EXPORT -wholename "*/$name.xipkg" | head -1 | xargs realpath)
+ if $install && [ -f $exported_pkg ] ; then
+ install_package $exported_pkg
fi
- printf $RESET
- printf "Finished building %s!\n" $name
- else
- printf "$ERROR$name does not exist\n"
+ return 0
fi
- # configure shadow here
- if [ "$name" = "shadow" ]; then
- xichroot "$XIB_CHROOT" "/usr/sbin/pwconv"
- xichroot "$XIB_CHROOT" "/usr/sbin/grpconv"
- xichroot "$XIB_CHROOT" "mkdir -p /etc/default"
- xichroot "$XIB_CHROOT" "/usr/sbin/useradd -D --gid 999"
- fi
+ printf "${ERROR}${CROSSMARK} ${name}\n"
}
+# build all of the packages
+#
build_all () {
for line in $(perl build_order.pm); do
build_package $line || return 1
done
-
}
+
if build_all; then
printf "\n${PASS}Built all packages!"
exit 0
else
- printf "$ERROR Something went wrong!$NEUTRAL Press enter to view recent log"
+ printf "${ERROR} Something went wrong!${NEUTRAL} Press enter to view recent log"
read;
- f=$(ls -1 --sort time $XIB_EXPORT/repo/*/*.log | head -1 | xargs realpath)
- less $f
+ less $(ls -1 --sort time $XIB_EXPORT/repo/*/*.log | head -1 | xargs realpath)
exit 1
fi
diff --git a/xibuild/build_package.sh b/xibuild/build_package.sh
index 2a7445e..9b8628e 100755
--- a/xibuild/build_package.sh
+++ b/xibuild/build_package.sh
@@ -7,8 +7,9 @@ BUILDFILE=$1
REPO=$(echo $BUILDFILE | rev | cut -d/ -f2 | rev)
NAME=$(basename $BUILDFILE .xibuild)
-source $BUILDFILE
+# extract an archive using its appropriate tool
+#
extract () {
FILE=$1
case "${FILE##*.}" in
@@ -27,6 +28,8 @@ extract () {
esac
}
+# check if the package we want to build already exists, comparing hashes of the build file
+#
package_exists () {
local exported="$XIB_EXPORT/repo/$REPO/$NAME"
local exported_pkg="$exported.xipkg"
@@ -45,8 +48,9 @@ package_exists () {
return 1
}
+# downloads the source and any additional files
+#
fetch_source () {
- # download additional files
local src_dir="$XIB_CHROOT/build/source"
mkdir -p $src_dir
@@ -55,11 +59,11 @@ fetch_source () {
if [ ! -z ${SOURCE} ]; then
if git ls-remote -q $SOURCE $BRANCH &> /dev/null; then
- # The source is a git repo
+ # the source is a git repo
git clone $SOURCE . &> /dev/null
git checkout $BRANCH &> /dev/null
else
- # The source is a file
+ # otherwise the source is a file
local downloaded_file=$(basename $SOURCE)
curl -SsL $SOURCE > $downloaded_file
@@ -83,7 +87,8 @@ fetch_source () {
fi
}
-
+# removes any unecessary files from the chroot, from previous builds
+#
clean_chroot () {
local export_dir="$XIB_CHROOT/export"
local build_dir="$XIB_CHROOT/build"
@@ -97,8 +102,18 @@ clean_chroot () {
mkdir -p "$XIB_EXPORT/repo/$REPO/"
}
+prepare_build_env () {
+ clean_chroot
+
+ cp "$BUILDFILE" "$XIB_CHROOT/build/"
+ printf $NAME > "$XIB_CHROOT/build/name"
+}
+
+# generate the script that will be used to build the xibuild
+#
make_buildscript () {
+ # TODO this should be an external buildprofile file
echo MAKEFLAGS="$MAKEFLAGS" >> "$XIB_CHROOT/build/profile"
echo LDFLAGS="$LDFLAGS" >> "$XIB_CHROOT/build/profile"
@@ -155,44 +170,66 @@ EOF
chmod 700 "$XIB_CHROOT/build/build.sh"
}
-package () {
+# package the dest files into a xipkg
+#
+package_dest () {
local export_repo="$XIB_EXPORT/repo/$REPO"
local export_pkg="$XIB_EXPORT/repo/$REPO/$NAME.xipkg"
local pkg_dest="$XIB_CHROOT/export"
cd "$pkg_dest"
+
+ # ensure that the package actually exists
if [ "$(ls -1 | wc -l)" = "0" ]; then
printf " package is empty;"
[ -z "${SOURCE}" ] || exit 1;
fi
+
tar -C $pkg_dest -czf $export_pkg ./
+
+ # export the buildfile
+ cp "$BUILDFILE" "$XIB_EXPORT/repo/$REPO/"
}
+# build the package
+#
build () {
- printf "$BLUE\tCleaning chroot..."
- clean_chroot && printf "$GREEN prepared\n" || return 1
-
- printf "$BLUE\tfetching source..."
- fetch_source && printf "$GREEN fetched $(du -sh "$XIB_CHROOT/build/source" | awk '{ print $1 }')\n" || return 1
+ local log_file="$XIB_EXPORT/repo/$REPO/$NAME.log"
- printf "$BLUE\tgenerating buildscript..."
- make_buildscript && printf "$GREEN generated\n" || return 1
+ printf "${BLUE}${TABCHAR}prepare "
+ prepare_build_env || return 1
+ printf "${GREEN}${CHECKMARK}\n"
- cp "$BUILDFILE" "$XIB_CHROOT/build/"
- printf $NAME > "$XIB_CHROOT/build/name"
+ printf "${BLUE}${TABCHAR}fetch "
+ fetch_source || return 1
+ printf "${GREEN}${CHECKMARK}${RESET}${INFOCHAR}$(du -sh "$XIB_CHROOT/build/source" | awk '{ print $1 }')\n"
- local log_file="$XIB_EXPORT/repo/$REPO/$NAME.log"
+ printf "${BLUE}${TABCHAR}generate "
+ make_buildscript || return 1
+ printf "${GREEN}${CHECKMARK}\n"
- printf "$BLUE\tBuilding package..."
- xichroot $XIB_CHROOT /build/build.sh &> $log_file && printf "$GREEN built!\n" || return 1
+ printf "${BLUE}${TABCHAR}build "
+ xichroot $XIB_CHROOT /build/build.sh &> $log_file || return 1
+ printf "${GREEN}${CHECKMARK}\n"
- printf "$BLUE\tPackaging package..."
- package && printf "$GREEN packaged to $(du -sh "$XIB_EXPORT/repo/$REPO/$NAME.xipkg" | awk '{ print $1 }')!\n" || return 1
+ printf "${BLUE}${TABCHAR}package "
+ package_dest || return 1
+ printf "${GREEN}${CHECKMARK}${RESET}${INFOCHAR}$(du -sh "$XIB_EXPORT/repo/$REPO/$NAME.xipkg" | awk '{ print $1 }')!\n"
- cp "$BUILDFILE" "$XIB_EXPORT/repo/$REPO/"
+ # export the buildfile
}
-[ -z "${XIB_CHROOT}" ] && echo "CRITICAL! No chroot env variable set!" && exit 1;
+#
+# IMPORTANT
+#
+# this script will attempt to build the package in a suitable chroot environment
+# if one is not specified then unwanted consequences can occur
+# using XIB_CHROOT=/ could be a possbility but be aware of the risks
+#
+[ -z "${XIB_CHROOT}" ] && echo "${RED}CRITICAL! ${RESET}No chroot env variable set!" && exit 1;
+
+# import all of the functions and constants in the build file, so we know what to do
+source $BUILDFILE
-package_exists && printf "\tPackage exists!\n" || build
+package_exists || build