From 6077476adc0dd5aa422ab86375900b29021f1606 Mon Sep 17 00:00:00 2001
From: wiiznokes <78230769+wiiznokes@users.noreply.github.com>
Date: Aug 21 2024 13:48:30 +0000
Subject: refractor srpm & bootstrap


---

diff --git a/.gitignore b/.gitignore
index 9b9c868..d70dc44 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,2 @@
-__pycache__/
-*.py[cod]
-*$py.class
-/dev
\ No newline at end of file
+/dev/*
+!dev/.keep
\ No newline at end of file
diff --git a/dev/.keep b/dev/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/dev/.keep
diff --git a/justfile b/justfile
new file mode 100644
index 0000000..7bf9f8d
--- /dev/null
+++ b/justfile
@@ -0,0 +1,28 @@
+set working-directory := 'dev'
+set export
+
+PACKAGE := 'cosmic-comp'
+# REPO := 'https://github.com/pop-os/cosmic-comp.git'
+# VERSION := '0.1.0'
+# COMMIT := 'latest'
+
+all: init sources spec build
+
+init:
+    cp ../rpms/{{PACKAGE}}/* .
+    ../scripts/srpm.sh
+
+sources:
+    cp vendor-* ~/rpmbuild/SOURCES/
+    cp *.patch ~/rpmbuild/SOURCES/ || true
+
+spec:
+    cp ../rpms/{{PACKAGE}}/{{PACKAGE}}.spec .
+    VENDOR=0 ../scripts/srpm.sh
+    cp {{PACKAGE}}.spec ~/rpmbuild/SPECS/
+
+build:
+    rpmbuild --undefine=_disable_source_fetch -bb ~/rpmbuild/SPECS/{{PACKAGE}}.spec
+
+fast-build:
+    rpmbuild -bb --short-circuit ~/rpmbuild/SPECS/{{PACKAGE}}.spec
diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh
old mode 100644
new mode 100755
index 5a1707e..dc784ce
--- a/scripts/bootstrap.sh
+++ b/scripts/bootstrap.sh
@@ -1,25 +1,9 @@
-#!/bin/bash -x
+#!/bin/bash -xe
 
-VENDOR=1
-# Names (Source name can sometimes be the same as name)
-NAME=
-SOURCE_NAME=
-# Version and commit (latest if using master)
-VERSION=0.1.0
-COMMIT=LATEST
-# Repos
-REPO=https://github.com/pop-os/$SOURCE_NAME
-RPM_REPO=https://pagure.io/fedora-cosmic/cosmic-packaging.git
-# Paths to files
-RPM_FILES=cosmic-packaging/rpms/$NAME/*
-SCRIPT_FILE=srpm.sh
-SCRIPT_DIR=cosmic-packaging/scripts/$SCRIPT_FILE
+export PACKAGE=cosmic-comp
 
-# Clone the RPM repo
-git clone --recurse-submodules $RPM_REPO
-# Get extra RPM files
-cp $RPM_FILES .
-# Get script file
-cp $SCRIPT_DIR .
-# Run script file
-. $SCRIPT_FILE $NAME $SOURCE_NAME $VERSION $COMMIT $REPO $VENDOR
\ No newline at end of file
+git clone https://pagure.io/fedora-cosmic/cosmic-packaging.git
+cp cosmic-packaging/rpms/$PACKAGE/* .
+cp cosmic-packaging/scripts/srpm.sh .
+
+./srpm.sh
diff --git a/scripts/build_locally.sh b/scripts/build_locally.sh
deleted file mode 100755
index 502ad85..0000000
--- a/scripts/build_locally.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash -xe
-
-# Build a package locally.
-# Need to be called from the root of the repo (./scripts/build_local.sh)
-
-
-PACKAGE=cosmic-settings
-REPO=https://github.com/pop-os/cosmic-settings
-
-rm -rf dev
-mkdir dev
-cp rpms/$PACKAGE/* dev/
-cp scripts/srpm.sh dev/
-cd dev
-./srpm.sh $PACKAGE $PACKAGE 0.1.0 LATEST $REPO 1
-
-cp vendor-* ~/rpmbuild/SOURCES/
-cp *.patch ~/rpmbuild/SOURCES/ || true
-
-cp $PACKAGE.spec ~/rpmbuild/SPECS/
-
-rpmbuild -bb ~/rpmbuild/SPECS/$PACKAGE.spec
diff --git a/scripts/no-sources-srpm.sh b/scripts/no-sources-srpm.sh
deleted file mode 100644
index cd0460c..0000000
--- a/scripts/no-sources-srpm.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/bash -x
-
-# name of the crate/package
-name=$1
-# version of the crate/package
-version=$2
-# commit to target (latest == master)
-commit=$3
-# path to the spec file on the pc
-path_to_spec=$4
-# repo link
-repo=$5
-
-# Get specfile
-cp $path_to_spec $name.spec 2>/dev/null || :
-
-# Make replacements to specfile
-sed -i "/^Version: / s/.*/Version:           $version~^%{commitdate}git%{sub %{commit} 1 7}/" $name.spec
-sed -i "/^%global commit / s/.*/%global commit none/" $name.spec
-current_date=$(date +'%Y%m%d')
-sed -i "/^%global commitdate / s/.*/%global commitdate $current_date/" $name.spec
-sed -i "/^%global commitdatestring / s/.*/%global commitdatestring $current_date/" $name.spec
-
-
-ls -a
-pwd
-
-echo Done! $1 $2 $3 $4 $5
\ No newline at end of file
diff --git a/scripts/srpm.sh b/scripts/srpm.sh
index 6b4e0c0..63f6599 100755
--- a/scripts/srpm.sh
+++ b/scripts/srpm.sh
@@ -1,39 +1,43 @@
 #!/bin/bash -xe
 
 # clone repo, detect last commit, vendor deps, update specfile
-
-if [ "$#" -lt 6 ]; then
-    echo "Error: Less than six arguments provided."
-    exit 1
+#
+#
+# PACKAGE: package name
+# SOURCE_NAME: sometime the same of PACKAGE
+# VERSION: tag, semver
+# COMMIT: latest or sha
+# REPO: link
+# VENDOR: 0 or 1
+
+check_variable() {
+    local var_name=$1
+    if [ -z "${!var_name+x}" ]; then
+        echo "Error: '$var_name' is not defined."
+        exit 1
+    fi
+}
+
+check_variable PACKAGE
+SOURCE_NAME=${SOURCE_NAME:-"$PACKAGE"}
+VERSION=${VERSION:-"0.1.0"}
+COMMIT=${COMMIT:-"latest"}
+REPO=${REPO:-"https://github.com/pop-os/$SOURCE_NAME"}
+VENDOR=${VENDOR:-1}
+
+if [ ! -e "$PACKAGE" ]; then
+    git clone --recurse-submodules $REPO $PACKAGE
 fi
 
-# NAME of the crate/package
-NAME=$1
-SOURCE_NAME=$2
-# VERSION of the crate/package
-VERSION=$3
-# COMMIT to target (LATEST == master)
-COMMIT=$4
-# REPO link
-REPO=$5
-# VENDOR?
-VENDOR=$6
-
-LATEST="LATEST"
-
-# Clone REPO and cd into it
-mkdir $SOURCE_NAME-$COMMIT && cd $SOURCE_NAME-$COMMIT && git clone --recurse-submodules $REPO .
+cd $PACKAGE
 
 # Get latest COMMIT hash if COMMIT is set to latest
-if [[ "$COMMIT" == "$LATEST" ]]; then
+if [[ "$COMMIT" == "latest" ]]; then
     COMMIT=$(git rev-parse HEAD)
-    cd .. && mv $SOURCE_NAME-LATEST $SOURCE_NAME-$COMMIT && cd $SOURCE_NAME-$COMMIT
 fi
 
-# Set short commit
 SHORTCOMMIT=$(echo ${COMMIT:0:7})
 
-# Reset to specified COMMIT
 git reset --hard $COMMIT
 
 COMMITDATE=$(git log -1 --format=%cd --date=format:%Y%m%d)
@@ -43,16 +47,10 @@ if [ "$VENDOR" -eq 1 ]; then
     echo "VENDOR=1"
     # Vendor dependencies and zip vendor
     cargo vendor >../vendor-config-$SHORTCOMMIT.toml
-    tar -pczf vendor-$SHORTCOMMIT.tar.gz vendor && mv vendor-$SHORTCOMMIT.tar.gz ../vendor-$SHORTCOMMIT.tar.gz
-    # Back into parent directory
-    rm -rf vendor
-    cd ..
-else
-    cd ..
+    tar -pczf ../vendor-$SHORTCOMMIT.tar.gz vendor
 fi
 
-# rm repo
-rm -rf $SOURCE_NAME-$COMMIT
+cd ..
 
 # Make replacements to specfile
 sed -i "/^Version: / s/.*/Version:           $VERSION~^%{commitdate}git%{shortcommit}/" $NAME.spec
@@ -60,8 +58,3 @@ sed -i "/^%global commit / s/.*/%global commit $COMMIT/" $NAME.spec
 
 sed -i "/^%global commitdate / s/.*/%global commitdate $COMMITDATE/" $NAME.spec
 sed -i "/^%global commitdatestring / s/.*/%global commitdatestring $COMMITDATESTRING/" $NAME.spec
-
-# Should have these sources
-# SOURCE_NAME-SHORTCOMMIT.tar.gz
-# vendor-%{shortcommit}.tar.gz
-# vendor-config-%{shortcommit}.toml

