Skip to content

Commit c973503

Browse files
committed
linux install script
1 parent a8d8fb1 commit c973503

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/bash
2+
3+
# Function to display help
4+
show_help() {
5+
echo
6+
echo "Phoenix AI Control Setup Script"
7+
echo "-------------------------------"
8+
echo "Usage:"
9+
echo " sudo ./setup_phoenix_ai_control_linux.sh [--managedByEmail <email>] [--allowedUsers <user1,user2,...>]"
10+
echo
11+
echo "Options:"
12+
echo " --managedByEmail Optional. Admin email who manages AI policy."
13+
echo " --allowedUsers Optional. Comma-separated list of Linux usernames allowed to use AI."
14+
echo
15+
echo "Examples:"
16+
echo " sudo ./setup_phoenix_ai_control_linux.sh --managedByEmail [email protected]"
17+
echo " sudo ./setup_phoenix_ai_control_linux.sh --allowedUsers alice,bob"
18+
echo " sudo ./setup_phoenix_ai_control_linux.sh --managedByEmail [email protected] --allowedUsers alice,bob"
19+
echo
20+
echo "Help:"
21+
echo " ./setup_phoenix_ai_control_linux.sh --help"
22+
echo
23+
exit 1
24+
}
25+
26+
# Check if script is run with sudo/as root
27+
if [ "$EUID" -ne 0 ]; then
28+
echo "This script must be run with sudo privileges."
29+
echo "Please run: sudo $0 $*"
30+
exit 1
31+
fi
32+
33+
# Parse arguments
34+
managedByEmail=""
35+
allowedUsers=""
36+
37+
while [[ $# -gt 0 ]]; do
38+
key="$1"
39+
case $key in
40+
--help)
41+
show_help
42+
;;
43+
--managedByEmail)
44+
managedByEmail="$2"
45+
shift 2
46+
;;
47+
--allowedUsers)
48+
allowedUsers="$2"
49+
shift 2
50+
;;
51+
*)
52+
echo "Unknown option: $1"
53+
show_help
54+
;;
55+
esac
56+
done
57+
58+
# Target directory and file
59+
TARGET_DIR="/etc/phoenix-ai-control"
60+
CONFIG_FILE="$TARGET_DIR/config.json"
61+
62+
# Create directory if it doesn't exist
63+
if [ ! -d "$TARGET_DIR" ]; then
64+
mkdir -p "$TARGET_DIR"
65+
fi
66+
67+
# Start creating the JSON content
68+
json_content='{'
69+
json_content+='"disableAI": true'
70+
71+
# Add managedByEmail if specified
72+
if [ -n "$managedByEmail" ]; then
73+
json_content+=',"managedByEmail": "'"$managedByEmail"'"'
74+
fi
75+
76+
# Add allowedUsers if specified
77+
if [ -n "$allowedUsers" ]; then
78+
json_content+=',"allowedUsers": ['
79+
80+
# Convert comma-separated list to array
81+
IFS=',' read -ra USERS <<< "$allowedUsers"
82+
83+
first=true
84+
for user in "${USERS[@]}"; do
85+
if $first; then
86+
json_content+='"'"$user"'"'
87+
first=false
88+
else
89+
json_content+=',"'"$user"'"'
90+
fi
91+
done
92+
93+
json_content+=']'
94+
fi
95+
96+
json_content+='}'
97+
98+
# Write the JSON to the config file
99+
echo "$json_content" > "$CONFIG_FILE"
100+
101+
# Set appropriate permissions: root:root with read access for everyone
102+
chown root:root "$CONFIG_FILE"
103+
chmod 644 "$CONFIG_FILE"
104+
105+
echo
106+
echo "Phoenix AI control config written to:"
107+
echo "$CONFIG_FILE"
108+
echo
109+
echo "Permissions set to allow only root to write, but everyone to read."

0 commit comments

Comments
 (0)