Skip to content

Instantly share code, notes, and snippets.

@kensleDev
Last active April 2, 2024 11:12
Show Gist options
  • Save kensleDev/9c52976e734994eb64ff187b19bdcffa to your computer and use it in GitHub Desktop.
Save kensleDev/9c52976e734994eb64ff187b19bdcffa to your computer and use it in GitHub Desktop.
username="kd"
apps=("python3" "python3-pip" "git" "curl" "wget" "lsb-release" "stow" "trash-cli" "silversearcher-ag" "fd-find" "ripgrep" "unzip" "fzf" "duf" "ncdu" "tmux" "jq" "zsh" "python3-venv")
apps_to_configure=("git" "tmux" "zsh" "coc")
architecture=$(uname -m)
install_apt_apps() {
for app in "${apps[@]}"; do
check_and_install $app
done
}
configure_apps() {
git clone https://github.com/julian-iaquinandi/dotfiles.git /home/"$username"/dotfiles
for app in "${apps_to_configure[@]}"; do
configure_with_stow $app
done
}
check_and_install() {
app=$1
if ! command -v $app &> /dev/null
then
echo "$app is not installed. Installing..."
sudo apt install -y $app
else
echo "$app is already installed."
fi
}
configure_with_stow() {
app=$1
dotfiles_dir="/home/kd/dotfiles" # Path to your dotfiles directory
# Check if the application folder exists in the dotfiles directory
if [ -d "$dotfiles_dir/$app" ]; then
echo "Configuring $app using stow..."
(cd $dotfiles_dir && stow $app)
else
echo "No configuration found for $app in $dotfiles_dir."
fi
}
check_linode_server() {
# Extract the CPU model name
cpu_model=$(grep -m 1 'model name' /proc/cpuinfo | awk -F': ' '{print $2}')
# Check if the CPU model contains 'AMD EPYC'
if [[ $cpu_model == *"AMD EPYC"* ]]; then
export IS_LINODE="true"
echo "IS_LINODE: $IS_LINODE"
else
export IS_LINODE="false"
fi
}
create_user_if_linode() {
if [[ $IS_LINODE == "true" ]]; then
if id "$username" &>/dev/null; then
echo "User $username found."
else
echo "Creating user $username..."
sudo adduser "$username" --disabled-password --gecos ""
# Prompt for the password
echo "Please enter a password for $username:"
read -s password
# Set the password for the user
echo "$username:$password" | sudo chpasswd
sudo usermod -aG sudo "$username"
echo "Rebooting!"
sleep 3
sudo reboot
fi
fi
}
install_gitpm() {
mkdir /home/"$username"/.local
mkdir /home/"$username"/.local/bin
curl https://gist.githubusercontent.com/kensleDev/9c52976e734994eb64ff187b19bdcffa/raw/b2907b0b7db3139b89697b460e3aecc4ffcbc21d/gitpm -o /home/"$username"/.local/bin/gitpm
sudo chmod u+x /home/"$username"/.local/bin/gitpm
export PATH="$HOME/.local/bin:$PATH"
}
install_bob_neovim() {
cargo install bob &&
bob install 25bedc92514b5f9aff129e62fbad30a3db48fccb &&
bob use 25bedc92514b5f9aff129e62fbad30a3db48fccb
git clone https://github.com/NvChad/NvChad ~/.config/nvim-chad --depth 1
configure_with_stow nv-chad
}
install_oh_my_zsh() {
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
echo "source ~/.config/zsh/.zshrc" > ~/.zshrc
}
install_nvm() {
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
export NVM_DIR=$HOME/.nvm;
source $NVM_DIR/nvm.sh;
nvm install stable
nvm use stable
}
install_rust() {
curl https://sh.rustup.rs -sSf | sh -s -- -y
source "$HOME/.cargo/env"
}
install_bum() {
curl -fsSL https://github.com/owenizedd/bum/raw/main/install.sh | bash
source ~/.zshrc
bum use 1.0.14
}
install_lazygit() {
if [ "$architecture" = "aarch64" ]; then
mkdir tmp && cd tmp
curl -Lo lazygit.tar.gz https://github.com/jesseduffield/lazygit/releases/download/v0.40.2/lazygit_0.40.2_Linux_arm64.tar.gz
tar xf lazygit.tar.gz lazygit
mv lazygit ~/.local/bin
cd .. && rm -rf tmp
else
mkdir tmp && cd tmp
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')
curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
tar xf lazygit.tar.gz lazygit
mv lazygit ~/.local/bin
rm lazygit.tar.gz
cd .. && rm -rf tmp
fi
}
install_exa() {
/home/"$username"/.local/bin/gitpm ogham/exa
}
install_gh() {
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
}
install_dotnet() {
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh
./dotnet-install.sh --version latest
rm dotnet-install.sh
}
sudo apt update -y && sudo apt upgrade -y
check_linode_server
create_user_if_linode
install_apt_apps
configure_apps
install_gitpm
install_oh_my_zsh
install_nvm
install_rust
install_bob_neovim
install_dotnet
install_lazygit
install_exa
install_gh
install_bum
#!/bin/bash
# Define the GitHub user and repository
GITHUB_USER_REPO="$1"
# Define the API URL to fetch the latest release from the GitHub repository
API_URL="https://api.github.com/repos/$GITHUB_USER_REPO/releases/latest"
# Define the installation path
INSTALL_PATH="$HOME/.local/bin"
# Fetch the latest release data using GitHub API
RELEASE_DATA=$(curl -s $API_URL)
# Determine the architecture of the current machine
ARCH=$(uname -m)
# Select the appropriate file extension and asset based on the architecture
if [ "$ARCH" = "arm64" ]; then
# Assuming ARM binaries are tagged with 'arm64' or similar in their names
ASSET_URL=$(echo $RELEASE_DATA | jq -r '.assets[] | select(.name | contains("arm64") and endswith(".zip")).browser_download_url')
else
# For x86_64 (Intel/AMD) architectures
ASSET_URL=$(echo $RELEASE_DATA | jq -r '.assets[] | select(.name | endswith(".zip") and (contains("amd64") or contains("x86_64"))).browser_download_url')
fi
# Check if the asset URL is empty
if [ -z "$ASSET_URL" ]; then
echo "Error: No compatible asset found for the latest release."
exit 1
fi
# Download the asset
curl -L $ASSET_URL -o /tmp/github_release.zip
# Create the installation directory if it doesn't exist
mkdir -p $INSTALL_PATH
# Unzip the release
unzip /tmp/github_release.zip -d $INSTALL_PATH
# Remove the downloaded zip file
rm /tmp/github_release.zip
echo "Installation complete. The release has been installed to $INSTALL_PATH"
# Define the path
BIN_PATH="$HOME/.local/bin"
# Loop through each item in the directory
for item in "$BIN_PATH"/*; do
# Check if the item is a directory
if [ -d "$item" ]; then
# Count the number of files in the directory
file_count=$(find "$item" -maxdepth 1 -type f | wc -l)
# Proceed if there is exactly one file in the directory
if [ "$file_count" -eq 1 ]; then
# Get the full path of the file
file_path=$(find "$item" -maxdepth 1 -type f)
# Move the file to BIN_PATH
mv "$file_path" "$BIN_PATH"
# Make the binary executable
chmod +x "$BIN_PATH/$(basename "$file_path")"
# Remove the now-empty directory
rmdir "$item"
fi
fi
done
echo "Cleanup complete."
##############################
# 0 - Create user if not exist
##############################
if id kd &>/dev/null; then
echo 'user found'
else
sudo adduser kd
sudo usermod -aG sudo kd
su - kd
fi
##############################
# 1 - Install Ansible dependancies (Python3) and clone dotfiles
##############################
sed -i "s/#\$nrconf{kernelhints} = -1;/\$nrconf{kernelhints} = -1;/g" /etc/needrestart/needrestart.conf
sudo apt update -y &&
sudo apt upgrade -y &&
sudo apt install -y python3 python3-pip git ansible
git clone https://github.com/julian-iaquinandi/dotfiles ~/dotfiles
##########################################
# 2a - Run Install Script
##########################################
sudo bash ~/dotfiles/ansible/init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment