big feat & update commit, read description...
feat: regenerate packages & release (update option), letter based folder structure support, choose gpg key, config file, multiple architecture done update: docs, comments in code, add, del, list, sign i dont know honestly... docs will be updated later
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					build/
 | 
				
			||||||
 | 
					commit
 | 
				
			||||||
							
								
								
									
										35
									
								
								build.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										35
									
								
								build.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PACKAGE="debrepo"
 | 
				
			||||||
 | 
					VERSION="1.0.0"
 | 
				
			||||||
 | 
					MAINTAINER="Filip Rojek <filip@filiprojek.cz>"
 | 
				
			||||||
 | 
					DEPENDS=""
 | 
				
			||||||
 | 
					ARCHITECTURE=""
 | 
				
			||||||
 | 
					HOMEPAGE="https://git.filiprojek.cz/fr/debrepo"
 | 
				
			||||||
 | 
					DESCRIPTION=""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					BASEF=$PACKAGE"_"$VERSION"_"$ACHITECTURE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# create folder structure
 | 
				
			||||||
 | 
					mkdir -p "./build/$BASEF/DEBIAN/" "./build/$BASEF/usr/bin/"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# create control file
 | 
				
			||||||
 | 
					echo "\
 | 
				
			||||||
 | 
					Package: $PACKAGE
 | 
				
			||||||
 | 
					Version: $VERSION
 | 
				
			||||||
 | 
					Maintainer: $MAINTAINER
 | 
				
			||||||
 | 
					Depends: $DEPENDS
 | 
				
			||||||
 | 
					Architecture: $ARCHITECTURE
 | 
				
			||||||
 | 
					Homepage: $HOMEPAGE
 | 
				
			||||||
 | 
					Description: $DESCRIPTION
 | 
				
			||||||
 | 
					" > "./build/$BASEF/DEBIAN/control"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# copy bin file
 | 
				
			||||||
 | 
					cp ./hello-program/hello-world "./build/$BASEF/usr/bin/"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# build deb file
 | 
				
			||||||
 | 
					dpkg --build "./build/$BASEF/"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# print info about deb file
 | 
				
			||||||
 | 
					dpkg-deb --info "./build/$BASEF.deb" && echo "Package build was successful"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										74
									
								
								debrepo
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								debrepo
									
									
									
									
									
								
							@@ -1,39 +1,95 @@
 | 
				
			|||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
VERSION="1.0.0"
 | 
					VERSION="1.0.0"
 | 
				
			||||||
DIR="$(cd "$(dirname "$0")" && pwd)"
 | 
					DIR="$(cd "$(dirname "$0")" && pwd)" # location of debrepo source path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# set vars
 | 
				
			||||||
 | 
					index=1
 | 
				
			||||||
 | 
					for arg in $@; do
 | 
				
			||||||
 | 
						# set REPODIR variable
 | 
				
			||||||
 | 
						if [ $arg = "--repodir" ]; then
 | 
				
			||||||
 | 
							ARGID="$((index+1))"
 | 
				
			||||||
 | 
							eval "REPODIR=\$$ARGID"
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if [ $arg = "--gpg" ]; then
 | 
				
			||||||
 | 
							ARGID="$((index+1))"
 | 
				
			||||||
 | 
							eval "GPG=\$$ARGID"
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						index=$((index+1))
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ -z $REPODIR ]; then
 | 
				
			||||||
 | 
						echo "error: --repodir is not set"
 | 
				
			||||||
 | 
						exit 1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$1" = "init" ] || [ "$1" = "-i" ] || [ "$1" = "--init" ]; then
 | 
					if [ "$1" = "init" ] || [ "$1" = "-i" ] || [ "$1" = "--init" ]; then
 | 
				
			||||||
	$DIR/scripts/repoinit.sh && echo "debrepo: repository folders have been successfully created"
 | 
						# create basic folder structure
 | 
				
			||||||
 | 
						$DIR/scripts/repoinit.sh $REPODIR && echo "debrepo: repository folders have been successfully created"
 | 
				
			||||||
	exit
 | 
						exit
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$1" = "add" ] || [ "$1" = "-a" ] || [ "$1" = "--add" ]; then
 | 
					if [ "$1" = "add" ] || [ "$1" = "-a" ] || [ "$1" = "--add" ]; then
 | 
				
			||||||
	# copy deb file to repo folder structure
 | 
						# copy deb file to repo folder structure
 | 
				
			||||||
	cp "./$2" "./apt-repo/pool/main/"
 | 
						if [ "$2" = "--letter-based-structure" ] || [ "$2" = "-l" ];then
 | 
				
			||||||
 | 
							first_letter=$(echo "$3" | sed 's/[.\/]//g' | cut -c 1 | tr '[:upper:]' '[:lower:]')
 | 
				
			||||||
 | 
							mkdir "$REPODIR/apt-repo/pool/main/$first_letter/"
 | 
				
			||||||
 | 
							cp "./$3" "$REPODIR/apt-repo/pool/main/$first_letter/$3"
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							cp "./$2" "$REPODIR/apt-repo/pool/main/"
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# generate package and release file
 | 
						# generate package and release file
 | 
				
			||||||
	$DIR/scripts/genPkgRel.sh $2 && echo "debrepo: package $2 was successfully added"
 | 
						$DIR/scripts/genPkgRel.sh $REPODIR $2 && echo "debrepo: package $2 was successfully added"
 | 
				
			||||||
 | 
						$DIR/scripts/gpgSign.sh $REPODIR $GPG && echo "debrepo: repo was succesfully signed"
 | 
				
			||||||
	exit
 | 
						exit
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$1" = "del" ] || [ "$1" = "-d" ] || [ "$1" = "--del" ]; then
 | 
					if [ "$1" = "del" ] || [ "$1" = "-d" ] || [ "$1" = "--del" ]; then
 | 
				
			||||||
	rm -i "./apt-repo/pool/main/$2" && echo "debrepo: package $2 was successfully removed"
 | 
							first_letter=$(echo "$2" | sed 's/[.\/]//g' | cut -c 1 | tr '[:upper:]' '[:lower:]')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if [ -f "$REPODIR/apt-repo/pool/main/$first_letter/$2" ]; then
 | 
				
			||||||
 | 
							# remove package
 | 
				
			||||||
 | 
							rm -i "$REPODIR/apt-repo/pool/main/$first_letter/$2" && echo "debrepo: package $2 was successfully removed"
 | 
				
			||||||
 | 
						elif [ -f "$REPODIR/apt-repo/pool/main/$2" ]; then
 | 
				
			||||||
 | 
							# remove package
 | 
				
			||||||
 | 
							rm -i "$REPODIR/apt-repo/pool/main/$2" && echo "debrepo: package $2 was successfully removed"
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							echo "error: package $2 was not found";
 | 
				
			||||||
 | 
							exit 1;
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# generate package and release file
 | 
						# generate package and release file
 | 
				
			||||||
	$DIR/scripts/genPkgRel.sh $2 && echo "debrepo: repository  was successfully updated"
 | 
						$DIR/scripts/genPkgRel.sh $REPODIR && echo "debrepo: repository  was successfully updated"
 | 
				
			||||||
 | 
						$DIR/scripts/gpgSign.sh $REPODIR && echo "debrepo: repo was succesfully signed"
 | 
				
			||||||
	exit
 | 
						exit
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$1" = "list" ] || [ "$1" = "-l" ] || [ "$1" = "--list" ]; then
 | 
					if [ "$1" = "list" ] || [ "$1" = "-l" ] || [ "$1" = "--list" ]; then
 | 
				
			||||||
	echo "debrepo: list of packages"
 | 
						echo "debrepo: list of packages"
 | 
				
			||||||
	ls -l "./apt-repo/pool/main/"
 | 
					
 | 
				
			||||||
 | 
						# if command tree is installed
 | 
				
			||||||
 | 
						if [ -e "$(which tree)" ]; then
 | 
				
			||||||
 | 
							tree "$REPODIR/apt-repo/pool/main/"
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							ls -R "$REPODIR/apt-repo/pool/main/"
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
	exit
 | 
						exit
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$1" = "sign" ] || [ "$1" = "-s" ] || [ "$1" = "--sign" ]; then
 | 
					if [ "$1" = "sign" ] || [ "$1" = "-s" ] || [ "$1" = "--sign" ]; then
 | 
				
			||||||
	$DIR/scripts/gpgSign.sh $2
 | 
						$DIR/scripts/gpgSign.sh $2 # $2 is optional value if GPG is set in config file
 | 
				
			||||||
	exit
 | 
						exit
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$1" = "serve" ] || [ "$1" = "-S" ] ||[ "$1" = "--serve" ]; then 
 | 
					if [ "$1" = "update" ] || [ "$1" = "-u" ] || [ "$1" = "--update" ]; then
 | 
				
			||||||
 | 
						$DIR/scripts/genPkgRel.sh && echo "debrepo: repo was successfully updated" $DIR/scripts/gpgSign.sh $3 && echo "debrepo: repo was succesfully signed" # $3 is optional value if GPG is set in config file
 | 
				
			||||||
 | 
						exit
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ "$1" = "serve" ] || [ "$1" = "-S" ] || [ "$1" = "--serve" ]; then 
 | 
				
			||||||
 | 
						echo "THIS SHOULD BE ONLY USED FOR TESTING!"
 | 
				
			||||||
	python3 -m http.server
 | 
						python3 -m http.server
 | 
				
			||||||
	exit
 | 
						exit
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,17 +1,18 @@
 | 
				
			|||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
DIR="$(cd "$(dirname "$0")" && pwd)"
 | 
					DIR="$(cd "$(dirname "$0")" && pwd)"
 | 
				
			||||||
LS="$(which ls)"
 | 
					LS="$(which ls)" # this prevents bugs when aliasing ls to tools like exa
 | 
				
			||||||
ARCHS="$($LS -l apt-repo/dists/stable/main/ | awk '{print $9}' | awk NF | awk -F - '{print $2}')"
 | 
					REPODIR="$1"
 | 
				
			||||||
 | 
					ARCHS="$($LS -l $REPODIR/apt-repo/dists/stable/main/ | awk '{print $9}' | awk NF | awk -F - '{print $2}')"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# generate Packages file
 | 
					# generate Packages file
 | 
				
			||||||
for ARCH in $ARCHS; do
 | 
					for ARCH in $ARCHS; do
 | 
				
			||||||
	echo $ARCH
 | 
						echo $ARCH
 | 
				
			||||||
	dpkg-scanpackages --multiversion --arch $ARCH "./apt-repo/pool/" > "./apt-repo/dists/stable/main/binary-$ARCH/Packages"
 | 
						dpkg-scanpackages --multiversion --arch $ARCH "$REPODIR/apt-repo/pool/" > "$REPODIR/apt-repo/dists/stable/main/binary-$ARCH/Packages"
 | 
				
			||||||
	# compress Packages file
 | 
						# compress Packages file
 | 
				
			||||||
	cat "./apt-repo/dists/stable/main/binary-$ARCH/Packages" | gzip -9 > "./apt-repo/dists/stable/main/binary-$ARCH/Packages.gz"
 | 
						cat "$REPODIR/apt-repo/dists/stable/main/binary-$ARCH/Packages" | gzip -9 > "$REPODIR/apt-repo/dists/stable/main/binary-$ARCH/Packages.gz"
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# generate Release file
 | 
					# generate Release file
 | 
				
			||||||
cd "./apt-repo/dists/stable/"
 | 
					cd "$REPODIR/apt-repo/dists/stable/"
 | 
				
			||||||
$DIR/generate-release.sh > "Release"
 | 
					$DIR/generate-release.sh > "Release"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
set -e
 | 
					set -e
 | 
				
			||||||
 | 
					. ../../config # this file is in /apt-repo/config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_hash() {
 | 
					do_hash() {
 | 
				
			||||||
    HASH_NAME=$1
 | 
					    HASH_NAME=$1
 | 
				
			||||||
@@ -11,20 +12,28 @@ do_hash() {
 | 
				
			|||||||
            continue
 | 
					            continue
 | 
				
			||||||
        fi
 | 
					        fi
 | 
				
			||||||
        echo " $(${HASH_CMD} ${f}  | cut -d" " -f1) $(wc -c $f)"
 | 
					        echo " $(${HASH_CMD} ${f}  | cut -d" " -f1) $(wc -c $f)"
 | 
				
			||||||
 | 
					pwd
 | 
				
			||||||
    done
 | 
					    done
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ ! -f "../../config" ]; then
 | 
				
			||||||
 | 
						echo "error - config file does not exists"
 | 
				
			||||||
 | 
						exit 1;
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cat << EOF
 | 
					cat << EOF
 | 
				
			||||||
Origin: Example Repository
 | 
					Origin: $ORIGIN
 | 
				
			||||||
Label: Example
 | 
					Label: $LABEL
 | 
				
			||||||
Suite: stable
 | 
					Suite: $SUITE
 | 
				
			||||||
Codename: stable
 | 
					Codename: $CODENAME
 | 
				
			||||||
Version: 1.0
 | 
					Version: $VERSION
 | 
				
			||||||
Architectures: amd64 arm64 arm7
 | 
					Architectures: $ARCHITECTURES
 | 
				
			||||||
Components: main
 | 
					Components: $COMPONENTS
 | 
				
			||||||
Description: An example software repository
 | 
					Description: $DESCRIPTION
 | 
				
			||||||
Date: $(date -Ru)
 | 
					Date: $(date -Ru)
 | 
				
			||||||
EOF
 | 
					EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_hash "MD5Sum" "md5sum"
 | 
					do_hash "MD5Sum" "md5sum"
 | 
				
			||||||
do_hash "SHA1" "sha1sum"
 | 
					do_hash "SHA1" "sha1sum"
 | 
				
			||||||
do_hash "SHA256" "sha256sum"
 | 
					do_hash "SHA256" "sha256sum"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,32 @@
 | 
				
			|||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
KEY="$1"
 | 
					REPODIR="$1"
 | 
				
			||||||
 | 
					. $REPODIR/apt-repo/config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#KEY="$2"
 | 
				
			||||||
 | 
					#echo $KEY
 | 
				
			||||||
 | 
					#if [ $KEY = "--repodir" ]; then
 | 
				
			||||||
 | 
					#	KEY=""
 | 
				
			||||||
 | 
					#fi
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#if [ $KEY ]; then
 | 
				
			||||||
 | 
					#	continue
 | 
				
			||||||
 | 
					#elif [ $DEFAULT_GPG ]; then
 | 
				
			||||||
 | 
					#	KEY="$DEFAULT_GPG"
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#	echo "error: no gpg key provided"
 | 
				
			||||||
 | 
					#	exit 1
 | 
				
			||||||
 | 
					#fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ ! $DEFAULT_GPG ]; then
 | 
				
			||||||
 | 
						echo "error: no gpg key provided in config file"
 | 
				
			||||||
 | 
						exit 1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					KEY=$DEFAULT_GPG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
echo "debrepo: signing using $KEY"
 | 
					echo "debrepo: signing using $KEY"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cat ./apt-repo/dists/stable/Release | gpg --default-key $KEY -abs > ./apt-repo/dists/stable/Release.gpg
 | 
					cat $REPODIR/apt-repo/dists/stable/Release | gpg --default-key $KEY -abs > $REPODIR/apt-repo/dists/stable/Release.gpg
 | 
				
			||||||
cat ./apt-repo/dists/stable/Release | gpg --default-key $KEY -abs --clearsign > ./apt-repo/dists/stable/InRelease
 | 
					cat $REPODIR/apt-repo/dists/stable/Release | gpg --default-key $KEY -abs --clearsign > $REPODIR/apt-repo/dists/stable/InRelease
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,11 @@
 | 
				
			|||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# make folders
 | 
					if [ -z $1 ]; then
 | 
				
			||||||
mkdir -p ./apt-repo/dists/stable/main/binary-amd64/
 | 
						echo "error: --repodir is not set"
 | 
				
			||||||
mkdir -p ./apt-repo/pool/main/
 | 
						exit 1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# make folders
 | 
				
			||||||
 | 
					mkdir -p $1/apt-repo/dists/stable/main/binary-amd64/
 | 
				
			||||||
 | 
					mkdir -p $1/apt-repo/pool/main/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user