/ scripts / test-install-detection.sh
test-install-detection.sh
 1  #!/bin/bash
 2  
 3  # Test Installation Detection Script
 4  # Shows how the Makefile installation variables work
 5  
 6  echo "KeepSync Installation Detection Test"
 7  echo "=================================="
 8  echo
 9  
10  # Function to show installation variables for a specific user
11  show_install_vars() {
12      local user_type="$1"
13      local uid="$2"
14      
15      echo "📋 $user_type Installation Variables:"
16      echo "   User ID: $uid"
17      
18      if [ "$uid" = "0" ]; then
19          # System installation (root/sudo)
20          echo "   INSTALL_DIR: /usr/local/bin"
21          echo "   SERVICE_DIR: /etc/systemd/system"
22          echo "   CONFIG_DIR: /etc/keepsync"
23          echo "   DATA_DIR: /var/lib/keepsync"
24          echo "   INSTALL_TYPE: system"
25          echo "   TPM Access: Configures udev rules for hardware TPM"
26          echo "   Service Management: systemctl (system-wide)"
27      else
28          # User installation (regular user)
29          echo "   INSTALL_DIR: $HOME/.local/bin"
30          echo "   SERVICE_DIR: $HOME/.config/systemd/user"
31          echo "   CONFIG_DIR: $HOME/.config/keepsync"
32          echo "   DATA_DIR: $HOME/.local/share/keepsync"
33          echo "   INSTALL_TYPE: user"
34          echo "   TPM Access: Uses simulator or user-accessible TPM"
35          echo "   Service Management: systemctl --user"
36      fi
37      echo
38  }
39  
40  # Show current user context
41  echo "🔍 Current User Context:"
42  echo "   User: $(whoami)"
43  echo "   UID: $(id -u)"
44  echo "   Groups: $(groups)"
45  echo
46  
47  # Check TPM availability
48  echo "🔧 TPM Hardware Detection:"
49  if [ -e /dev/tpm0 ]; then
50      echo "   ✅ /dev/tpm0 found (standard TPM device)"
51  else
52      echo "   ❌ /dev/tpm0 not found"
53  fi
54  
55  if [ -e /dev/tpmrm0 ]; then
56      echo "   ✅ /dev/tpmrm0 found (TPM resource manager - preferred)"
57  else
58      echo "   ❌ /dev/tpmrm0 not found"
59  fi
60  
61  if getent group tss > /dev/null 2>&1; then
62      echo "   ✅ 'tss' group exists for TPM access"
63      if groups | grep -q tss; then
64          echo "   ✅ Current user is in 'tss' group"
65      else
66          echo "   ❌ Current user is NOT in 'tss' group"
67      fi
68  else
69      echo "   ❌ 'tss' group not found"
70  fi
71  echo
72  
73  # Show installation types
74  show_install_vars "Regular User" "$(id -u)"
75  show_install_vars "Root/Sudo User" "0"
76  
77  echo "📖 Installation Commands:"
78  echo "   Regular User:  make install"
79  echo "   System-wide:   sudo make install"
80  echo "   Uninstall:     make uninstall (or sudo make uninstall)"
81  echo
82  
83  echo "🔒 Security Features:"
84  echo "   • Hardware TPM support when available"
85  echo "   • Graceful fallback to simulator mode"
86  echo "   • User-space installation doesn't require privileges"
87  echo "   • System installation configures TPM access"
88  echo "   • Quantum-resistant encryption works in both modes"
89  echo
90  
91  echo "✅ Test complete! The Makefile will automatically detect"
92  echo "   your privileges and configure the appropriate installation."