mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-05 21:28:48 +00:00
refactor: Use common script to avoid code duplication
This commit is contained in:
parent
9403f30157
commit
e5ddd2ee48
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
RC='\033[0m'
|
RC='\033[0m'
|
||||||
RED='\033[31m'
|
RED='\033[31m'
|
||||||
YELLOW='\033[33m'
|
YELLOW='\033[33m'
|
||||||
|
|
|
@ -1,63 +1,5 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
RC='\033[0m'
|
|
||||||
RED='\033[31m'
|
|
||||||
YELLOW='\033[33m'
|
|
||||||
GREEN='\033[32m'
|
|
||||||
|
|
||||||
command_exists() {
|
|
||||||
which $1 >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
checkEnv() {
|
|
||||||
## Check for requirements.
|
|
||||||
REQUIREMENTS='curl groups sudo'
|
|
||||||
for req in ${REQUIREMENTS}; do
|
|
||||||
if ! command_exists ${req}; then
|
|
||||||
echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check Package Handler
|
|
||||||
PACKAGEMANAGER='apt-get dnf pacman zypper'
|
|
||||||
for pgm in ${PACKAGEMANAGER}; do
|
|
||||||
if command_exists ${pgm}; then
|
|
||||||
PACKAGER=${pgm}
|
|
||||||
echo "Using ${pgm}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "${PACKAGER}" ]; then
|
|
||||||
echo -e "${RED}Can't find a supported package manager${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Check SuperUser Group
|
|
||||||
SUPERUSERGROUP='wheel sudo root'
|
|
||||||
for sug in ${SUPERUSERGROUP}; do
|
|
||||||
if groups | grep -q ${sug}; then
|
|
||||||
SUGROUP=${sug}
|
|
||||||
echo "Super user group ${SUGROUP}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check if member of the sudo group.
|
|
||||||
if ! groups | grep -q ${SUGROUP}; then
|
|
||||||
echo -e "${RED}You need to be a member of the sudo group to run me!${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
DTYPE="unknown" # Default to unknown
|
|
||||||
# Use /etc/os-release for modern distro identification
|
|
||||||
if [ -f /etc/os-release ]; then
|
|
||||||
. /etc/os-release
|
|
||||||
DTYPE=$ID
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
setupAlacritty() {
|
setupAlacritty() {
|
||||||
echo "Install Alacritty if not already installed..."
|
echo "Install Alacritty if not already installed..."
|
||||||
if ! command_exists alacritty; then
|
if ! command_exists alacritty; then
|
||||||
|
|
|
@ -1,63 +1,5 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
RC='\033[0m'
|
|
||||||
RED='\033[31m'
|
|
||||||
YELLOW='\033[33m'
|
|
||||||
GREEN='\033[32m'
|
|
||||||
|
|
||||||
command_exists() {
|
|
||||||
which $1 >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
checkEnv() {
|
|
||||||
## Check for requirements.
|
|
||||||
REQUIREMENTS='curl groups sudo'
|
|
||||||
for req in ${REQUIREMENTS}; do
|
|
||||||
if ! command_exists ${req}; then
|
|
||||||
echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check Package Handler
|
|
||||||
PACKAGEMANAGER='apt-get dnf pacman zypper'
|
|
||||||
for pgm in ${PACKAGEMANAGER}; do
|
|
||||||
if command_exists ${pgm}; then
|
|
||||||
PACKAGER=${pgm}
|
|
||||||
echo "Using ${pgm}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "${PACKAGER}" ]; then
|
|
||||||
echo -e "${RED}Can't find a supported package manager${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Check SuperUser Group
|
|
||||||
SUPERUSERGROUP='wheel sudo root'
|
|
||||||
for sug in ${SUPERUSERGROUP}; do
|
|
||||||
if groups | grep -q ${sug}; then
|
|
||||||
SUGROUP=${sug}
|
|
||||||
echo "Super user group ${SUGROUP}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check if member of the sudo group.
|
|
||||||
if ! groups | grep -q ${SUGROUP}; then
|
|
||||||
echo -e "${RED}You need to be a member of the sudo group to run me!${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
DTYPE="unknown" # Default to unknown
|
|
||||||
# Use /etc/os-release for modern distro identification
|
|
||||||
if [ -f /etc/os-release ]; then
|
|
||||||
. /etc/os-release
|
|
||||||
DTYPE=$ID
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
setupKitty() {
|
setupKitty() {
|
||||||
echo "Install Kitty if not already installed..."
|
echo "Install Kitty if not already installed..."
|
||||||
if ! command_exists kitty; then
|
if ! command_exists kitty; then
|
||||||
|
|
|
@ -1,63 +1,5 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
RC='\033[0m'
|
|
||||||
RED='\033[31m'
|
|
||||||
YELLOW='\033[33m'
|
|
||||||
GREEN='\033[32m'
|
|
||||||
|
|
||||||
command_exists() {
|
|
||||||
which "$1" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
checkEnv() {
|
|
||||||
## Check for requirements.
|
|
||||||
REQUIREMENTS='curl groups sudo'
|
|
||||||
for req in $REQUIREMENTS; do
|
|
||||||
if ! command_exists "$req"; then
|
|
||||||
echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check Package Handler
|
|
||||||
PACKAGEMANAGER='apt-get dnf pacman zypper'
|
|
||||||
for pgm in $PACKAGEMANAGER; do
|
|
||||||
if command_exists "$pgm"; then
|
|
||||||
PACKAGER="$pgm"
|
|
||||||
echo "Using $pgm"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "$PACKAGER" ]; then
|
|
||||||
echo -e "${RED}Can't find a supported package manager${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Check SuperUser Group
|
|
||||||
SUPERUSERGROUP='wheel sudo root'
|
|
||||||
for sug in $SUPERUSERGROUP; do
|
|
||||||
if groups | grep -q "$sug"; then
|
|
||||||
SUGROUP="$sug"
|
|
||||||
echo "Super user group $SUGROUP"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check if member of the sudo group.
|
|
||||||
if ! groups | grep -q "$SUGROUP"; then
|
|
||||||
echo -e "${RED}You need to be a member of the sudo group to run me!${RC}\n"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
DTYPE="unknown" # Default to unknown
|
|
||||||
# Use /etc/os-release for modern distro identification
|
|
||||||
if [ -f /etc/os-release ]; then
|
|
||||||
. /etc/os-release
|
|
||||||
DTYPE="$ID"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
setupRofi() {
|
setupRofi() {
|
||||||
echo "Install Rofi if not already installed..."
|
echo "Install Rofi if not already installed..."
|
||||||
if ! command_exists rofi; then
|
if ! command_exists rofi; then
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
RC='\033[0m'
|
|
||||||
RED='\033[31m'
|
|
||||||
YELLOW='\033[33m'
|
|
||||||
GREEN='\033[32m'
|
|
||||||
|
|
||||||
# Check if the home directory and linuxtoolbox folder exist, create them if they don't
|
# Check if the home directory and linuxtoolbox folder exist, create them if they don't
|
||||||
LINUXTOOLBOXDIR="$HOME/linuxtoolbox"
|
LINUXTOOLBOXDIR="$HOME/linuxtoolbox"
|
||||||
|
|
||||||
|
@ -27,59 +22,6 @@ fi
|
||||||
|
|
||||||
cd "$LINUXTOOLBOXDIR/linux-setup" || exit
|
cd "$LINUXTOOLBOXDIR/linux-setup" || exit
|
||||||
|
|
||||||
command_exists() {
|
|
||||||
command -v "$1" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
checkEnv() {
|
|
||||||
## Check for requirements.
|
|
||||||
REQUIREMENTS='curl groups sudo'
|
|
||||||
for req in $REQUIREMENTS; do
|
|
||||||
if ! command_exists "$req"; then
|
|
||||||
echo -e "${RED}To run me, you need: $REQUIREMENTS${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check Package Manager
|
|
||||||
PACKAGEMANAGER='apt yum dnf pacman zypper'
|
|
||||||
for pgm in $PACKAGEMANAGER; do
|
|
||||||
if command_exists "$pgm"; then
|
|
||||||
PACKAGER="$pgm"
|
|
||||||
echo "Using $pgm"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "$PACKAGER" ]; then
|
|
||||||
echo -e "${RED}Can't find a supported package manager${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Check if the current directory is writable.
|
|
||||||
GITPATH="$(dirname "$(realpath "$0")")"
|
|
||||||
if [ ! -w "$GITPATH" ]; then
|
|
||||||
echo -e "${RED}Can't write to $GITPATH${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Check SuperUser Group
|
|
||||||
SUPERUSERGROUP='wheel sudo root'
|
|
||||||
for sug in $SUPERUSERGROUP; do
|
|
||||||
if groups | grep -q "$sug"; then
|
|
||||||
SUGROUP="$sug"
|
|
||||||
echo "Super user group $SUGROUP"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check if member of the sudo group.
|
|
||||||
if ! groups | grep -q "$SUGROUP"; then
|
|
||||||
echo -e "${RED}You need to be a member of the sudo group to run me!${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
installDepend() {
|
installDepend() {
|
||||||
## Check for dependencies.
|
## Check for dependencies.
|
||||||
DEPENDENCIES='tar tree multitail tldr trash-cli unzip cmake make jq'
|
DEPENDENCIES='tar tree multitail tldr trash-cli unzip cmake make jq'
|
||||||
|
|
|
@ -1,60 +1,5 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
RC='\e[0m'
|
|
||||||
RED='\e[31m'
|
|
||||||
YELLOW='\e[33m'
|
|
||||||
GREEN='\e[32m'
|
|
||||||
|
|
||||||
command_exists() {
|
|
||||||
command -v $1 >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
checkEnv() {
|
|
||||||
## Check for requirements.
|
|
||||||
REQUIREMENTS='curl groups sudo'
|
|
||||||
if ! command_exists ${REQUIREMENTS}; then
|
|
||||||
echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Check Package Handeler
|
|
||||||
PACKAGEMANAGER='apt-get yum dnf pacman zypper'
|
|
||||||
for pgm in ${PACKAGEMANAGER}; do
|
|
||||||
if command_exists ${pgm}; then
|
|
||||||
PACKAGER=${pgm}
|
|
||||||
echo "Using ${pgm}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "${PACKAGER}" ]; then
|
|
||||||
echo -e "${RED}Can't find a supported package manager"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Check if the current directory is writable.
|
|
||||||
GITPATH="$(dirname "$(readlink -f "$0")")"
|
|
||||||
if [ ! -w ${GITPATH} ]; then
|
|
||||||
echo -e "${RED}Can't write to ${GITPATH}${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Check SuperUser Group
|
|
||||||
SUPERUSERGROUP='wheel sudo root'
|
|
||||||
for sug in ${SUPERUSERGROUP}; do
|
|
||||||
if groups | grep ${sug}; then
|
|
||||||
SUGROUP=${sug}
|
|
||||||
echo "Super user group ${SUGROUP}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check if member of the sudo group.
|
|
||||||
if ! groups | grep ${SUGROUP} >/dev/null; then
|
|
||||||
echo -e "${RED}You need to be a member of the sudo group to run me!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
installDepend() {
|
installDepend() {
|
||||||
## Check for dependencies.
|
## Check for dependencies.
|
||||||
echo -e "${YELLOW}Installing dependencies...${RC}"
|
echo -e "${YELLOW}Installing dependencies...${RC}"
|
||||||
|
|
|
@ -1,62 +1,5 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
RC='\033[0m'
|
|
||||||
RED='\033[31m'
|
|
||||||
YELLOW='\033[33m'
|
|
||||||
GREEN='\033[32m'
|
|
||||||
|
|
||||||
command_exists() {
|
|
||||||
which $1 >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
checkEnv() {
|
|
||||||
## Check for requirements.
|
|
||||||
REQUIREMENTS='curl groups sudo'
|
|
||||||
for req in ${REQUIREMENTS}; do
|
|
||||||
if ! command_exists ${req}; then
|
|
||||||
echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
## Check Package Handler
|
|
||||||
PACKAGEMANAGER='apt-get nala dnf pacman zypper yum xbps-install'
|
|
||||||
for pgm in ${PACKAGEMANAGER}; do
|
|
||||||
if command_exists ${pgm}; then
|
|
||||||
PACKAGER=${pgm}
|
|
||||||
echo "Using ${pgm}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "${PACKAGER}" ]; then
|
|
||||||
echo -e "${RED}Can't find a supported package manager${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Check SuperUser Group
|
|
||||||
SUPERUSERGROUP='wheel sudo root'
|
|
||||||
for sug in ${SUPERUSERGROUP}; do
|
|
||||||
if groups | grep ${sug} >/dev/null; then
|
|
||||||
SUGROUP=${sug}
|
|
||||||
echo "Super user group ${SUGROUP}"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## Check if member of the sudo group.
|
|
||||||
if ! groups | grep ${SUGROUP} >/dev/null; then
|
|
||||||
echo -e "${RED}You need to be a member of the sudo group to run me!${RC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
DTYPE="unknown" # Default to unknown
|
|
||||||
# Use /etc/os-release for modern distro identification
|
|
||||||
if [ -f /etc/os-release ]; then
|
|
||||||
. /etc/os-release
|
|
||||||
DTYPE=$ID
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
fastUpdate() {
|
fastUpdate() {
|
||||||
case ${PACKAGER} in
|
case ${PACKAGER} in
|
||||||
pacman)
|
pacman)
|
||||||
|
|
21
src/list.rs
21
src/list.rs
|
@ -11,6 +11,15 @@ use ratatui::{
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
macro_rules! with_common_script {
|
||||||
|
($command:expr) => {
|
||||||
|
concat!(
|
||||||
|
include_str!("commands/common-script.sh"),
|
||||||
|
include_str!($command)
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
struct ListNode {
|
struct ListNode {
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
command: &'static str,
|
command: &'static str,
|
||||||
|
@ -57,7 +66,7 @@ impl CustomList {
|
||||||
} => {
|
} => {
|
||||||
ListNode {
|
ListNode {
|
||||||
name: "Full System Update",
|
name: "Full System Update",
|
||||||
command: include_str!("commands/system-update.sh"),
|
command: with_common_script!("commands/system-update.sh"),
|
||||||
},
|
},
|
||||||
ListNode {
|
ListNode {
|
||||||
name: "Setup Bash Prompt",
|
name: "Setup Bash Prompt",
|
||||||
|
@ -77,11 +86,11 @@ impl CustomList {
|
||||||
} => {
|
} => {
|
||||||
ListNode {
|
ListNode {
|
||||||
name: "Build Prerequisites",
|
name: "Build Prerequisites",
|
||||||
command: include_str!("commands/system-setup/1-compile-setup.sh"),
|
command: with_common_script!("commands/system-setup/1-compile-setup.sh"),
|
||||||
},
|
},
|
||||||
ListNode {
|
ListNode {
|
||||||
name: "Gaming Dependencies",
|
name: "Gaming Dependencies",
|
||||||
command: include_str!("commands/system-setup/2-gaming-setup.sh"),
|
command: with_common_script!("commands/system-setup/2-gaming-setup.sh"),
|
||||||
},
|
},
|
||||||
ListNode {
|
ListNode {
|
||||||
name: "Recursion?",
|
name: "Recursion?",
|
||||||
|
@ -94,15 +103,15 @@ impl CustomList {
|
||||||
} => {
|
} => {
|
||||||
ListNode {
|
ListNode {
|
||||||
name: "Alacritty Setup",
|
name: "Alacritty Setup",
|
||||||
command: include_str!("commands/dotfiles/alacritty-setup.sh"),
|
command: with_common_script!("commands/dotfiles/alacritty-setup.sh"),
|
||||||
},
|
},
|
||||||
ListNode {
|
ListNode {
|
||||||
name: "Kitty Setup",
|
name: "Kitty Setup",
|
||||||
command: include_str!("commands/dotfiles/kitty-setup.sh"),
|
command: with_common_script!("commands/dotfiles/kitty-setup.sh"),
|
||||||
},
|
},
|
||||||
ListNode {
|
ListNode {
|
||||||
name: "Rofi Setup",
|
name: "Rofi Setup",
|
||||||
command: include_str!("commands/dotfiles/rofi-setup.sh"),
|
command: with_common_script!("commands/dotfiles/rofi-setup.sh"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user