From 0f0d67d419ed77f7edd1979320c6362091d1cd05 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Mon, 10 Mar 2025 15:05:52 +0100 Subject: [PATCH] feat: add checks for community.general collection and ensure default shell is set to bash --- config/ansible/main.yml | 13 +++++++++-- config/ansible/tasks/global/global.yml | 2 +- config/ansible/tasks/global/symlinks.yml | 1 - .../ansible/tasks/workstations/symlinks.yml | 13 +++++++++++ .../tasks/workstations/workstation.yml | 3 +++ config/home-manager/flake.lock | 12 +++++----- setup.sh | 23 +++++++++++++++++++ 7 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 config/ansible/tasks/workstations/symlinks.yml diff --git a/config/ansible/main.yml b/config/ansible/main.yml index e2e70f5..54a5fdf 100644 --- a/config/ansible/main.yml +++ b/config/ansible/main.yml @@ -3,9 +3,18 @@ gather_facts: true pre_tasks: - - name: Install required collections - ansible.builtin.command: ansible-galaxy collection install -r requirements.yml + - name: Check if community.general collection is installed + ansible.builtin.command: ansible-galaxy collection list community.general + register: collection_check + changed_when: false + ignore_errors: true delegate_to: localhost + + - name: Install required collections + ansible.builtin.command: ansible-galaxy collection install -r "{{ playbook_dir }}/requirements.yml" + delegate_to: localhost + when: collection_check.rc != 0 or "community.general" not in collection_check.stdout + changed_when: collection_check.rc != 0 or "community.general" not in collection_check.stdout run_once: true tasks: diff --git a/config/ansible/tasks/global/global.yml b/config/ansible/tasks/global/global.yml index 0d9e237..873b53e 100644 --- a/config/ansible/tasks/global/global.yml +++ b/config/ansible/tasks/global/global.yml @@ -1,4 +1,4 @@ -- name: Include symlinks tasks +- name: Include global symlinks tasks ansible.builtin.import_tasks: tasks/global/symlinks.yml - name: Gather package facts diff --git a/config/ansible/tasks/global/symlinks.yml b/config/ansible/tasks/global/symlinks.yml index 610f87b..161f983 100644 --- a/config/ansible/tasks/global/symlinks.yml +++ b/config/ansible/tasks/global/symlinks.yml @@ -11,7 +11,6 @@ follow: false loop: - { src: "$DOTFILES_PATH/config/home-manager", dest: "~/.config/home-manager" } - - { src: "$DOTFILES_PATH/vscode/settings.json", dest: "~/.config/Code/User/settings.json" } - { src: "$DOTFILES_PATH/config/ssh/config", dest: "~/.ssh/config" } - { src: "$DOTFILES_PATH/config/ssh/config.d", dest: "~/.ssh/config.d" } - { src: "$DOTFILES_PATH/config/starship.toml", dest: "~/.config/starship.toml" } diff --git a/config/ansible/tasks/workstations/symlinks.yml b/config/ansible/tasks/workstations/symlinks.yml new file mode 100644 index 0000000..958e8d9 --- /dev/null +++ b/config/ansible/tasks/workstations/symlinks.yml @@ -0,0 +1,13 @@ +- name: Set user home directory + ansible.builtin.set_fact: + user_home: "{{ ansible_env.HOME if ansible_user_id == 'root' else lookup('env', 'HOME') }}" + +- name: Create workstation symlinks + ansible.builtin.file: + src: "{{ item.src | replace('~', user_home) | replace('$DOTFILES_PATH', lookup('env', 'DOTFILES_PATH')) }}" + dest: "{{ item.dest | replace('~', user_home) }}" + state: link + force: true + follow: false + loop: + - { src: "$DOTFILES_PATH/vscode/settings.json", dest: "~/.config/Code/User/settings.json" } diff --git a/config/ansible/tasks/workstations/workstation.yml b/config/ansible/tasks/workstations/workstation.yml index 92591ae..6035aa5 100644 --- a/config/ansible/tasks/workstations/workstation.yml +++ b/config/ansible/tasks/workstations/workstation.yml @@ -1,3 +1,6 @@ +- name: Include workstation symlinks tasks + ansible.builtin.import_tasks: tasks/workstations/symlinks.yml + - name: Include GNOME Extensions tasks ansible.builtin.import_tasks: tasks/workstations/gnome-extensions.yml diff --git a/config/home-manager/flake.lock b/config/home-manager/flake.lock index 5779f61..46f9607 100644 --- a/config/home-manager/flake.lock +++ b/config/home-manager/flake.lock @@ -23,11 +23,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1741048562, - "narHash": "sha256-W4YZ3fvWZiFYYyd900kh8P8wU6DHSiwaH0j4+fai1Sk=", + "lastModified": 1741445498, + "narHash": "sha256-F5Em0iv/CxkN5mZ9hRn3vPknpoWdcdCyR0e4WklHwiE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "6af28b834daca767a7ef99f8a7defa957d0ade6f", + "rev": "52e3095f6d812b91b22fb7ad0bfc1ab416453634", "type": "github" }, "original": { @@ -39,11 +39,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1741173522, - "narHash": "sha256-k7VSqvv0r1r53nUI/IfPHCppkUAddeXn843YlAC5DR0=", + "lastModified": 1741379970, + "narHash": "sha256-Wh7esNh7G24qYleLvgOSY/7HlDUzWaL/n4qzlBePpiw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "d69ab0d71b22fa1ce3dbeff666e6deb4917db049", + "rev": "36fd87baa9083f34f7f5027900b62ee6d09b1f2f", "type": "github" }, "original": { diff --git a/setup.sh b/setup.sh index c815311..1e1875d 100755 --- a/setup.sh +++ b/setup.sh @@ -338,6 +338,28 @@ check_compatibility() { esac } +# Ensure bash is set as the default shell for the user +ensure_shell() { + local shell + shell=$(getent passwd "$USER" | cut -d: -f7) + if [ "$shell" != "/bin/bash" ]; then + log_info "Setting default shell to bash..." + chsh -s /bin/bash || die "Failed to set default shell to bash" + log_success "Default shell set to bash." + fi + + # Ensure shell is set for root user + if [ "$USER" != "root" ]; then + local root_shell + root_shell=$(getent passwd root | cut -d: -f7) + if [ "$root_shell" != "/bin/bash" ]; then + log_info "Setting default shell for root to bash..." + sudo chsh -s /bin/bash root || die "Failed to set default shell for root to bash" + log_success "Default shell for root set to bash." + fi + fi +} + main() { check_compatibility @@ -378,6 +400,7 @@ main() { setup_symlinks setup_ansible + ensure_shell # Get hostname local hostname