The following changes since commit 28bab50823c3d634724b918c08a09a92c0b649cc:
add maui-shell (experimental) (2022-01-13 10:43:18 +0100)
are available in the Git repository at:
https://gitlab.com/yarl-manjaro/manjaro-arm-tools.git less-code-duplication
for you to fetch changes up to e13f71bc01aad96d25c051b62dad4b3508584b85:
Less code duplication (2022-01-17 11:09:00 +0100)
----------------------------------------------------------------
yarl (1):
Less code duplication
bin/buildarmimg | 17 +++--------------
bin/buildarmpkg | 18 ++++--------------
bin/builddockerimg | 12 ++----------
bin/buildemmcinstaller | 12 ++----------
bin/buildrootfs | 12 ++----------
bin/getarmprofiles | 5 +----
lib/functions.sh | 25 +++++++++++++++++++++++++
7 files changed, 39 insertions(+), 62 deletions(-)
diff --git a/bin/buildarmimg b/bin/buildarmimg
index 29122d6..371430d 100755
--- a/bin/buildarmimg
+++ b/bin/buildarmimg
@@ -14,18 +14,10 @@ CHROOTDIR=$ROOTFS_IMG/rootfs_$ARCH
PKG_CACHE=$CHROOTDIR/var/cache/pacman/pkg
# check if root
-if [ "$EUID" -ne 0 ]
- then echo "This script requires root permissions to run. Please run as root or with sudo!"
- exit
-fi
+checkroot
# check if script is already running
-for pid in $(pidof -x buildarmimg); do
- if [ $pid != $$ ]; then
- echo "[$(date)] : buildarmimg : Process is already running with PID $pid"
- exit 1
- fi
-done
+checkrunning
#Arguments
opt=":e:d:v:i:b:nfxhk:mos:p:c"
@@ -103,10 +95,7 @@ if [ ! -d "$PROFILES/arm-profiles" ]; then
fi
#Make sure only a known branch is used
-if [[ "$BRANCH" != "stable" && "$BRANCH" != "testing" && "$BRANCH" != "unstable" ]]; then
- msg "Unknown branch. Please use either, stable, testing or unstable!"
- exit 1
-fi
+checkbranch
# start the timer
timer_start=$(get_timer)
diff --git a/bin/buildarmpkg b/bin/buildarmpkg
index dacbcba..f2b9551 100755
--- a/bin/buildarmpkg
+++ b/bin/buildarmpkg
@@ -11,18 +11,10 @@ CHROOTDIR=$BUILDDIR/$ARCH
PKG_CACHE=$CHROOTDIR/var/cache/pacman/pkg
# check if root
-if [ "$EUID" -ne 0 ]
- then echo "This script requires root permissions to run. Please run as root or with sudo!"
- exit
-fi
+checkroot
# check if script is already running
-for pid in $(pidof -x buildarmpkg); do
- if [ $pid != $$ ]; then
- echo "[$(date)] : buildarmpkg : Process is already running with PID $pid"
- exit 1
- fi
-done
+checkrunning
#Arguments
opt=":p:a:i:r:nb:kh"
@@ -80,10 +72,8 @@ if [ $ARCH == "any" ]; then
fi
#Make sure only a known branch is used
-if [[ "$BRANCH" != "stable" && "$BRANCH" != "testing" && "$BRANCH" != "unstable" ]]; then
- msg "Unknown branch. Please use either, stable, testing or unstable!"
- exit 1
-fi
+checkbranch
+
# start the timer
timer_start=$(get_timer)
diff --git a/bin/builddockerimg b/bin/builddockerimg
index c9b0f16..19bcd5a 100644
--- a/bin/builddockerimg
+++ b/bin/builddockerimg
@@ -10,18 +10,10 @@ source $LIBDIR/functions.sh
enable_colors
# check if root
-if [ "$EUID" -ne 0 ]
- then echo "This script requires root permissions to run. Please run as root or with sudo!"
- exit
-fi
+checkroot
# check if script is already running
-for pid in $(pidof -x builddockerimg); do
- if [ $pid != $$ ]; then
- echo "[$(date)] : builddockerimg : Process is already running with PID $pid"
- exit 1
- fi
-done
+checkrunning
# Functions
diff --git a/bin/buildemmcinstaller b/bin/buildemmcinstaller
index b28aaea..ef1cb2f 100755
--- a/bin/buildemmcinstaller
+++ b/bin/buildemmcinstaller
@@ -11,18 +11,10 @@ CHROOTDIR=$ROOTFS_IMG/rootfs_$ARCH
PKG_CACHE=$CHROOTDIR/var/cache/pacman/pkg
# check if root
-if [ "$EUID" -ne 0 ]
- then echo "This script requires root permissions to run. Please run as root or with sudo!"
- exit
-fi
+checkroot
# check if script is already running
-for pid in $(pidof -x buildemmcinstaller); do
- if [ $pid != $$ ]; then
- echo "[$(date)] : buildemmcinstaller : Process is already running with PID $pid"
- exit 1
- fi
-done
+checkrunning
#Arguments
opt=":e:d:v:i:f:nxh"
diff --git a/bin/buildrootfs b/bin/buildrootfs
index 41531e9..21967d1 100644
--- a/bin/buildrootfs
+++ b/bin/buildrootfs
@@ -9,18 +9,10 @@ source $LIBDIR/functions.sh
enable_colors
# check if root
-if [ "$EUID" -ne 0 ]
- then echo "This script requires root permissions to run. Please run as root or with sudo!"
- exit
-fi
+checkroot
# check if script is already running
-for pid in $(pidof -x buildrootfs); do
- if [ $pid != $$ ]; then
- echo "[$(date)] : buildrootfs : Process is already running with PID $pid"
- exit 1
- fi
-done
+checkrunning
# Functions
diff --git a/bin/getarmprofiles b/bin/getarmprofiles
index e46d5ad..3acd97a 100755
--- a/bin/getarmprofiles
+++ b/bin/getarmprofiles
@@ -4,10 +4,7 @@ LIBDIR=/usr/share/manjaro-arm-tools/lib
source $LIBDIR/functions.sh
# check if root
-if [ "$EUID" -ne 0 ]
- then echo "This script requires root permissions to run. Please run as root or with sudo!"
- exit
-fi
+checkroot
#Arguments
opt="fhp"
diff --git a/lib/functions.sh b/lib/functions.sh
index 2d2beb8..1580e59 100755
--- a/lib/functions.sh
+++ b/lib/functions.sh
@@ -28,6 +28,8 @@ COLORS=true
FILESYSTEM='ext4'
srv_list=/tmp/services_list
+PROGNAME=${0##*/}
+
#import conf file
source /etc/manjaro-arm-tools/manjaro-arm-tools.conf
@@ -180,6 +182,29 @@ create_torrent() {
mktorrent -v -a udp://tracker.opentrackr.org:1337 -w https://osdn.net/dl/manjaro-arm/$IMAGE -o $IMAGE.torrent $IMAGE
}
+checkroot () {
+ if [ "$EUID" -ne 0 ]
+ then echo "This script requires root permissions to run. Please run as root or with sudo!"
+ exit
+ fi
+}
+
+checkbranch () {
+ if [[ "$BRANCH" != "stable" && "$BRANCH" != "testing" && "$BRANCH" != "unstable" ]]; then
+ msg "Unknown branch. Please use either, stable, testing or unstable!"
+ exit 1
+ fi
+}
+
+checkrunning() {
+ for pid in $(pidof -x $PROGNAME); do
+ if [ $pid != $$ ]; then
+ echo "[$(date)] : $PROGNAME : Process is already running with PID $pid"
+ exit 1
+ fi
+ done
+}
+
checksum_img() {
# Create checksums for the image
info "Creating checksums for [$IMAGE]..."