organized and added help to install script.

This commit is contained in:
Josh Ashton
2024-02-12 21:44:09 -07:00
parent 453fc683e5
commit 399470c771
2 changed files with 48 additions and 54 deletions
+8 -1
View File
@@ -20,21 +20,27 @@ install() {
if [[ $DISTRO == "arch" ]]; then if [[ $DISTRO == "arch" ]]; then
yes | sudo pacman -S $PACKAGE yes | sudo pacman -S $PACKAGE
yes | sudo pacman -S $COMMAND
exit 0 exit 0
elif [[ $DISTRO == "archarm" ]]; then elif [[ $DISTRO == "archarm" ]]; then
yes | sudo pacman -S $PACKAGE yes | sudo pacman -S $PACKAGE
yes | sudo pacman -S $COMMAND
exit 0 exit 0
elif [[ $DISTRO == "ubuntu" ]]; then elif [[ $DISTRO == "ubuntu" ]]; then
yes | sudo apt-get install $PACKAGE yes | sudo apt-get install $PACKAGE
yes | sudo apt-get install $COMMAND
exit 0 exit 0
elif [[ $DISTRO == "fedora" ]]; then elif [[ $DISTRO == "fedora" ]]; then
yes | sudo dnf install $PACKAGE yes | sudo dnf install $PACKAGE
yes | sudo dnf install $COMMAND
exit 0 exit 0
elif [[ $DISTRO == "centos" ]]; then elif [[ $DISTRO == "centos" ]]; then
yes | sudo yum install $PACKAGE yes | sudo yum install $PACKAGE
yes | sudo yum install $COMMAND
exit 0 exit 0
elif [[ $DISTRO == "debian" ]]; then elif [[ $DISTRO == "debian" ]]; then
yes | sudo apt install $PACKAGE yes | sudo apt install $PACKAGE
yes | sudo apt install $COMMAND
exit 0 exit 0
else else
error error
@@ -46,11 +52,12 @@ install() {
if command -v "brew" &> /dev/null if command -v "brew" &> /dev/null
then then
yes | brew install $PACKAGE yes | brew install $PACKAGE
yes | brew install $COMMAND
elif command -v "port" &> /dev/null elif command -v "port" &> /dev/null
then then
yes | sudo port install $PACKAGE yes | sudo port install $PACKAGE
yes | sudo port install $COMMAND
else else
echo "Homebrew or MacPorts not found. Please install one of them before running this script." echo "Homebrew or MacPorts not found. Please install one of them before running this script."
exit 1 exit 1
+40 -53
View File
@@ -1,7 +1,25 @@
#!/bin/zsh #!/bin/zsh
# This is the intial install script for quaxlyqueen/scripts. help() {
# It will install the scripts and set up the environment. echo "This script installs and sets up the configuration for the repo quaxlyqueen/scripts."
echo "It will install the scripts in /usr/local/bin and set up the environment variables and aliases."
echo "The user will be prompted to:"
echo " - Set up the environment variables and aliases"
echo " - Create a theme for supported applications"
echo " - Set up Git, github-cli (gh), and gclone"
echo "\nUsage: sudo ./install"
echo " sudo ./install -h | --help"
exit 0
}
# The script must be run as root
is_root() {
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
exit 1
fi
}
create_theme() { create_theme() {
USER=$1 USER=$1
@@ -12,8 +30,8 @@ create_theme() {
echo "Supported applications will automatically use the active.theme link to theme themselves." echo "Supported applications will automatically use the active.theme link to theme themselves."
echo "active.theme is a symbolic link to (for eg.) light.theme or dark.theme." echo "active.theme is a symbolic link to (for eg.) light.theme or dark.theme."
echo "\nMany themes can be created with this format, and using the `set-theme <theme>` command." echo "\nMany themes can be created with this format, and using the 'set-theme <theme>' command."
echo "See `set-theme --help` for more information." echo "See 'set-theme --help' for more information."
echo "\n\nYou can create a theme now or use the default light and dark themes." echo "\n\nYou can create a theme now or use the default light and dark themes."
read "?Do you want to create a theme now? (y/n) " CHOICE read "?Do you want to create a theme now? (y/n) " CHOICE
@@ -33,7 +51,7 @@ create_theme() {
su $USER -c "echo 'hover=$HOVER' >> $DIR/$NAME.theme" su $USER -c "echo 'hover=$HOVER' >> $DIR/$NAME.theme"
echo "Theme created successfully." echo "Theme created successfully."
echo "You can now use the `set-theme $NAME` command to use this theme." echo "You can now use the 'set-theme $NAME' command to use this theme."
echo "Setting the active theme to $NAME.theme..." echo "Setting the active theme to $NAME.theme..."
su $USER -c "ln -s $DIR/$NAME.theme $DIR/active.theme" su $USER -c "ln -s $DIR/$NAME.theme $DIR/active.theme"
@@ -59,57 +77,12 @@ create_theme() {
fi fi
} }
install_gh() {
# Install github-cli
if ! command -v "gh" &> /dev/null
then
echo "gh not found. Installing gh..."
COMMAND="gh"
PACKAGE="github-cli"
if [[ "$OSTYPE" == "darwin"* ]]; then
DISTRO=$(cat /etc/os-release | grep -oP '(?<=^ID=).+' | tr -d '"')
if [[ $DISTRO == "arch" ]]; then
yes | sudo pacman -S $PACKAGE
elif [[ $DISTRO == "archarm" ]]; then
yes | sudo pacman -S $PACKAGE
elif [[ $DISTRO == "ubuntu" ]]; then
yes | sudo apt-get install $PACKAGE
elif [[ $DISTRO == "fedora" ]]; then
yes | sudo dnf install $PACKAGE
elif [[ $DISTRO == "centos" ]]; then
yes | sudo yum install $PACKAGE
elif [[ $DISTRO == "debian" ]]; then
yes | sudo apt install $PACKAGE
else
echo "Unsupported distro. Please install $COMMAND from $PACKAGE manually."
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "gh not found. Installing gh..."
if command -v "brew" &> /dev/null
then
yes | brew install $COMMAND
elif command -v "port" &> /dev/null
then
yes | sudo port install $COMMAND
else
echo "Homebrew or MacPorts not found. Please install one of them before running this script."
fi
fi
fi
}
setup_git() { setup_git() {
# Set up gclone # Set up gclone
if [ ! -d "/home/$USER/.config/gclone" ]; then if [ ! -d "/home/$USER/.config/gclone" ]; then
su $USER -c "mkdir /home/$USER/.config/gclone" su $USER -c "mkdir /home/$USER/.config/gclone"
su $USER -c "touch /home/$USER/.config/gclone/gclone.conf" su $USER -c "touch /home/$USER/.config/gclone/gclone.conf"
read "?Please enter your GitHub user name for gclone: " GHUSER read "?Please enter your GitHub user name for gclone: " GHUSER
su $USER -c "gclone --set-default $GHUSER" su $USER -c "gclone --set-default $GHUSER"
fi fi
@@ -118,15 +91,19 @@ setup_git() {
if [ ! -f "/home/$USER/.gitconfig" ]; then if [ ! -f "/home/$USER/.gitconfig" ]; then
read "?Please enter your name for Git: " NAME read "?Please enter your name for Git: " NAME
read "?Please enter your email for Git: " EMAIL read "?Please enter your email for Git: " EMAIL
su $USER -c "git config --global user.name $NAME" su $USER -c "git config --global user.name $NAME"
su $USER -c "git config --global user.email $EMAIL" su $USER -c "git config --global user.email $EMAIL"
fi fi
# Install github-cli if it is not already installed
check_dependency "gh" "github-cli"
# If the user has not set up github-cli, do so now # If the user has not set up github-cli, do so now
install_gh
if [ ! -f "/home/$USER/.config/gh/hosts.yml" ]; then if [ ! -f "/home/$USER/.config/gh/hosts.yml" ]; then
echo "Please log in to GitHub using github-cli." echo "Please log in to GitHub using github-cli."
echo "This will allow you to modify your repositories and other GitHub features." echo "This will allow you to modify your repositories and other GitHub features."
su $USER -c "gh auth login" su $USER -c "gh auth login"
fi fi
} }
@@ -147,6 +124,9 @@ setup_environment() {
echo "alias goto='. goto $1'" >> ~/.zshrc echo "alias goto='. goto $1'" >> ~/.zshrc
echo "export PATH=$PATH:$DIR" >> ~/.zshrc echo "export PATH=$PATH:$DIR" >> ~/.zshrc
# Source the .zshrc file to update the environment
source ~/.zshrc
USER=$SUDO_USER USER=$SUDO_USER
if [ ! -d "/home/$USER/.config" ]; then if [ ! -d "/home/$USER/.config" ]; then
su $USER -c "mkdir /home/$USER/.config" su $USER -c "mkdir /home/$USER/.config"
@@ -160,12 +140,19 @@ setup_environment() {
setup_git setup_git
} }
is_root
if [[ $# -eq 1 ]]; then
if [[ $1 == "-h" || $1 == "--help" ]]; then
help
fi
fi
# Install the scripts # Install the scripts
echo "Installing scripts..." echo "Installing scripts..."
sudo cp * /usr/local/bin sudo cp * /usr/local/bin
setup_environment setup_environment
echo "Installation complete. Please restart your terminal to use the new commands, or run `source ~/.zshrc`." echo "Installation complete. Please restart your terminal to use the new commands, or run 'source ~/.zshrc'."
echo "To remove the scripts, simply delete the files in /usr/local/bin and remove the aliases from your .zshrc file." echo "To remove the scripts, simply delete the files in /usr/local/bin and remove the aliases from your .zshrc file."
echo "Thank you for using quaxlyqueen/scripts!" echo "Thank you for using quaxlyqueen/scripts!"
exit 0 exit 0