Skip to content

Commit 32c79a2

Browse files
committed
Add .gitignore, systemd service, dependencies list, and post-install script; update upload directory in main.go
1 parent 77eccfd commit 32c79a2

7 files changed

Lines changed: 150 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Release Package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
arch: [amd64, arm64]
14+
include:
15+
- arch: amd64
16+
goarch: amd64
17+
deb_arch: amd64
18+
rpm_arch: x86_64
19+
- arch: arm64
20+
goarch: arm64
21+
deb_arch: arm64
22+
rpm_arch: aarch64
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v3
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v4
29+
with:
30+
go-version: '1.20'
31+
32+
- name: Set up Ruby
33+
uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: '3.0'
36+
37+
- name: Install FPM
38+
run: gem install fpm
39+
40+
- name: Get the version
41+
id: get_version
42+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
43+
44+
- name: Build binary for ${{ matrix.arch }}
45+
run: GOARCH=${{ matrix.goarch }} go build -o agent
46+
47+
- name: Make scripts executable
48+
run: chmod +x scripts/postinstall.sh
49+
50+
- name: Package DEB for ${{ matrix.arch }}
51+
run: |
52+
fpm -s dir -t deb -n agent -v ${{ env.VERSION }} \
53+
--architecture ${{ matrix.deb_arch }} \
54+
--description "Remote file opener via REST API" \
55+
--maintainer "Sai Sanjay <saisanjay7660@gmail.com>" \
56+
--depends "apt" \
57+
--after-install scripts/postinstall.sh \
58+
--deb-pre-depends "apt" \
59+
./agent=/usr/local/bin/agent \
60+
./agent.service=/lib/systemd/system/agent.service \
61+
./dependencies.txt=/usr/share/agent/dependencies.txt
62+
63+
- name: Package RPM for ${{ matrix.arch }}
64+
run: |
65+
fpm -s dir -t rpm -n agent -v ${{ env.VERSION }} \
66+
--architecture ${{ matrix.rpm_arch }} \
67+
--description "Remote file opener via REST API" \
68+
--maintainer "Sai Sanjay <saisanjay7660@gmail.com>" \
69+
--depends "yum" \
70+
--after-install scripts/postinstall.sh \
71+
./agent=/usr/local/bin/agent \
72+
./agent.service=/usr/lib/systemd/system/agent.service \
73+
./dependencies.txt=/usr/share/agent/dependencies.txt
74+
75+
- name: Upload artifacts
76+
uses: actions/upload-artifact@v3
77+
with:
78+
name: packages-${{ matrix.arch }}
79+
path: |
80+
agent_${{ env.VERSION }}_${{ matrix.deb_arch }}.deb
81+
agent-${{ env.VERSION }}-1.${{ matrix.rpm_arch }}.rpm
82+
83+
release:
84+
needs: build
85+
runs-on: ubuntu-latest
86+
steps:
87+
- name: Download all artifacts
88+
uses: actions/download-artifact@v3
89+
with:
90+
path: packages
91+
92+
- name: Display structure of downloaded files
93+
run: ls -R packages
94+
95+
- name: Flatten directory structure
96+
run: |
97+
mkdir -p release_files
98+
find packages -type f -name "*.deb" -o -name "*.rpm" | xargs -I {} cp {} release_files/
99+
100+
- name: Create "any" and "noarch" packages
101+
run: |
102+
# For demonstration, create symlinks to the amd64 packages
103+
# In a real scenario, you might need to create truly architecture-independent packages
104+
cd release_files
105+
cp agent_${{ env.VERSION }}_amd64.deb agent_${{ env.VERSION }}_any.deb
106+
cp agent-${{ env.VERSION }}-1.x86_64.rpm agent-${{ env.VERSION }}-1.noarch.rpm
107+
108+
- name: Create Release
109+
uses: softprops/action-gh-release@v1
110+
with:
111+
files: release_files/*
112+
draft: false
113+
prerelease: false
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
agent_*
2+
agent

agent

-24 Bytes
Binary file not shown.

agent.service

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=remote file opener via rest api
3+
After=network.target
4+
5+
[Service]
6+
ExecStart=/usr/local/bin/agent
7+
Restart=on-failure
8+
User=root
9+
Environment=DISPLAY=:0
10+
11+
[Install]
12+
WantedBy=multi-user.target

dependencies.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
okular
2+
gedit
3+
eog
4+
vlc
5+
onlyoffice-desktopeditors
6+
file-roller
7+
xdg-utils

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func init() {
3232
// Set default configuration
3333
config = Config{
3434
Port: "8080",
35-
UploadDirectory: "/tmp/file-opener-uploads",
35+
UploadDirectory: "/tmp/agent-uploads",
3636
FileTypeOpeners: map[string]string{
3737
".pdf": "okular",
3838
".txt": "gedit",

scripts/postinstall.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# Install required applications
3+
apt-get update
4+
apt-get install -y $(cat /usr/share/agent/dependencies.txt)
5+
6+
# Create upload directory
7+
mkdir -p /tmp/agent-uploads
8+
chmod 777 /tmp/agent-uploads
9+
10+
# Reload systemd and enable service
11+
systemctl daemon-reload
12+
systemctl enable agent.service
13+
systemctl start agent.service

0 commit comments

Comments
 (0)