-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·70 lines (58 loc) · 1.68 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/env bash
echo "Starting inital setup"
## GENERATED BY CHATGPT
# Check if an argument was provided
if [ $# -ne 1 ]; then
echo "Usage: $0 [desktop|laptop]"
exit 1
fi
# Convert the argument to lowercase to ensure case-insensitive comparison
device_type=$(echo "$1" | tr '[:upper:]' '[:lower:]')
# List of packages to install
packages=(
curl
git
pipx
wget
)
# Function to install packages using apt
install_with_apt() {
echo "Using apt to install packages..."
sudo apt update
sudo apt upgrade -y
sudo apt install -y "${packages[@]}"
}
# Function to install packages using dnf
install_with_dnf() {
echo "Using dnf to install packages..."
sudo dnf install -y "${packages[@]}"
}
# Detect package manager and install packages
if command -v apt >/dev/null 2>&1; then
install_with_apt
elif command -v dnf >/dev/null 2>&1; then
install_with_dnf
else
echo "Neither apt nor dnf found. Exiting."
exit 1
fi
# Install Ansible with pipx
echo "Installing Ansible with pipx"
pipx ensurepath
pipx install --include-deps ansible
# Add user to passwordless sudo
echo "Adding user to passwordless sudo"
sudo echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/$USER
# Initial Ansible pull
# Check the input and run the corresponding playbook
if [ "$device_type" == "desktop" ]; then
echo "Running pull for desktop..."
ansible-pull -U https://github.com/0lzi/workstation-config.git -e 'desktop=true'
elif [ "$device_type" == "laptop" ]; then
echo "Running pull for laptop..."
ansible-pull -U https://github.com/0lzi/workstation-config.git
else
echo "Invalid input. Please enter either 'desktop' or 'laptop'."
exit 1
fi
echo "Reboot may be required..."