about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWeirdTreeThing <bradyn127@protonmail.com>2023-11-02 22:42:43 -0400
committerWeirdTreeThing <bradyn127@protonmail.com>2023-11-02 22:42:43 -0400
commit1059f5f1fa14d75903984301fea8c99914e185d2 (patch)
tree90d6cb40d7850c1b66a3bda196bbb4384d970252
parent551a2d3fa32d99fbcfc747f0d6f2cf78bf484b8b (diff)
Fix formatting, check if the system has sudo or doas
-rwxr-xr-xinstall.sh66
1 files changed, 36 insertions, 30 deletions
diff --git a/install.sh b/install.sh
index 05bb14f..b8a76d9 100755
--- a/install.sh
+++ b/install.sh
@@ -17,43 +17,49 @@ elif [ -f /usr/bin/apk ]; then
 	distro="alpine"
 fi
 
+if [ -f /usr/bin/sudo ]; then
+	privesc="sudo"
+elif [ -f /usr/bin/doas ]; then
+	privesc="doas"
+fi
+
 
 if ! [ -f /usr/bin/keyd ]; then
     # if keyd isnt installed
 	echo "Installing keyd dependencies"
 	case $distro in
 		deb)
-			sudo apt install -y build-essential git
-		;;
+			$privesc apt install -y build-essential git
+			;;
 		arch)
-		sudo pacman -S --noconfirm base-devel git
-		;;
+			$privesc pacman -S --noconfirm base-devel git
+			;;
 		fedora)
-		sudo dnf groupinstall -y "Development Tools" "Development Libraries"
-		;;
+			$privesc dnf groupinstall -y "Development Tools" "Development Libraries"
+			;;
 	esac
 
 	echo "Installing keyd"
 	case $distro in
 		suse)
-		sudo zypper --non-interactive install keyd
-		;;
+			$privesc zypper --non-interactive install keyd
+			;;
 		arch)
-		git clone https://aur.archlinux.org/keyd.git
-		cd keyd
-		makepkg -si --noconfirm
-		cd ..
-		;;
+			git clone https://aur.archlinux.org/keyd.git
+			cd keyd
+			makepkg -si --noconfirm
+			cd ..
+			;;
 		alpine)
-		doas apk add --no-interactive keyd
-		;;
+			$privesc apk add --no-interactive keyd
+			;;
 		*)
-		git clone https://github.com/rvaiya/keyd
-		cd keyd
-		make
-		sudo make install
-		cd ..
-		;;
+			git clone https://github.com/rvaiya/keyd
+			cd keyd
+			make
+			$privesc make install
+			cd ..
+			;;
 	esac
 fi
 
@@ -61,27 +67,27 @@ echo "Generating config"
 python3 cros-keyboard-map.py
 
 echo "Installing config"
-sudo mkdir -p /etc/keyd
-sudo cp cros.conf /etc/keyd
+$privesc mkdir -p /etc/keyd
+$privesc cp cros.conf /etc/keyd
 
 echo "Enabling keyd"
 case $distro in
     alpine)
-        doas rc-update add keyd
-        doas rc-service keyd restart
+        $privesc rc-update add keyd
+        $privesc rc-service keyd restart
 	;;
     *)
-        sudo systemctl enable keyd
-	sudo systemctl restart keyd
+        $privesc systemctl enable keyd
+	$privesc systemctl restart keyd
 	;;
 esac
 
 echo "Installing libinput configuration"
-sudo mkdir -p /etc/libinput
+$privesc mkdir -p /etc/libinput
 if [ -f /etc/libinput/local-overrides.quirks ]; then
-    cat $ROOT/local-overrides.quirks | sudo tee -a /etc/libinput/local-overrides.quirks > /dev/null
+    cat $ROOT/local-overrides.quirks | $privesc tee -a /etc/libinput/local-overrides.quirks > /dev/null
 else
-    sudo cp $ROOT/local-overrides.quirks /etc/libinput/local-overrides.quirks
+    $privesc cp $ROOT/local-overrides.quirks /etc/libinput/local-overrides.quirks
 fi
 
 echo "Done"