Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0aedf86c35 | |||
| 931c7119f5 | |||
| e1b1610598 | |||
| 4c2912ce1d |
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@ -26,7 +26,7 @@ jobs:
|
|||||||
run: sudo apt update && sudo apt install -y libusb-1.0-0-dev
|
run: sudo apt update && sudo apt install -y libusb-1.0-0-dev
|
||||||
|
|
||||||
- name: Build Release
|
- name: Build Release
|
||||||
run: go build -v -ldflags "-X main.gitVersion=${{ github.ref_name }}" ./...
|
run: go build -v -o go-bsb-cams-${{ github.ref_name }} -ldflags "-X main.gitVersion=${{ github.ref_name }}" ./...
|
||||||
if: github.ref_type == 'tag'
|
if: github.ref_type == 'tag'
|
||||||
|
|
||||||
- name: Build Non-Release
|
- name: Build Non-Release
|
||||||
@ -37,4 +37,4 @@ jobs:
|
|||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
if: github.ref_type == 'tag'
|
if: github.ref_type == 'tag'
|
||||||
with:
|
with:
|
||||||
files: go-bsb-cams
|
files: go-bsb-cams-v*
|
||||||
|
|||||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1761236834,
|
||||||
|
"narHash": "sha256-+pthv6hrL5VLW2UqPdISGuLiUZ6SnAXdd2DdUE+fV2Q=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "d5faa84122bc0a1fd5d378492efce4e289f8eac1",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
48
flake.nix
Normal file
48
flake.nix
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
|
||||||
|
outputs =
|
||||||
|
{ self
|
||||||
|
, nixpkgs
|
||||||
|
, flake-utils
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages."${system}";
|
||||||
|
go-bsb-cams-pkg = pkgs.buildGoModule {
|
||||||
|
pname = "go-bsb-cams";
|
||||||
|
version = "1.0.1";
|
||||||
|
src = ./.;
|
||||||
|
vendorHash = "sha256-U5B8QJRLSb4S1N0veMPodWfxRZuk/RkCjSd/RAzow78=";
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
libusb1
|
||||||
|
];
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
};
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
packages = {
|
||||||
|
default = go-bsb-cams-pkg;
|
||||||
|
oscgoesbrrr = go-bsb-cams-pkg;
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
libusb1
|
||||||
|
go
|
||||||
|
gcc
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
formatter = pkgs.nixfmt-tree;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
54
main.go
54
main.go
@ -20,10 +20,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const udevrule = `# Bigscreen Bigeye
|
const udevrule = `# Bigscreen Bigeye
|
||||||
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="35bd", ATTRS{idProduct}=="0202", MODE="0660", TAG+="uaccess"
|
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="35bd", ATTRS{idProduct}=="0202", MODE="0660", GROUP="users", TAG+="uaccess"
|
||||||
SUBSYSTEM=="usb", ATTRS{idVendor}=="35bd", ATTRS{idProduct}=="0202", MODE="0660", TAG+="uaccess"
|
SUBSYSTEM=="usb", ATTRS{idVendor}=="35bd", ATTRS{idProduct}=="0202", MODE="0660", GROUP="users", TAG+="uaccess"
|
||||||
`
|
`
|
||||||
const path = "99-bsb-cams.rules"
|
const udevfilename = "99-bsb-cams.rules"
|
||||||
|
|
||||||
func getdevice() (device string) {
|
func getdevice() (device string) {
|
||||||
ctx := gousb.NewContext()
|
ctx := gousb.NewContext()
|
||||||
@ -32,40 +32,42 @@ func getdevice() (device string) {
|
|||||||
user, _ := user.Current()
|
user, _ := user.Current()
|
||||||
if user.Username == "root" && !*sudo {
|
if user.Username == "root" && !*sudo {
|
||||||
log.Print("Running As Root Isnt Reccomended For Safety, Creating A UDEV Rule To Allow Rootless Access ")
|
log.Print("Running As Root Isnt Reccomended For Safety, Creating A UDEV Rule To Allow Rootless Access ")
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(udevfilename); err == nil {
|
||||||
log.Print("File Already Exists")
|
log.Print("File Already Exists")
|
||||||
} else {
|
} else {
|
||||||
err := os.WriteFile(path, []byte(udevrule), 0644)
|
err := os.WriteFile(udevfilename, []byte(udevrule), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not Create File: %v", err)
|
log.Fatalf("Could not Create File: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var response string
|
var response string
|
||||||
log.Printf("Would You Like The UDEV Rule Automatically Moved To Your UDEV DIR? It will be at /usr/lib/udev/rules.d/%v (Y/N)", path)
|
log.Print("Would You Like The UDEV Rule Automatically Moved And Put In Place? (Y/N)")
|
||||||
fmt.Scan(&response)
|
fmt.Scan(&response)
|
||||||
switch strings.ToLower(response) {
|
switch strings.ToLower(response) {
|
||||||
case "yes", "ye", "y":
|
case "yes", "ye", "y":
|
||||||
log.Print("Moving File !!")
|
log.Printf("Would You Like The Rule Moved To The Userspace (/usr/lib/udev/rules.d/%v) Or The Linux OS Space (/etc/udev/rules.d/%v) (Good For Atomic Operating Systems) ", udevfilename)
|
||||||
if _, err := os.Stat(path); err == nil {
|
log.Print("0/Userspace 1/OS Space")
|
||||||
log.Print("File Already Exists, Do You Want To Replace It? (Y/N)")
|
|
||||||
fmt.Scan(&response)
|
fmt.Scan(&response)
|
||||||
switch strings.ToLower(response) {
|
switch strings.ToLower(response) {
|
||||||
case "yes", "ye", "y":
|
case "0", "userspace":
|
||||||
log.Print("Replacing File !")
|
log.Printf("Putting File In /usr/lib/udev/rules.d/%v !!", udevfilename)
|
||||||
case "n", "no":
|
err := os.Rename(udevfilename, "/usr/lib/udev/rules.d/"+udevfilename)
|
||||||
os.Exit(0)
|
|
||||||
default:
|
|
||||||
log.Fatal("Invalid Response")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := os.Rename(path, "/usr/lib/udev/rules.d/"+path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could Not Move File: %v", err)
|
log.Fatalf("Could Not Move File: %v", err)
|
||||||
}
|
}
|
||||||
|
case "1", "os space":
|
||||||
|
log.Printf("Putting File In /etc/udev/rules.d/%v !!", udevfilename)
|
||||||
|
err := os.Rename(udevfilename, "/etc/udev/rules.d/"+udevfilename)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could Not Move File: %v", err)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Fatal("Invalid Response")
|
||||||
|
}
|
||||||
log.Print("Please Reboot Your PC For Changes To Take Effect!!")
|
log.Print("Please Reboot Your PC For Changes To Take Effect!!")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
case "n", "no":
|
case "n", "no":
|
||||||
log.Printf("Please move the file (%v) into your udev rule directory and reboot for it to take effect, or if you REALLLLY want to run this program as sudo append --sudo to your run command", path)
|
log.Printf("Please move the file (%v) into your udev rule directory and reboot for it to take effect, or if you REALLLLY want to run this program as sudo append --sudo to your run command", udevfilename)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
default:
|
default:
|
||||||
log.Fatal("Invalid Answer")
|
log.Fatal("Invalid Answer")
|
||||||
@ -74,20 +76,21 @@ func getdevice() (device string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if err == gousb.ErrorAccess {
|
if err == gousb.ErrorAccess {
|
||||||
log.Print("It looks like the cameras cannot be accessed, udev file being created in this directory")
|
log.Print("It looks like the cameras cannot be accessed, udev file being created in this directory")
|
||||||
log.Printf("Creating UDEV Rule At %v", path)
|
log.Printf("Creating UDEV Rule At %v", udevfilename)
|
||||||
if _, err := os.Stat(path); err == nil {
|
err := os.WriteFile(udevfilename, []byte(udevrule), 0644)
|
||||||
log.Print("File Already Exists")
|
|
||||||
} else {
|
|
||||||
err := os.WriteFile(path, []byte(udevrule), 0644)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not Create File: %v", err)
|
log.Fatalf("Could not Create File: %v", err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
log.Print("File Created ! Please copy to your udev directory, chown to root, and reboot for it to take effect")
|
log.Print("File Created ! Please copy to your udev directory, chown to root, and reboot for it to take effect")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if dev == nil {
|
||||||
|
log.Fatal("Could Not Find Device, Please Make Sure It Is On And Plugged In !")
|
||||||
|
}
|
||||||
defer dev.Close()
|
defer dev.Close()
|
||||||
return fmt.Sprintf("/dev/bus/usb/%03v/%03v", dev.Desc.Bus, dev.Desc.Address)
|
return fmt.Sprintf("/dev/bus/usb/%03v/%03v", dev.Desc.Bus, dev.Desc.Address)
|
||||||
}
|
}
|
||||||
@ -112,6 +115,7 @@ func main() {
|
|||||||
mux.Handle("/stream", stream)
|
mux.Handle("/stream", stream)
|
||||||
log.Print("Server Is Running And Can Be Accessed At: http://localhost:" + strconv.Itoa(*port) + "/stream")
|
log.Print("Server Is Running And Can Be Accessed At: http://localhost:" + strconv.Itoa(*port) + "/stream")
|
||||||
log.Print("Make Sure You Have No Ending / When Inputting The Url Into Baballonia !!!")
|
log.Print("Make Sure You Have No Ending / When Inputting The Url Into Baballonia !!!")
|
||||||
|
log.Print("If You Are Here And Cannot See The Cams, Please Close This Program, Unplug And Replug Your BSB, And Try Again :)")
|
||||||
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), mux))
|
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), mux))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user