Created
June 27, 2018 14:22
-
-
Save santuari/fde966927f798b021de819b6da9eeb9d to your computer and use it in GitHub Desktop.
Script to index the Ubuntu repository within a cdrom. This script may be used to add packages to a cdrom.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Variable to customize | |
GPG_NAME=key_id | |
GPG_PATH_PW=path_to_password | |
#Main is the default repo component, I added extras. It means that my deb in pool/extras will be added | |
REPONAME=(main extras) | |
ORIGIN="my company" | |
LABEL="my mirror" | |
REPO=dists/$CODENAME/ | |
REPO_SOURCE=pool/ | |
CODENAME=xenial | |
GLOBAL_RELEASE=$REPO/Release | |
GLOBAL_INRELEASE=$REPO/InRelease | |
verify_file () { | |
if test ! -s "$1"; then | |
echo "$1 is empty" | |
exit 1 | |
fi | |
} | |
create_folder () { | |
if test ! -d "$1" ; then | |
echo "Creating folder $1" | |
mkdir -p "$1" | |
fi | |
} | |
cd ubuntu | |
create_folder "$REPO" | |
# Generate Global release file in REPO | |
cat > $GLOBAL_RELEASE <<ENDRELEASE | |
Origin: $ORIGIN | |
Label: $LABEL | |
Suite: $CODENAME | |
Version: $VERSION | |
Codename: $CODENAME | |
Date: $(date -u '+%a, %d %b %Y %T %Z') | |
Architectures: amd64 i386 | |
Components: $(printf '%s ' "${REPONAME[@]}") | |
Description: Ubuntu Xenial 16.04 | |
ENDRELEASE | |
MD5=() | |
SHA1=() | |
SHA256=() | |
# For each REPO_TYPE generate the packages | |
for REPO_TYPE in "${REPONAME[@]}"; do | |
BINARY="$REPO/$REPO_TYPE/binary-amd64/" | |
SOURCE="$REPO_SOURCE/$REPO_TYPE/" | |
if test ! -d "$SOURCE"; then | |
echo "$SOURCE do not exist, skipping indexing" | |
continue | |
fi | |
PACKAGE_FILE="$BINARY/Packages" | |
create_folder "$BINARY" | |
echo "Indexing packages in $SOURCE to $BINARY" | |
dpkg-scanpackages -a amd64 -m "$SOURCE" > "$PACKAGE_FILE" | |
verify_file "$PACKAGE_FILE" | |
gzip -9c "$PACKAGE_FILE" > "${PACKAGE_FILE}.gz" | |
#TODO: should be created? | |
#xz $PACKAGE_FILE | |
# Release info goes into Release & Release.gpg which includes an md5 & sha1 hash of Packages.* | |
# They must be generated for each REPO_TYPE | |
cat > "$BINARY/Release" <<ENDRELEASE | |
Component: $REPO_TYPE | |
Origin: $ORIGIN | |
Label: $LABEL | |
Architecture: amd64 | |
Description: Apt | |
ENDRELEASE | |
cd "$REPO"||exit 1 | |
#Collect all hashes | |
#MD5Sum | |
for hashme in $(find "$REPO_TYPE" -type f); do | |
md5=$(openssl dgst -md5 "${hashme}"|cut -d" " -f 2) | |
size=$(stat -c %s "${hashme}") | |
MD5+=(" ${md5} ${size} ${hashme}") | |
done | |
#SHA1 | |
for hashme in $(find "$REPO_TYPE" -type f); do | |
sha1=$(openssl dgst -sha1 "${hashme}"|cut -d" " -f 2) | |
size=$(stat -c %s "${hashme}") | |
SHA1+=(" ${sha1} ${size} ${hashme}") | |
done | |
#SHA256 | |
for hashme in $(find "$REPO_TYPE" -type f); do | |
sha1=$(openssl dgst -sha256 "${hashme}"|cut -d" " -f 2) | |
size=$(stat -c %s "${hashme}") | |
SHA256+=(" ${sha1} ${size} ${hashme}") | |
done | |
cd - | |
done | |
#Write all hashes in the Global Release file | |
{ | |
echo "MD5Sum:" | |
printf "%s\n" "${MD5[@]}" | |
echo "SHA1:" | |
printf "%s\n" "${SHA1[@]}" | |
echo "SHA256:" | |
printf "%s\n" "${SHA256[@]}" | |
} >> $GLOBAL_RELEASE | |
verify_file "$GLOBAL_RELEASE" | |
# Sign the global release | |
# TODO: remove the password from this command | |
gpg --batch --passphrase-file $GPG_PATH_PW --yes --digest-algo SHA256 -u $GPG_NAME --sign -bao $GLOBAL_RELEASE.gpg $GLOBAL_RELEASE | |
gpg --batch --passphrase-file $GPG_PATH_PW --yes --digest-algo SHA256 -u $GPG_NAME --clearsign -o $GLOBAL_INRELEASE $GLOBAL_RELEASE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment