-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathscript.sh
169 lines (141 loc) · 5.4 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
RED="31"
GREEN="32"
BOLDGREEN="\e[1;${GREEN}m"
ITALICRED="\e[3;${RED}m"
ENDCOLOR="\e[0m"
if [ "$1" = "gui" ]; then
# Script is running with a GUI argument (icon)
if zenity --question --width=400 --height=100 --text="This script will install Samba server on your system. Did you change the password via passwd?"; then
# User answered "yes" or "Y" or "y"
password=$(zenity --password --title="Enter your password")
echo "$password" | sudo -S echo "Continuing with Samba server installation..."
else
# User answered "no" or "N" or "n"
zenity --error --width=400 --height=100 --text="This script requires your password to work correctly. Please change your password via passwd and try again."
exit 1
fi
else
# Script is running without a GUI argument (console)
echo "WARNING: This script will install Samba server on your system."
read -p "Did you change the password via passwd? [Y/N] " password_choice
case "$password_choice" in
y|Y ) # User answered "yes" or "Y" or "y"
read -s -p "Please enter your password: " password
echo "$password" | sudo -S echo "Continuing with Samba server installation..." ;;
n|N ) # User answered "no" or "N" or "n"
echo "This script requires your password to work correctly. Please change your password via passwd and try again."
exit 1 ;;
* ) # User provided an invalid choice
echo "Invalid choice, aborting script." && exit 1 ;;
esac
fi
# Check if "deck" user's password has been changed
if [ "$(sudo grep '^deck:' /etc/shadow | cut -d':' -f2)" = "*" ] || [ "$(sudo grep '^deck:' /etc/shadow | cut -d':' -f2)" = "!" ]; then
# Prompt user to change "deck" user's password
echo "It looks like you haven't changed the password for the 'deck' user yet."
read -p "Would you like to change it now? (y/n) " choice
if [ "$choice" = "y" ]; then
sudo passwd deck
fi
fi
# Disable steamos-readonly
echo "Disabling steamos-readonly..."
sudo steamos-readonly disable
# Edit pacman.conf file
echo "Editing pacman.conf file..."
sudo sed -i '/^SigLevel[[:space:]]*=[[:space:]]*Required DatabaseOptional/s/^/#/' /etc/pacman.conf
sudo sed -i '/^#SigLevel[[:space:]]*=[[:space:]]*Required DatabaseOptional/a\SigLevel = TrustAll' /etc/pacman.conf
# Initialize pacman keys
echo "Initializing pacman keys..."
sudo pacman-key --init
# Populate pacman keys
echo "Populating pacman keys..."
sudo pacman-key --populate archlinux
# Install Samba
echo "Installing samba..."
sudo pacman -Sy --noconfirm samba
# Initialize Samba configuration after installed
echo "Initializing new smb.conf file..."
sudo tee /etc/samba/smb.conf > /dev/null <<EOF
[global]
netbios name = steamdeck
EOF
# Function to add a new share to smb.conf
add_smb_share() {
echo "Adding share for $1..."
sudo tee -a /etc/samba/smb.conf > /dev/null <<EOF
[$2]
comment = $2 directory
path = $1
browseable = yes
read only = no
create mask = 0777
directory mask = 0777
force user = deck
force group = deck
EOF
}
# Handle multiple directory inputs
while true; do
echo "Enter the path of the directory you want to share, or press ENTER to share the entire /home directory:"
read -p "Path: " custom_path
# default to /home/
if [[ -z "$custom_path" ]]; then
custom_path="/home/"
share_name="home"
add_smb_share "$custom_path" "$share_name"
echo "No path entered. Defaulting to share the entire /home directory."
elif [[ -d "$custom_path" ]]; then
share_name=$(basename "$custom_path")
# create new share
add_smb_share "$custom_path" "$share_name"
echo "Directory added: $custom_path"
else
echo "The path '$custom_path' does not exist or is not a directory. Please check the path and try again."
fi
read -p "Would you like to add another directory? (Y/n): " add_more
if [[ $add_more =~ ^[Nn] ]]; then
break
fi
done
# Confirm sharing setup
while true; do
read -p "Are you sure you want to proceed with sharing directories? (y/n): " confirmation
case "$confirmation" in
[Yy] )
echo "Proceeding with sharing setup..."
break ;;
[Nn] )
echo "Setup aborted by user."
exit 1 ;;
* )
echo "Invalid input. Please enter 'Y' for Yes or 'N' for No." ;;
esac
done
echo "Adding 'deck' user to samba user database..."
if [ "$1" = "gui" ]; then
password=$(zenity --password --title "Set Samba Password" --width=400)
(echo "$password"; echo "$password") | sudo smbpasswd -s -a deck
else
sudo smbpasswd -a deck
fi
# Enable and start smb service
echo "Enabling and starting smb service..."
sudo systemctl enable smb.service
sudo systemctl start smb.service
firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload
# Restart smb service
echo "Restarting smb service..."
sudo systemctl restart smb.service
# re-enable the readonly filesystem
sudo steamos-readonly enable
echo "Filesystem now read-only"
# Final confirmation
if [ "$1" = "gui" ]; then
zenity --info --width=400 --height=100 --text="Samba server set up successfully! You can now access the shared directories on your Steam Deck from any device on your local network."
else
echo -e "${BOLDGREEN}Samba server set up successfully!${ENDCOLOR} You can now access the shared directories on your Steam Deck from any device on your local network."
read -p "Press Enter to continue..."
fi