-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotfiles
More file actions
executable file
·77 lines (66 loc) · 1.69 KB
/
Copy pathdotfiles
File metadata and controls
executable file
·77 lines (66 loc) · 1.69 KB
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
71
72
73
74
75
76
77
#!/bin/bash
SSH_DIR="$HOME/.ssh"
DOTFILES_DIR="$HOME/.dotfiles"
function fedora_setup() {
if ! [[ -x $(command -v ansible) ]]; then
echo "Installing Ansible..."
sudo dnf install -y ansible git
fi
}
function ubuntu_setup() {
if ! [[ -x $(command -v ansible) ]]; then
echo "Installing Ansible..."
sudo apt install -y ansible git
fi
}
function arch_setup() {
if ! [[ -x $(command -v ansible) ]]; then
echo "Installing Ansible..."
sudo pacman -S ansible git openssh --noconfirm
fi
}
function setup_ssh() {
if ! [[ -d $SSH_DIR ]]; then
echo "Setting up SSH keys..."
mkdir -p $SSH_DIR
chmod 700 $SSH_DIR
ssh-keygen -b 4096 -t rsa -f $SSH_DIR/id_rsa -N "" -C "$USER@$HOSTNAME"
cat $SSH_DIR/id_rsa.pub > $SSH_DIR/authorized_keys
chmod 600 $SSH_DIR/authorized_keys
fi
}
# Detect the OS and run the appropriate setup function.
os=$(uname -n)
if [[ -f /etc/os-release ]]; then
source /etc/os-release
os=$ID
fi
case $os in
fedora)
fedora_setup
;;
ubuntu)
ubuntu_setup
;;
arch)
arch_setup
;;
*)
echo "Unsupported OS: $os"
exit 1
;;
esac
# Setup SSH keys for the current user if they don't already exist.
setup_ssh
# Clone the dotfiles repository if it doesn't already exist.
if ! [[ -d $DOTFILES_DIR ]]; then
echo "Cloning dotfiles repository..."
git clone "https://github.com/Juangr4/dotdev.git" $DOTFILES_DIR
else
echo "Updating dotfiles repository..."
git -C $DOTFILES_DIR pull
fi
# Install galaxy requirements.
ansible-galaxy install -r $DOTFILES_DIR/requirements.yml
# Run the Ansible playbook.
ANSIBLE_CONFIG=$DOTFILES_DIR/ansible.cfg ansible-playbook $DOTFILES_DIR/playbook.yml --ask-become-pass "$@"