Skip to content

Commit

Permalink
Add Debian configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaillard committed Dec 18, 2023
1 parent 21b734b commit 4acba95
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 42 deletions.
73 changes: 71 additions & 2 deletions .github/workflows/mclip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,30 @@ on: push
permissions:
contents: write
jobs:

# Lint
cppcheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install
run: sudo apt install -y cppcheck
- name: Cppcheck
run: cppcheck ${GITHUB_WORKSPACE}/src/*.c
cpplint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install
run: sudo apt install -y cpplint
- name: Cpplint
run: cpplint ${GITHUB_WORKSPACE}/src/*.c

# Build
build:
needs: [cppcheck, cpplint]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -19,12 +42,58 @@ jobs:
- name: Make
run: make

- name: Upload
- name: Make dist
run: make dist

- name: Upload binary
uses: actions/upload-artifact@v3
with:
name: mclip
name: binary
path: src/mclip

- name: Upload source archive
uses: actions/upload-artifact@v3
with:
name: source-archive
path: mclip-*.tar.gz

# Package - Debian
package-debian:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download source-archive
uses: actions/download-artifact@v3
with:
name: source-archive

- name: Debian package
run: |
sudo apt-get install -y devscripts debhelper
mkdir -p "${RUNNER_TEMP}/debian-packaging"
cp mclip-*.tar.gz "${RUNNER_TEMP}/debian-packaging"
cd "${RUNNER_TEMP}/debian-packaging"
ORIG_TAR_GZ=$(ls mclip-*.gz | sed -E 's/^mclip-([[:digit:]])\.([[:digit:]])\.([[:digit:]])\.tar\.gz$/mclip_\1.\2.\3\.orig\.tar\.gz/g')
mv mclip-*.tar.gz "${ORIG_TAR_GZ}"
tar xf "${ORIG_TAR_GZ}"
cd mclip-*/
cp -R "${GITHUB_WORKSPACE}/debian" .
debuild -us -uc
- name: Upload debian package
uses: actions/upload-artifact@v3
with:
name: debian-package
path: mclip-*.deb

# Release
release:
needs: [package-debian]
runs-on: ubuntu-latest
steps:
- name: Release
uses: cycjimmy/semantic-release-action@v4
env:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,7 @@ Makefile
# Other
########################################################################################################################

# make dist and make distdir
mclip-*
mclip_*
src/mclip
37 changes: 37 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Contributing to mclip

:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:

## Unix philosophy

mclip responds to a very simple need, having a very simple clipboard manager which does not require any "big" dependency (X11, Wayland, etc.).

It adheres to the [Unix philosophy](https://en.wikipedia.org/wiki/Unix_philosophy), it does one thing well and no more.

Maintainers should keep in mind that the tool must stay as simple as possible. If it is it will be easy to maintain it and make it compatible with several operating systems and architectures.

## How to help

mclip must stay a very simple tool to use and maintain, we do not wish to add a lot of new features in it.

As maintainers our goals should be to make it widely used, simple, secure and rock solid.

Here are what you can do to help us improve it.

- Report bugs ;
- Create packages for new Linux distributions ;
- Read the source code to find security problems, provide guidance and solutions to fix them ;
- Write MD files to explain how to use it with other tools (Neovim, Emacs, etc.).

## Useful links

- Autotools
- [Autoconf](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.71/html_node/index.html)
- [GNU Automake](https://www.gnu.org/software/automake/manual/html_node/index.html)
- [Man Pages - The Complete Guide](https://betterprogramming.pub/man-pages-the-complete-guide-800ad93425fe)
- Linux distributions packaging
- [Debian](https://www.debian.org/)
- [Packaging Intro](https://wiki.debian.org/Packaging/Intro)
- [Debian New Maintainer's Guide](https://www.debian.org/doc/manuals/maint-guide/index.en.html)
- [Debian Policy Manual](https://www.debian.org/doc/debian-policy/index.html)
- [PackagingWithGit](https://wiki.debian.org/PackagingWithGit)
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SUBDIRS = src
dist_doc_DATA = README.md
man_MANS = man/$(PACKAGE).1
EXTRA_DIST = $(man_MANS)
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mclip (1.0.0-1) UNRELEASED; urgency=low

* Initial release.

-- Baptiste Gaillard <[email protected]> Sat, 16 Dec 2023 09:00:37 +0100
17 changes: 17 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Source: mclip
Section: utils
Priority: optional
Maintainer: Baptiste Gaillard <[email protected]>
Build-Depends: debhelper-compat (= 13), dh-autoreconf
Standards-Version: 4.5.1
Homepage: https://github.com/bgaillard/mclip
Rules-Requires-Root: no
Vcs-Git: https://github.com/bgaillard/mclip.git
#Vcs-Browser: https://salsa.debian.org/debian/mclip

Package: mclip
Architecture: any
Multi-Arch: foreign
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: mclip (for "Memory CLIPboard") is a very simple clipboard manager which stores its data inside a POSIX
shared memory object.
11 changes: 11 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: mclip
Upstream-Contact: Baptiste Gaillard <[email protected]>
Source: https://github.com/bgaillard/mclip
#
# Please double check copyright with the licensecheck(1) command.

Files:
*
Copyright: 2023 Baptiste Gaillard
License: GPL-3+
12 changes: 12 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
#export DH_VERBOSE = 1
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
dh $@ --with autoreconf

#override_dh_install:
# dh_install --list-missing -X.la -X.pyc -X.pyo
93 changes: 53 additions & 40 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
/**
* Copyright (C) 2023 Baptiste Gaillard
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/

#define _GNU_SOURCE

#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <getopt.h>

static const char SHARED_MEMORY_NAME[] = "/mclip";

Expand All @@ -25,18 +38,18 @@ void in() {
exit(1);
}

char characters[2] = {0};
char characters[128] = {0};

int offset = 0;
int nb_read = 0;
int total_nb_read = 0;

while(fgets(characters, sizeof(characters), stdin) != NULL) {
while (fgets(characters, sizeof(characters), stdin) != NULL) {
nb_read = strlen(characters);
total_nb_read = total_nb_read + nb_read;

// Truncate the file to reserve space in it
if(ftruncate(fd, total_nb_read) == -1) {
if (ftruncate(fd, total_nb_read) == -1) {
fprintf(stderr, "ftruncate() failed\n");
exit(1);
}
Expand All @@ -46,7 +59,7 @@ void in() {
else
addr = mmap(NULL, total_nb_read, PROT_WRITE, MAP_SHARED, fd, 0);

sprintf(addr + offset, "%s", characters);
snprintf(addr + offset, nb_read, "%s", characters);

offset = total_nb_read;
}
Expand Down Expand Up @@ -74,7 +87,8 @@ void out() {

fstat(fd, &st);

// The shared memory is empty when it has just been initialized the first time with 'shm_open()'.
// The shared memory is empty when it has just been initialized the first
// time with 'shm_open()'.
if (st.st_size != 0) {
addr = mmap(NULL, 1024, PROT_READ, MAP_SHARED, fd, 0);

Expand All @@ -84,7 +98,7 @@ void out() {
}
}

printf("%s", (char*) addr);
printf("%s", addr);
}

/**
Expand All @@ -94,8 +108,10 @@ void help() {
printf("Usage: mclip [OPTION]\n\n");
printf("Clipboard which stores its data inside shared memory.\n\n");
printf("\t -h, --help \t show quick summary of options\n");
printf("\t -i, --in \t read text from standard input and write it into the clipboard shared memory (default)\n");
printf("\t -o, --out \t print the content of the clipboard shared memory\n\n");
printf("\t -i, --in \t read text from standard input and write it into "
"the clipboard shared memory (default)\n");
printf("\t -o, --out \t print the content of the clipboard shared "
"memory\n\n");
}

/**
Expand All @@ -104,58 +120,55 @@ void help() {
* @param argc Number of arguments.
* @param argv Array of arguments.
*/
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
int option_help = 0;
int option_in = 0;
int option_out = 0;

int c;
int option_index = 0;

static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"in", no_argument, 0, 'i'},
{"out", no_argument, 0, 'o'},
{0, 0, 0, 0}
};
static struct option long_options[] = {{"help", no_argument, 0, 'h'},
{"in", no_argument, 0, 'i'},
{"out", no_argument, 0, 'o'},
{0, 0, 0, 0}};

while(1) {
while (1) {
c = getopt_long(argc, argv, "hio", long_options, &option_index);

// No more options to read
if (c == -1)
break;

switch(c) {

// --help
case 'h':
option_help = 1;
break;
switch (c) {
// --help
case 'h':
option_help = 1;
break;

// --in
case 'i':
option_in = 1;
break;
// --in
case 'i':
option_in = 1;
break;

// --out
case 'o':
option_out = 1;
break;
// --out
case 'o':
option_out = 1;
break;

// Error encountered (i.e. bad option specified)
case '?':
exit(1);
// Error encountered (i.e. bad option specified)
case '?':
exit(1);
}

}

if (option_help == 1 && (option_in == 1 || option_out == 1)) {
fprintf(stderr, "The '--help' option cannot be provided with the '--in' or '--out' option!\n");
fprintf(stderr, "The '--help' option cannot be provided with the "
"'--in' or '--out' option!\n");
return 1;
} else if (option_help == 0 && option_in == 1 && option_out == 1) {
fprintf(stderr, "The '--in' and '--out' options cannot be specified together!\n");
fprintf(stderr,
"The '--in' and '--out' options cannot be specified together!\n");
return 1;
} else if (optind < argc) {
fprintf(stderr, "Unknown argument speficied '%s'!\n", argv[optind]);
Expand Down

0 comments on commit 4acba95

Please sign in to comment.