7-services 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env bash
  2. # NAME: Enable and configure system services
  3. set -euo pipefail
  4. # Source common functions
  5. source "$(dirname "$0")/../common.sh" || {
  6. echo "[ERROR] Could not source common.sh" >&2
  7. exit 1
  8. }
  9. enable_networking_services() {
  10. log_info "Enabling networking services"
  11. sudo systemctl enable --now NetworkManager.service
  12. sudo systemctl enable --now bluetooth.service
  13. sudo systemctl enable --now sshd.service
  14. }
  15. enable_audio_services() {
  16. log_info "Enabling audio services"
  17. systemctl --user enable --now pipewire.service
  18. systemctl --user enable --now pipewire-pulse.service
  19. systemctl --user enable --now wireplumber.service
  20. }
  21. enable_printing_services() {
  22. log_info "Enabling printing services"
  23. sudo systemctl enable --now cups.service
  24. }
  25. configure_time_locale() {
  26. log_info "Configuring time and locale services"
  27. if ! grep -q "en_US.UTF-8 UTF-8" /etc/locale.gen; then
  28. echo "en_US.UTF-8 UTF-8" | sudo tee -a /etc/locale.gen
  29. sudo locale-gen
  30. fi
  31. echo "LANG=en_US.UTF-8" | sudo tee /etc/locale.conf
  32. log_info "System locale set to en_US.UTF-8"
  33. sudo timedatectl set-timezone America/Montevideo
  34. sudo timedatectl set-ntp true
  35. sudo systemctl enable --now systemd-timesyncd.service
  36. sudo systemctl enable --now cronie.service
  37. }
  38. enable_security_services() {
  39. log_info "Enabling security services"
  40. sudo systemctl enable --now ufw.service
  41. sudo ufw --force enable
  42. sudo ufw default deny incoming
  43. sudo ufw default allow outgoing
  44. }
  45. enable_backup_services() {
  46. log_info "Enabling backup services"
  47. if findmnt / -t btrfs &>/dev/null; then
  48. sudo systemctl enable --now snapper-timeline.timer
  49. sudo systemctl enable --now snapper-cleanup.timer
  50. log_info "Snapper enabled (BTRFS detected)"
  51. else
  52. log_info "Skipping Snapper (no BTRFS detected)"
  53. fi
  54. }
  55. enable_power_management() {
  56. log_info "Enabling power management"
  57. sudo systemctl enable --now power-profiles-daemon.service
  58. }
  59. enable_system_optimization() {
  60. log_info "Enabling system optimization"
  61. sudo systemctl enable --now haveged.service
  62. sudo systemctl enable --now plocate-updatedb.timer
  63. sudo systemctl enable --now syncthing@forbi.service
  64. }
  65. main() {
  66. init_script
  67. enable_networking_services
  68. enable_audio_services
  69. enable_printing_services
  70. configure_time_locale
  71. enable_security_services
  72. enable_backup_services
  73. enable_power_management
  74. enable_system_optimization
  75. finish_script 0
  76. }
  77. main "$@"