Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User options and fixes #86

Merged
merged 8 commits into from
Mar 6, 2024
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The following commands can be used to upgrade an existing psx-pi-smbshare device
cd ~
wget -O setup.sh https://raw.githubusercontent.com/toolboc/psx-pi-smbshare/master/setup.sh
chmod 755 setup.sh
sudo ./setup.sh
./setup.sh
```

## How it works
Expand Down Expand Up @@ -124,7 +124,7 @@ This configuration will forward all ftp requests made to the host ip of the psx-
IP Address = 192.168.2.2
Subnet Mask = 255.255.255.0
Default Router = 192.168.2.1
Primary DNS = 8.8.8.8
Primary DNS = 1.1.1.1
Secondary DNS = <leave blank or use your home router ip address>

"Automatic" => "Do Not Use" => "Enable"
Expand Down Expand Up @@ -153,7 +153,7 @@ Ensure that the following options are set:
IP address = 192.168.2.2
Mask = 255.255.255.0
Gateway = 192.168.2.1
DNS Server = 8.8.8.8
DNS Server = 1.1.1.1
SMB Server
Address Type = IP
Address = 192.168.2.1
Expand Down
68 changes: 48 additions & 20 deletions automount-usb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,44 @@
# This allows for use of USB & HDD in addition to Micro-SD
# It also creates a new Samba configuration which exposes the last attached USB drive @ //SMBSHARE/<PARTITION>

USER=`whoami`

# Update packages
sudo apt-get update

# Install NTFS Read/Write Support
sudo apt-get install -y ntfs-3g
# Install NTFS Read/Write Support and udisks2
sudo apt-get install -y ntfs-3g udisks2

# Add user to disk group
sudo usermod -a -G disk ${USER}

# Create polkit rule
sudo mkdir -p /etc/polkit-1/rules.d/
sudo mkdir -p /etc/polkit-1/localauthority/50-local.d/

# For polkit > 105
sudo cat <<'EOF' | sudo tee /etc/polkit-1/rules.d/10-udisks2.rules
// Allow udisks2 to mount devices without authentication
// for users in the "disk" group.
polkit.addRule(function(action, subject) {
if ((action.id == "org.freedesktop.udisks2.filesystem-mount-system" ||
action.id == "org.freedesktop.udisks2.filesystem-mount" ||
action.id == "org.freedesktop.udisks2.filesystem-mount-other-seat") &&
subject.isInGroup("disk")) {
return polkit.Result.YES;
}
});
EOF

# Install pmount with ExFAT support
sudo apt-get install -y exfat-fuse exfat-utils autoconf intltool libtool libtool-bin libglib2.0-dev libblkid-dev
cd ~
git clone https://github.com/stigi/pmount-exfat.git
cd pmount-exfat
./autogen.sh
make
sudo make install prefix=usr
sudo sed -i 's/not_physically_logged_allow = no/not_physically_logged_allow = yes/' /etc/pmount.conf
# For polkit <= 105
sudo cat <<'EOF' | sudo tee /etc/polkit-1/localauthority/50-local.d/10-udisks2.pkla
[Authorize mounting of devices for group disk]
Identity=unix-group:disk
Action=org.freedesktop.udisks2.filesystem-mount-system;org.freedesktop.udisks2.filesystem-mount;org.freedesktop.udisks2.filesystem-mount-other-seat
ResultAny=yes
ResultInactive=yes
ResultActive=yes
EOF

# Create udev rule
sudo cat <<'EOF' | sudo tee /etc/udev/rules.d/usbstick.rules
Expand All @@ -41,7 +64,7 @@ After=dev-%i.device
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/automount.sh %I
ExecStop=/usr/bin/pumount /dev/%I
ExecStop=/usr/bin/udisksctl unmount -b /dev/%I
EOF

sudo cat <<'EOF' | sudo tee /lib/systemd/system/[email protected]
Expand All @@ -60,17 +83,20 @@ sudo cat <<'EOF' | sudo tee /usr/local/bin/automount.sh
#!/bin/bash

PART=$1
UUID=`blkid /dev/${PART} -o value -s UUID`
FS_LABEL=`lsblk -o name,label | grep ${PART} | awk '{print $2}'`

if [ -z ${PART} ]
then
exit
fi

runuser pi -s /bin/bash -c "/usr/bin/pmount --umask 000 --noatime -w --sync /dev/${PART} /media/${PART}"
runuser userplaceholder -s /bin/bash -c "udisksctl mount -b /dev/${PART} --no-user-interaction"

pkill ps3netsrv++
/usr/local/bin/ps3netsrv++ -d /media/$PART
if [ -f /usr/local/bin/ps3netsrv++ ]; then
pkill ps3netsrv++
/usr/local/bin/ps3netsrv++ -d /media/userplaceholder/$UUID
fi

#create a new smb share for the mounted drive
cat <<EOS | sudo tee /etc/samba/smb.conf
Expand All @@ -81,27 +107,29 @@ usershare allow guests = yes
map to guest = bad user
allow insecure wide links = yes
[share]
Comment = Pi default shared folder
Path = /media/$PART
Comment = default shared folder
Path = /media/userplaceholder/$UUID
Browseable = yes
Writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
Public = yes
Guest ok = yes
force user = pi
force user = userplaceholder
follow symlinks = yes
wide links = yes
EOS

#if you wish to create a samba user with password you can use the following:
#sudo smbpasswd -a pi
#sudo smbpasswd -a userplaceholder
sudo /etc/init.d/smbd restart
EOF

sudo sed -i "s/userplaceholder/${USER}/g" /usr/local/bin/automount.sh

# Make script executable
sudo chmod +x /usr/local/bin/automount.sh

# Reload udev rules and triggers
sudo udevadm control --reload-rules && udevadm trigger
sudo udevadm control --reload-rules && sudo udevadm trigger
15 changes: 9 additions & 6 deletions samba-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ then
exit
fi

#restart ps3netsrv++
pkill ps3netsrv++
/usr/local/bin/ps3netsrv++ -d /share
#if /usr/local/bin/ps3netsrv++ exists
if [ -f /usr/local/bin/ps3netsrv++ ]; then
#restart ps3netsrv++
pkill ps3netsrv++
/usr/local/bin/ps3netsrv++ -d /share
fi

sudo cat <<'EOF' | sudo tee /etc/samba/smb.conf
[global]
Expand All @@ -20,7 +23,7 @@ usershare allow guests = yes
map to guest = bad user
allow insecure wide links = yes
[share]
Comment = Pi shared folder
Comment = shared folder
Path = /share
Browseable = yes
Writeable = Yes
Expand All @@ -29,11 +32,11 @@ create mask = 0777
directory mask = 0777
Public = yes
Guest ok = yes
force user = pi
force user = userplaceholder
follow symlinks = yes
wide links = yes
EOF

#if you wish to create a samba user with password you can use the following:
#sudo smbpasswd -a pi
#sudo smbpasswd -a userplaceholder
sudo /etc/init.d/smbd restart
85 changes: 60 additions & 25 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,77 @@ if [ $USER = "root" ]; then
exit 1
fi

if whiptail --yesno "Would you like to enable ps3netsrv for PS3 support? (SMB is enabled either way for PS2 support etc.)" 8 55; then
PS3NETSRV=true
else
PS3NETSRV=false
fi

if whiptail --yesno "Would you like to enable XLink Kai?" 8 55; then
XLINKKAI=true
else
XLINKKAI=false
fi

if whiptail --yesno "Would you like to enable wifi access point for a direct wifi connection?" 8 55; then
WIFIACCESSPOINT=true
else
WIFIACCESSPOINT=false
fi

if whiptail --yesno "Would you like to share wifi over ethernet, for devices without wifi? (Ethernet will no longer work for providing the pi an internet connection)" 9 55; then
ETHROUTE=true
else
ETHROUTE=false
fi

# Update packages
sudo apt-get -y update
sudo apt-get -y upgrade

# Ensure basic tools are present
sudo apt-get -y install screen wget git curl coreutils
sudo apt-get -y install screen wget git curl coreutils iptables hostapd

# Install and configure Samba
sudo apt-get install -y samba samba-common-bin
wget https://raw.githubusercontent.com/toolboc/psx-pi-smbshare/master/samba-init.sh -O /home/${USER}/samba-init.sh
sed -i "s/userplaceholder/${USER}/g" /home/${USER}/samba-init.sh
chmod 755 /home/${USER}/samba-init.sh
sudo cp /home/${USER}/samba-init.sh /usr/local/bin
sudo mkdir -m 1777 /share

# Install ps3netsrv
sudo rm /usr/local/bin/ps3netsrv++
sudo apt-get install -y git gcc
git clone https://github.com/dirkvdb/ps3netsrv--.git
cd ps3netsrv--
git submodule update --init
make CXX=g++
sudo cp ps3netsrv++ /usr/local/bin

# Install wifi-to-eth route settings
sudo apt-get install -y dnsmasq
wget https://raw.githubusercontent.com/toolboc/psx-pi-smbshare/master/wifi-to-eth-route.sh -O /home/${USER}/wifi-to-eth-route.sh
# Install ps3netsrv if PS3NETSRV is true
if [ "$PS3NETSRV" = true ]; then
sudo rm /usr/local/bin/ps3netsrv++
sudo apt-get install -y git gcc
git clone https://github.com/dirkvdb/ps3netsrv--.git
cd ps3netsrv--
git submodule update --init
make CXX=g++
sudo cp ps3netsrv++ /usr/local/bin
fi

if [ "$ETHROUTE" = true ]; then
# Install wifi-to-eth route settings
sudo apt-get install -y dnsmasq
wget https://raw.githubusercontent.com/toolboc/psx-pi-smbshare/master/wifi-to-eth-route.sh -O /home/${USER}/wifi-to-eth-route.sh
else
touch /home/${USER}/wifi-to-eth-route.sh
fi
chmod 755 /home/${USER}/wifi-to-eth-route.sh

# Install setup-wifi-access-point settings
sudo apt-get install -y hostapd bridge-utils
wget https://raw.githubusercontent.com/toolboc/psx-pi-smbshare/master/setup-wifi-access-point.sh -O /home/${USER}/setup-wifi-access-point.sh
if [ "$WIFIACCESSPOINT" = true ]; then
# Install setup-wifi-access-point settings
sudo apt-get install -y hostapd bridge-utils
wget https://raw.githubusercontent.com/toolboc/psx-pi-smbshare/master/setup-wifi-access-point.sh -O /home/${USER}/setup-wifi-access-point.sh
else
touch /home/${USER}/setup-wifi-access-point.sh
fi
chmod 755 /home/${USER}/setup-wifi-access-point.sh

# Install XLink Kai if XLINKKAI is true
if [ "$XLINKKAI" = true ]; then

# Remove old XLink Kai Repo if present
sudo rm -rf /etc/apt/sources.list.d/teamxlink.list

Expand All @@ -81,23 +119,20 @@ while true; do
sleep 5
done
EOF
else
touch /home/${USER}/launchkai.sh

#End of XLink Kai install
fi
chmod 755 /home/${USER}/launchkai.sh

# Install USB automount settings
wget https://raw.githubusercontent.com/toolboc/psx-pi-smbshare/master/automount-usb.sh -O /home/${USER}/automount-usb.sh
chmod 755 /home/${USER}/automount-usb.sh
sudo /home/${USER}/automount-usb.sh
/home/${USER}/automount-usb.sh

# Set samba-init + ps3netsrv, wifi-to-eth-route, setup-wifi-access-point, and XLink Kai to run on startup
{ echo -e "@reboot sudo bash /usr/local/bin/samba-init.sh\n@reboot sudo bash /home/${USER}/wifi-to-eth-route.sh && sudo bash /home/${USER}/setup-wifi-access-point.sh\n@reboot bash /home/${USER}/launchkai.sh"; } | crontab -u pi -

# Start services
sudo /usr/local/bin/samba-init.sh
sudo /home/${USER}/wifi-to-eth-route.sh
sudo /home/${USER}/setup-wifi-access-point.sh
ps3netsrv++ -d /share/
screen -dmS kailauncher /home/${USER}/launchkai.sh
{ echo -e "@reboot sudo bash /usr/local/bin/samba-init.sh\n@reboot sudo bash /home/${USER}/wifi-to-eth-route.sh && sudo bash /home/${USER}/setup-wifi-access-point.sh\n@reboot bash /home/${USER}/launchkai.sh"; } | crontab -u ${USER} -

# Not a bad idea to reboot
sudo reboot
2 changes: 1 addition & 1 deletion wifi-to-eth-route.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sudo rm -rf /etc/dnsmasq.d/*

echo -e "interface=$eth\n\
bind-dynamic\n\
server=8.8.8.8\n\
server=1.1.1.1\n\
domain-needed\n\
bogus-priv\n\
dhcp-range=$dhcp_range_start,$dhcp_range_end,$dhcp_time" > /etc/dnsmasq.d/custom-dnsmasq.conf
Expand Down