aptosaurus/aptosaurus.sh

176 lines
4.7 KiB
Bash
Raw Normal View History

2019-08-05 23:02:44 +00:00
#!/usr/bin/env bash
# Make sure the current directory is the location of this script to simplify matters
cd "$(dirname "$(readlink -f "$0")")" || exit 2;
2019-08-05 23:33:58 +00:00
export GNUPGHOME="${PWD}/gnupg";
2019-08-05 23:02:44 +00:00
################
### Settings ###
################
# The name of this project
project_name="aptosaurus";
# The path to the lantern build engine git submodule
lantern_path="./lantern-build-engine";
###
# Custom Settings
###
# The directory that contains the source deb packages
dir_sources="sources";
# The directory the repository is in
dir_repo="repo";
# The id of the GPG key to use for signing
gpg_key_id="7A37B795C20E4651D9BBE1B2D48D801C6A66A5D8";
###############################################################################
# Check out the lantern git submodule if needed
if [ ! -f "${lantern_path}/lantern.sh" ]; then git submodule update --init "${lantern_path}"; fi
source "${lantern_path}/lantern.sh";
if [[ "$#" -lt 1 ]]; then
echo -e "${FBLE}${project_name}${RS}";
echo -e " by Starbeamrainbowlabs";
echo -e "${LC}Powered by the lantern build engine, v${version}${RS}";
echo -e "";
echo -e "Based on https://askubuntu.com/a/89698/139735";
echo -e "";
echo -e "${CSECTION}Usage${RS}";
echo -e " ./build ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ...";
echo -e "";
echo -e "${CSECTION}Available actions${RS}";
2019-08-09 22:45:32 +00:00
echo -e " ${CACTION}setup${RS} - Perform initial setup";
echo -e " ${CACTION}update${RS} - Scan for new packages and add them to the repository";
echo -e " ${CACTION}update-cron${RS} - Like ${CACTION}update${RS}, but silent unless something goes wrong";
echo -e " ${CACTION}metafiles${RS} - Rebuild the repository metafiles only (useful if you've manually fiddled with the repo packages)";
2019-08-05 23:02:44 +00:00
echo -e "";
exit 1;
fi
###############################################################################
task_setup() {
task_begin "Checking environment";
check_command gpg true;
check_command cp true;
check_command rm true;
check_command mkdir true;
check_command find true;
check_command xargs true;
check_command ln true;
check_command apt-ftparchive true;
check_command dpkg-sig true;
task_end $?;
task_begin "Checking keys";
if [ ! -f "./public.gpg" ]; then
echo "Error: Couldn't find the public key to use.";
echo "Make sure that ${HC}public.gpg${HC} exist on disk.";
exit 1;
fi
task_end $?;
task_begin "Creating directories";
2019-08-05 23:41:43 +00:00
mkdir "${dir_sources}" "${dir_repo}";
task_end $?;
2019-08-05 23:41:43 +00:00
if [ ! -d "${GNUPGHOME}" ]; then
2019-08-05 23:44:05 +00:00
mkdir "${GNUPGHOME}";
chown 0700 "${GNUPGHOME}";
2019-08-05 23:02:44 +00:00
if [ ! -f "./secret.gpg" ]; then
echo "Couldn't find the secret key to use.";
echo "Make sure ${HC}secret.gpg${RS} exists on disk.";
fi
task_begin "Importing keys";
gpg --import -v -v ./secret.gpg;
gpg --import -v -v ./public.gpg;
gpg --list-keys;
rm secret.gpg;
task_end $?;
fi
if [ ! -f "${repo_dir}/aptosaurus.asc" ]; then
task_begin "Hard linking public signing key";
cp -al "./public.gpg" "${dir_repo}/aptosaurus.asc";
task_end $?;
fi
}
# $1 - the .deb file to symlink
_symlink_deb() {
source="$1";
2019-08-05 23:49:46 +00:00
destination="$(basename "${source}")";
2019-08-05 23:02:44 +00:00
2019-08-05 23:49:46 +00:00
if [ -f "${destination}" ]; then return; fi
2019-08-05 23:02:44 +00:00
2019-08-05 23:49:46 +00:00
ln -s "${source}" "${destination}";
2019-08-05 23:02:44 +00:00
}
task_update() {
task_begin "Symlinking new packages";
2019-08-05 23:51:50 +00:00
package_count_before="$(find ${dir_repo} -name "*.deb" | wc -l)";
2019-08-05 23:02:44 +00:00
export -f _symlink_deb;
cd "${dir_repo}" || exit 2;
2019-08-05 23:47:23 +00:00
find "../${dir_sources}" -type f -name "*.deb" -print0 | xargs --null -n1 -I{} bash -c '_symlink_deb "{}"';
2019-08-05 23:02:44 +00:00
exit_code="$?";
cd - || exit 2;
2019-08-05 23:51:50 +00:00
package_count_after="$(find ${dir_repo} -name "*.deb" | wc -l)";
2019-08-05 23:02:44 +00:00
task_end "${exit_code}";
if [[ "${package_count_before}" -eq "${package_count_after}" ]]; then
echo "No new packages to process.";
exit 0;
else
new_package_count=$((package_count_after-package_count_before));
echo -e "Found ${new_package_count} new packages";
fi
cd "${dir_repo}" || exit 2;
task_begin "Signing packages";
execute dpkg-sig -k "${gpg_key_id}" -s builder "*.deb";
task_end $?;
tasks_run "metafiles";
}
task_metafiles() {
2019-08-05 23:02:44 +00:00
task_begin "Building packages file";
2019-08-06 00:21:29 +00:00
apt-ftparchive packages . >Packages;
2019-08-05 23:02:44 +00:00
execute bzip2 -kf Packages;
task_end $?;
2019-08-05 23:52:49 +00:00
task_begin "Generating release file";
2019-08-06 00:21:29 +00:00
apt-ftparchive release . >Release;
2019-08-05 23:52:49 +00:00
task_end $?;
2019-08-05 23:02:44 +00:00
2019-08-05 23:52:49 +00:00
task_begin "Signing release file";
2019-08-05 23:02:44 +00:00
execute gpg --yes -abs -u "${gpg_key_id}" -o Release.gpg Release
task_end $?;
}
2019-08-09 22:45:32 +00:00
task_update-cron() {
2019-08-09 22:46:57 +00:00
tmpfile="$(mktemp --suffix ".aptosaurus.log")";
2019-08-09 22:45:32 +00:00
set +e;
2019-08-09 22:48:00 +00:00
bash ./aptosaurus.sh update | ansi_strip >"${tmpfile}";
2019-08-09 22:50:17 +00:00
exit_code="${?}";
2019-08-09 22:45:32 +00:00
if [[ "${exit_code}" -ne 0 ]]; then
cat "${tmpfile}";
fi
rm "${tmpfile}";
2019-08-09 22:45:32 +00:00
}
2019-08-05 23:02:44 +00:00
###############################################################################
tasks_run $@;