lazy-installer.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # Function to check if running as root
  3. check_root() {
  4. if [ "$(id -u)" -ne 0 ]; then
  5. echo "Please run this script as root."
  6. echo "To switch to root, use: su"
  7. echo "Then navigate to the home directory and clone the repository:"
  8. echo "cd ~"
  9. echo "git clone https://git.teleco.ch/crt/basic-kiosk.git/"
  10. echo "Run this script again using: bash basic-kiosk/lazy-installer.sh"
  11. exit 1
  12. fi
  13. }
  14. # Function to check if /sbin paths are in root's bash profile
  15. check_sbin_paths() {
  16. if ! grep -q '/sbin' ~/.bashrc; then
  17. echo 'export PATH=$PATH:/sbin:/usr/sbin' >> ~/.bashrc
  18. echo 'export PATH=$PATH:/sbin:/usr/sbin' >> ~/.profile
  19. echo "Added /sbin paths to root's bash profile."
  20. fi
  21. export PATH=$PATH:/sbin:/usr/sbin
  22. }
  23. # Function to install basic packages
  24. install_basics() {
  25. apt update && apt upgrade -y
  26. apt install sudo dialog git htop tmux screen screenfetch -y
  27. }
  28. # Function to check if kiosk user exists, if not create it
  29. check_kiosk_user() {
  30. if ! id -u kiosk > /dev/null 2>&1; then
  31. read -p "Enter password for kiosk user: " kiosk_password
  32. useradd -m -s /bin/bash kiosk
  33. echo "kiosk:$kiosk_password" | chpasswd
  34. echo "Created kiosk user."
  35. fi
  36. if ! groups kiosk | grep -q "\bsudo\b"; then
  37. usermod -aG sudo kiosk
  38. echo "Added kiosk user to sudo group."
  39. fi
  40. }
  41. # Function to clone the repository for root user
  42. clone_repo_for_root() {
  43. if [ ! -d ~/basic-kiosk ]; then
  44. echo "Cloning the repository to the home directory..."
  45. if ! git clone https://git.teleco.ch/crt/basic-kiosk.git/ ~/basic-kiosk; then
  46. read -p "Git clone failed. Do you want to try copying the folder instead? (y/n): " choice
  47. if [ "$choice" = "y" ]; then
  48. cp -r "$(dirname "$0")" ~/basic-kiosk
  49. echo "Copied the folder to the home directory."
  50. else
  51. echo "Please clone the repository manually and run the script again."
  52. exit 1
  53. fi
  54. fi
  55. fi
  56. }
  57. # Function to clone the repository for kiosk user
  58. clone_repo_for_kiosk() {
  59. if ! sudo -u kiosk bash -c "[ -d ~/basic-kiosk ]"; then
  60. echo "Cloning the repository to the kiosk user's home directory..."
  61. if ! sudo -u kiosk bash -c "git clone https://git.teleco.ch/crt/basic-kiosk.git/ ~/basic-kiosk"; then
  62. read -p "Git clone failed. Do you want to try copying the folder instead? (y/n): " choice
  63. if [ "$choice" = "y" ]; then
  64. sudo -u kiosk bash -c "cp -r $(dirname "$0") ~/basic-kiosk"
  65. sudo chown -R kiosk:kiosk /home/kiosk/basic-kiosk
  66. echo "Copied the folder to the kiosk user's home directory."
  67. else
  68. echo "Please clone the repository manually and run the script again."
  69. exit 1
  70. fi
  71. fi
  72. fi
  73. }
  74. # Function to run the installer as kiosk user
  75. run_installer_as_kiosk() {
  76. sudo -u kiosk bash -c "cd ~/basic-kiosk && bash installer.sh"
  77. }
  78. # Main script execution
  79. check_root
  80. check_sbin_paths
  81. clone_repo_for_root
  82. install_basics
  83. check_kiosk_user
  84. clone_repo_for_kiosk
  85. run_installer_as_kiosk