From 2d04cb04d411b8a0a9800d6f9b471c41829b4a9f Mon Sep 17 00:00:00 2001 From: DaanSelen Date: Wed, 11 Feb 2026 16:58:47 +0100 Subject: [PATCH] feat: add system usb disablement --- .gitignore | 1 - bin/disable-usb.sh | 16 +++++++++ manage.sh => bin/manage.sh | 0 build.sh | 25 ++++++++++++++- dyn-com-install.sh => compile-install.sh | 41 ++++++++++++++++++++++-- demo/demo.go | 20 ++++++++++++ install.sh | 38 +++++++++++++++++++++- service-files/disable-usb.service | 12 +++++++ 8 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 bin/disable-usb.sh rename manage.sh => bin/manage.sh (100%) rename dyn-com-install.sh => compile-install.sh (68%) create mode 100644 demo/demo.go create mode 100644 service-files/disable-usb.service diff --git a/.gitignore b/.gitignore index 74307cc..f4e5054 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore # # Binaries for programs and plugins -* !*.* *.exe *.exe~ diff --git a/bin/disable-usb.sh b/bin/disable-usb.sh new file mode 100644 index 0000000..e65f4e0 --- /dev/null +++ b/bin/disable-usb.sh @@ -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 \ No newline at end of file diff --git a/manage.sh b/bin/manage.sh similarity index 100% rename from manage.sh rename to bin/manage.sh diff --git a/build.sh b/build.sh index 84c84df..39abae9 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,25 @@ #!/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 \ No newline at end of file diff --git a/dyn-com-install.sh b/compile-install.sh similarity index 68% rename from dyn-com-install.sh rename to compile-install.sh index 710c5b9..a657fac 100755 --- a/dyn-com-install.sh +++ b/compile-install.sh @@ -35,9 +35,17 @@ fi cat > /home/\${userland_name}/.config/systemd/user/presentation.service << EOF EOF +# ABOVE AS WELL +# COMPILE presentation.service USERLAND SERVICE INTO INSTALL FILE! +# + cat ./service-files/presentation.service >> ./$install_file echo -e "\nEOF\n" >> ./$install_file +# +# COMPILE video.service USERLAND SERVICE INTO INSTALL FILE! +# + cat >> ./$install_file << EOF # THIS MUST BE THE SAME AS \$REPO/service-files/video.service cat > /home/\${userland_name}/.config/systemd/user/video.service << EOF @@ -46,15 +54,44 @@ EOF cat ./service-files/video.service >> ./$install_file echo -e "\nEOF\n" >> ./$install_file +# +# COMPILE disable-usb.service SYSTEM SERVICE INTO INSTALL FILE! +# + 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 EOF # 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 +# +# 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 echo "alias userjournal='journalctl --user-unit'" /home/\${userland_name}/.bashrc diff --git a/demo/demo.go b/demo/demo.go new file mode 100644 index 0000000..2fbf9ca --- /dev/null +++ b/demo/demo.go @@ -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() +} diff --git a/install.sh b/install.sh index 55dc2c1..7fd7ec2 100644 --- a/install.sh +++ b/install.sh @@ -65,7 +65,23 @@ RestartSec=2 WantedBy=default.target 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 #!/bin/bash # @@ -213,6 +229,26 @@ fi exit 0 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 chmod +x /opt/raspscreen/bin/manage.sh diff --git a/service-files/disable-usb.service b/service-files/disable-usb.service new file mode 100644 index 0000000..026f930 --- /dev/null +++ b/service-files/disable-usb.service @@ -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 \ No newline at end of file