summarylogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PKGBUILD4
-rw-r--r--dist_detect.1.gzbin504 -> 847 bytes
-rwxr-xr-xdist_detect_main77
3 files changed, 79 insertions, 2 deletions
diff --git a/PKGBUILD b/PKGBUILD
index 23a21191fad3..b1faca4eb051 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,6 +1,6 @@
# Maintainer: Amirreza Firoozi <firoozi128.af@gmail.com>
pkgname=dist_detect
-pkgver=1.0
+pkgver=1.8
pkgrel=1
epoch=
pkgdesc="a simple script that helps you detect your distro name easily "
@@ -11,7 +11,7 @@ depends=('')
install=
md5sums=('SKIP')
changelog=
-source=("https://github.com/AmirrezaFiroozi/dist_detect/archive/v1.0.tar.gz")
+source=("https://github.com/AmirrezaFiroozi/dist_detect/archive/v${pkgver}.tar.gz")
noextract=()
package() {
diff --git a/dist_detect.1.gz b/dist_detect.1.gz
index 65b1f691be34..84d6e663e296 100644
--- a/dist_detect.1.gz
+++ b/dist_detect.1.gz
Binary files differ
diff --git a/dist_detect_main b/dist_detect_main
new file mode 100755
index 000000000000..b3549aee9ed1
--- /dev/null
+++ b/dist_detect_main
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+#Author : Amirreza Firoozi
+#License : GPL3
+#version : 1.8
+
+#This is a simple script that find distro name and echo (return) it.
+#Its useful if you want to know what distro is your own script running on.
+previous_way(){
+#This is the way we used in previous_way version(s)
+distros=( "Arch" "Ubuntu" "Debian" "Suse" )
+dId=0
+while [ "1" == "1" ];do
+ grep -i "${distros[dId]}" /etc/issue 1>/dev/null 2>&1
+ exstatus=$?
+ if [ "$exstatus" == "0" ];then #if grep found dist_name successfuly , we save dist_name in distro
+ distro=${distros[dId]}
+
+ break
+ fi
+
+ if [ "$dId" -gt "${#distros[@]}" ];then #if the number of loop is greater than number of distros we will break the loop
+
+ break
+ fi
+ ((dId++))
+done
+}
+#This is the current_way .
+#As you can see its more powerful and reliable and need less time :D
+current_way(){
+
+ distro=$(egrep "^NAME" /etc/os-release | sed s/"NAME="// | sed s/\"//g)
+
+}
+#In previous version we used if to make argument support
+#in this version we use the correct way of it (getopts)
+current_way
+
+if [ "$#" == "0" ];then
+ echo "$distro"
+ exit 0
+fi
+
+
+while getopts ":o:p" OPTIONS; do
+ case $OPTIONS in
+
+ o) #redirects output to a file
+ while [ "$#" -gt "1" ];do
+ FILE=$2
+ echo "$distro" > $FILE
+
+ shift #Move on to next input file
+ done
+
+ ;;
+
+ p) #use previous_way
+ previous_way
+
+ if [ "$#" == "1" ];then
+ echo "$distro"
+ exit 0
+ fi
+
+ ;;
+
+ *) #unrecognized option
+
+ echo -e " Invalid Option \n see man dist_detect if you need help "
+ exit 1
+
+ ;;
+ esac
+done
+shift $((OPTIND-1)) #This tells getopts to move on to the next argument