diff options
Diffstat (limited to 'lazy-installer.sh')
-rw-r--r-- | lazy-installer.sh | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/lazy-installer.sh b/lazy-installer.sh new file mode 100644 index 0000000..6e7276c --- /dev/null +++ b/lazy-installer.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +# Function to check if running as root +check_root() { + if [ "$(id -u)" -ne 0; then + echo "Please run this script as root." + echo "To switch to root, use: su" + echo "Then navigate to the home directory and clone the repository:" + echo "cd ~" + echo "git clone https://git.teleco.ch/crt/basic-kiosk.git/" + echo "Run this script again using: bash basic-kiosk/lazy-installer.sh" + exit 1 + fi +} + +# Function to check if /sbin paths are in root's bash profile +check_sbin_paths() { + if ! grep -q '/sbin' ~/.bashrc; then + echo 'export PATH=$PATH:/sbin:/usr/sbin' >> ~/.bashrc + echo 'export PATH=$PATH:/sbin:/usr/sbin' >> ~/.profile + echo "Added /sbin paths to root's bash profile." + fi + export PATH=$PATH:/sbin:/usr/sbin +} + +# Function to install basic packages +install_basics() { + apt update && apt upgrade -y + apt install sudo dialog git htop tmux screen screenfetch -y +} + +# Function to check if kiosk user exists, if not create it +check_kiosk_user() { + if ! id -u kiosk > /dev/null 2>&1; then + read -p "Enter password for kiosk user: " kiosk_password + useradd -m -s /bin/bash kiosk + echo "kiosk:$kiosk_password" | chpasswd + echo "Created kiosk user." + fi + if ! groups kiosk | grep -q "\bsudo\b"; then + usermod -aG sudo kiosk + echo "Added kiosk user to sudo group." + fi +} + +# Function to clone the repository for root user +clone_repo_for_root() { + if [ ! -d ~/basic-kiosk ]; then + echo "Cloning the repository to the home directory..." + if ! git clone https://git.teleco.ch/crt/basic-kiosk.git/ ~/basic-kiosk; then + read -p "Git clone failed. Do you want to try copying the folder instead? (y/n): " choice + if [ "$choice" = "y" ]; then + cp -r "$(dirname "$0")" ~/basic-kiosk + echo "Copied the folder to the home directory." + else + echo "Please clone the repository manually and run the script again." + exit 1 + fi + fi + fi +} + +# Function to clone the repository for kiosk user +clone_repo_for_kiosk() { + if ! sudo -u kiosk bash -c "[ -d ~/basic-kiosk ]"; then + echo "Cloning the repository to the kiosk user's home directory..." + if ! sudo -u kiosk bash -c "git clone https://git.teleco.ch/crt/basic-kiosk.git/ ~/basic-kiosk"; then + read -p "Git clone failed. Do you want to try copying the folder instead? (y/n): " choice + if [ "$choice" = "y" ]; then + sudo -u kiosk bash -c "cp -r $(dirname "$0") ~/basic-kiosk" + sudo chown -R kiosk:kiosk /home/kiosk/basic-kiosk + echo "Copied the folder to the kiosk user's home directory." + else + echo "Please clone the repository manually and run the script again." + exit 1 + fi + fi + fi +} + +# Function to run the installer as kiosk user +run_installer_as_kiosk() { + sudo -u kiosk bash -c "cd ~/basic-kiosk && bash installer.sh" +} + +# Main script execution +check_root +check_sbin_paths +clone_repo_for_root +install_basics +check_kiosk_user +clone_repo_for_kiosk +run_installer_as_kiosk |