feat: add system usb disablement
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,7 +3,6 @@
|
|||||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||||
#
|
#
|
||||||
# Binaries for programs and plugins
|
# Binaries for programs and plugins
|
||||||
*
|
|
||||||
!*.*
|
!*.*
|
||||||
*.exe
|
*.exe
|
||||||
*.exe~
|
*.exe~
|
||||||
|
|||||||
16
bin/disable-usb.sh
Normal file
16
bin/disable-usb.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
for dev in /sys/bus/usb/devices/*; do
|
||||||
|
# Only match main device entries (no colon)
|
||||||
|
if [[ $(basename "$dev") =~ ^[0-9]+-[0-9]+$ ]]; then
|
||||||
|
if [ -e "$dev/driver" ]; then
|
||||||
|
echo "-----"
|
||||||
|
echo "Device path: $dev"
|
||||||
|
dev_name=$(basename "$dev")
|
||||||
|
echo "Unbinding: $dev_name"
|
||||||
|
echo "$dev_name" > /sys/bus/usb/drivers/usb/unbind
|
||||||
|
else
|
||||||
|
echo "Skipping: $dev"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
25
build.sh
25
build.sh
@@ -1,2 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
go build -o RaspScreen src/*.go
|
|
||||||
|
export CGO_ENABLED=1
|
||||||
|
export GOARCH=amd64
|
||||||
|
|
||||||
|
if [[ "$1" == "win" ]]; then
|
||||||
|
export CC=x86_64-w64-mingw32-gcc
|
||||||
|
export CXX=x86_64-w64-mingw32-g++
|
||||||
|
export CGO_LDFLAGS="-static-libgcc -static-libstdc++"
|
||||||
|
export GOOS=windows
|
||||||
|
|
||||||
|
echo "Building Windows AMD64 binaries"
|
||||||
|
go-winres simply --icon ./src/icon.ico --manifest gui
|
||||||
|
mv *.syso ./src
|
||||||
|
go build -o ./raspscreen.exe -ldflags -H=windowsgui ./src
|
||||||
|
elif [[ "$1" == "linux" ]]; then
|
||||||
|
export CC=gcc
|
||||||
|
export CXX=g++
|
||||||
|
export GOOS=linux
|
||||||
|
|
||||||
|
echo "Building Linux AMD64 binaries"
|
||||||
|
go build -o ./raspscreen ./src
|
||||||
|
fi
|
||||||
|
echo "Done"
|
||||||
|
exit 0
|
||||||
@@ -35,9 +35,17 @@ fi
|
|||||||
cat > /home/\${userland_name}/.config/systemd/user/presentation.service << EOF
|
cat > /home/\${userland_name}/.config/systemd/user/presentation.service << EOF
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# ABOVE AS WELL
|
||||||
|
# COMPILE presentation.service USERLAND SERVICE INTO INSTALL FILE!
|
||||||
|
#
|
||||||
|
|
||||||
cat ./service-files/presentation.service >> ./$install_file
|
cat ./service-files/presentation.service >> ./$install_file
|
||||||
echo -e "\nEOF\n" >> ./$install_file
|
echo -e "\nEOF\n" >> ./$install_file
|
||||||
|
|
||||||
|
#
|
||||||
|
# COMPILE video.service USERLAND SERVICE INTO INSTALL FILE!
|
||||||
|
#
|
||||||
|
|
||||||
cat >> ./$install_file << EOF
|
cat >> ./$install_file << EOF
|
||||||
# THIS MUST BE THE SAME AS \$REPO/service-files/video.service
|
# THIS MUST BE THE SAME AS \$REPO/service-files/video.service
|
||||||
cat > /home/\${userland_name}/.config/systemd/user/video.service << EOF
|
cat > /home/\${userland_name}/.config/systemd/user/video.service << EOF
|
||||||
@@ -46,15 +54,44 @@ EOF
|
|||||||
cat ./service-files/video.service >> ./$install_file
|
cat ./service-files/video.service >> ./$install_file
|
||||||
echo -e "\nEOF\n" >> ./$install_file
|
echo -e "\nEOF\n" >> ./$install_file
|
||||||
|
|
||||||
|
#
|
||||||
|
# COMPILE disable-usb.service SYSTEM SERVICE INTO INSTALL FILE!
|
||||||
|
#
|
||||||
|
|
||||||
cat >> ./$install_file << EOF
|
cat >> ./$install_file << EOF
|
||||||
# THIS MUST BE THE AS \$REPO/manage.sh
|
# THIS MUST BE THE SAME AS \$REPO/service-files/disable-usb.service
|
||||||
|
cat > /etc/systemd/system/disable-usb.service << EOF
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat ./service-files/disable-usb.service >> ./$install_file
|
||||||
|
echo -e "\nEOF\n" >> ./$install_file
|
||||||
|
|
||||||
|
#
|
||||||
|
# COMPILE manage.sh SCRIPT INTO INSTALL FILE!
|
||||||
|
#
|
||||||
|
|
||||||
|
cat >> ./$install_file << EOF
|
||||||
|
# THIS MUST BE THE SAME AS \$REPO/bin/manage.sh
|
||||||
cat > /opt/raspscreen/bin/manage.sh << EOF
|
cat > /opt/raspscreen/bin/manage.sh << EOF
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Make sure to prefix all $ with a \
|
# Make sure to prefix all $ with a \
|
||||||
sed 's/\$/\\$/g' ./manage.sh >> "$install_file"
|
sed 's/\$/\\$/g' ./bin/manage.sh >> "$install_file"
|
||||||
echo -e "\nEOF\n" >> ./$install_file
|
echo -e "\nEOF\n" >> ./$install_file
|
||||||
|
|
||||||
|
#
|
||||||
|
# COMPILE disable-usb.sh SCRIPT INTO INSTALL FILE!
|
||||||
|
#
|
||||||
|
|
||||||
|
cat >> ./$install_file << EOF
|
||||||
|
# THIS MUST BE THE SAME AS \$REPO/bin/disable-usb.sh
|
||||||
|
cat > /opt/raspscreen/bin/disable-usb << EOF
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sed 's/\$/\\$/g' ./bin/disable-usb.sh >> "$install_file"
|
||||||
|
echo -e "\nEOF\n" >> ./$install_file
|
||||||
|
|
||||||
|
|
||||||
cat >> ./$install_file << EOF
|
cat >> ./$install_file << EOF
|
||||||
echo "alias userjournal='journalctl --user-unit'" /home/\${userland_name}/.bashrc
|
echo "alias userjournal='journalctl --user-unit'" /home/\${userland_name}/.bashrc
|
||||||
|
|
||||||
20
demo/demo.go
Normal file
20
demo/demo.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
userCtx, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Fatally tried to get user context...")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(userCtx)
|
||||||
|
log.Println(userCtx.Name)
|
||||||
|
log.Println(userCtx.Username)
|
||||||
|
log.Println(userCtx.HomeDir)
|
||||||
|
fmt.Scanln()
|
||||||
|
}
|
||||||
38
install.sh
38
install.sh
@@ -65,7 +65,23 @@ RestartSec=2
|
|||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# THIS MUST BE THE AS $REPO/manage.sh
|
# THIS MUST BE THE SAME AS $REPO/service-files/disable-usb.service
|
||||||
|
cat > /etc/systemd/system/disable-usb.service << EOF
|
||||||
|
[Unit]
|
||||||
|
Description="Systemec RaspScreen USB-Disablement service"
|
||||||
|
After=systemd-udevd.service
|
||||||
|
Wants=systemd-udevd.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/opt/raspscreen
|
||||||
|
ExecStart=/opt/raspscreen/bin/disable-usb.sh
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# THIS MUST BE THE SAME AS $REPO/bin/manage.sh
|
||||||
cat > /opt/raspscreen/bin/manage.sh << EOF
|
cat > /opt/raspscreen/bin/manage.sh << EOF
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
@@ -213,6 +229,26 @@ fi
|
|||||||
exit 0
|
exit 0
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# THIS MUST BE THE SAME AS $REPO/bin/disable-usb.sh
|
||||||
|
cat > /opt/raspscreen/bin/disable-usb << EOF
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
for dev in /sys/bus/usb/devices/*; do
|
||||||
|
# Only match main device entries (no colon)
|
||||||
|
if [[ \$(basename "\$dev") =~ ^[0-9]+-[0-9]+\$ ]]; then
|
||||||
|
if [ -e "\$dev/driver" ]; then
|
||||||
|
echo "-----"
|
||||||
|
echo "Device path: \$dev"
|
||||||
|
dev_name=\$(basename "\$dev")
|
||||||
|
echo "Unbinding: \$dev_name"
|
||||||
|
echo "\$dev_name" > /sys/bus/usb/drivers/usb/unbind
|
||||||
|
else
|
||||||
|
echo "Skipping: \$dev"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
EOF
|
||||||
|
|
||||||
echo "alias userjournal='journalctl --user-unit'" /home/${userland_name}/.bashrc
|
echo "alias userjournal='journalctl --user-unit'" /home/${userland_name}/.bashrc
|
||||||
|
|
||||||
chmod +x /opt/raspscreen/bin/manage.sh
|
chmod +x /opt/raspscreen/bin/manage.sh
|
||||||
|
|||||||
12
service-files/disable-usb.service
Normal file
12
service-files/disable-usb.service
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description="Systemec RaspScreen USB-Disablement service"
|
||||||
|
After=systemd-udevd.service
|
||||||
|
Wants=systemd-udevd.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/opt/raspscreen
|
||||||
|
ExecStart=/opt/raspscreen/bin/disable-usb.sh
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
Reference in New Issue
Block a user