-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add post-install script and update systemd service configurations
- Loading branch information
Showing
4 changed files
with
113 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Check if the script is running on Ubuntu, Debian, or Pop!_OS | ||
if [[ -f /etc/os-release ]]; then | ||
. /etc/os-release | ||
if [[ "$ID" == "ubuntu" || "$ID" == "debian" || "$ID" == "pop" ]]; then | ||
# Create keyrings directory | ||
sudo mkdir -p --mode=0755 /usr/share/keyrings | ||
|
||
# Download and install GPG key | ||
curl -fsSL https://pkg.paretosecurity.com/paretosecurity.gpg | sudo tee /usr/share/keyrings/paretosecurity.gpg >/dev/null | ||
|
||
# Add Pareto repository | ||
echo 'deb [signed-by=/usr/share/keyrings/paretosecurity.gpg] https://pkg.paretosecurity.com/debian stable main' | sudo tee /etc/apt/sources.list.d/pareto.list | ||
|
||
# Check for systemd | ||
if command -v systemctl >/dev/null 2>&1; then | ||
# Create socket unit | ||
cat << 'EOF' | sudo tee /etc/systemd/system/pareto-linux.socket > /dev/null | ||
[Unit] | ||
Description=Socket for pareto-linux | ||
[Socket] | ||
ListenStream=/var/run/pareto-linux.sock | ||
SocketMode=0666 | ||
Accept=no | ||
[Install] | ||
WantedBy=sockets.target | ||
EOF | ||
|
||
# Create service unit | ||
cat << 'EOF' | sudo tee /etc/systemd/system/pareto-linux.service > /dev/null | ||
[Unit] | ||
Description=Service for pareto-linux | ||
Requires=pareto-linux.socket | ||
[Service] | ||
ExecStart=/usr/bin/paretosecurity helper | ||
User=root | ||
Group=root | ||
StandardInput=socket | ||
Type=oneshot | ||
RemainAfterExit=no | ||
[Install] | ||
WantedBy=multi-user.target | ||
EOF | ||
|
||
# Reload systemd and enable socket | ||
systemctl daemon-reload | ||
systemctl enable pareto-linux.socket | ||
systemctl start pareto-linux.socket | ||
fi | ||
fi | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package cmd | |
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
@@ -21,33 +22,73 @@ Accept=no | |
[Install] | ||
WantedBy=sockets.target` | ||
|
||
func getServiceContent() string { | ||
return fmt.Sprintf(`[Unit] | ||
const serviceContent = `[Unit] | ||
Description=Service for pareto-linux | ||
Requires=pareto-linux.socket | ||
[Service] | ||
ExecStart=%s | ||
ExecStart=/usr/bin/paretosecurity helper | ||
User=root | ||
Group=root | ||
StandardInput=socket | ||
Type=oneshot | ||
RemainAfterExit=no | ||
[Install] | ||
WantedBy=multi-user.target`, os.Args[0]) | ||
WantedBy=multi-user.target` | ||
|
||
func runHelper() { | ||
// Get the socket from file descriptor 0 | ||
file := os.NewFile(0, "socket") | ||
listener, err := net.FileListener(file) | ||
if err != nil { | ||
log.Debugf("Failed to create listener: %v\n", err) | ||
os.Exit(1) | ||
} | ||
defer listener.Close() | ||
|
||
log.Info("Server is listening on Unix domain socket...") | ||
|
||
for { | ||
conn, err := listener.Accept() | ||
if err != nil { | ||
log.Debugf("Failed to accept connection: %v\n", err) | ||
continue | ||
} | ||
|
||
handleConnection(conn) | ||
break | ||
} | ||
} | ||
|
||
func handleConnection(conn net.Conn) { | ||
defer conn.Close() | ||
log.Info("Connection received") | ||
|
||
// Handle the request | ||
_, err := conn.Write([]byte("Hello from Go app!\n")) | ||
if err != nil { | ||
log.Debugf("Failed to write to connection: %v\n", err) | ||
} | ||
} | ||
|
||
var helperCmd = &cobra.Command{ | ||
Use: "helper", | ||
Short: "install root helper", | ||
Use: "helper [--install]", | ||
Short: "A root helper", | ||
Long: `A root helper that listens on a Unix domain socket and responds to authenticated requests.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
installSystemdHelper() | ||
installFlag, _ := cmd.Flags().GetBool("install") | ||
if installFlag { | ||
installSystemdHelper() | ||
return | ||
} | ||
runHelper() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(helperCmd) | ||
helperCmd.Flags().Bool("install", false, "install root helper") | ||
} | ||
|
||
func installSystemdHelper() { | ||
|
@@ -68,7 +109,7 @@ func installSystemdHelper() { | |
|
||
// Create service file | ||
servicePath := filepath.Join(systemdPath, "[email protected]") | ||
if err := os.WriteFile(servicePath, []byte(getServiceContent()), 0644); err != nil { | ||
if err := os.WriteFile(servicePath, []byte(serviceContent), 0644); err != nil { | ||
fmt.Printf("Failed to create service file: %v\n", err) | ||
return | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters