Thursday, March 23, 2023

Creating a tiny new GhostBSD package for sharing with others

 Creating a tiny new GhostBSD / FreeBSD package for sharing with others, GURUs Generate_User_Report_for_Upload

 Here is an example of creating a FreeBSD style package, read some URLs

 
Insert this file to start your journey.  Copy and paste into tmp_stage.sh ;  chmod u+x tmp_stage.sh ;  sh ./tmp_stage.sh
 
 
#!/bin/sh

STAGEDIR=/tmp/stage
rm -rf ${STAGEDIR}
mkdir -p ${STAGEDIR}

cat >> ${STAGEDIR}/+PRE_DEINSTALL <<EOF
# careful here, this may clobber your system
echo "Resetting root shell"
pw usermod -n root -s /bin/csh
EOF

cat >> ${STAGEDIR}/+POST_INSTALL <<EOF
# careful here, this may clobber your system
echo "Registering root shell"
pw usermod -n root -s /bin/sh
EOF


https://github.com/freebsd/pkg  Github has some good reading too.
 
https://stackoverflow.com/questions/4602977/freebsd-pkg-create-how-to Kind of Sparse as an example.  May be of future use


https://forums.freebsd.org/threads/where-does-make-package-put-the-pkg-file.73535/  Helpful example of creating a package   "pkg help create"

https://forums.freebsd.org/threads/creating-a-pkg-with-pkg-create.88358/  FreeBSD forum post that I followed and put a link to this blog.



https://docs.freebsd.org/en/books/porters-handbook/plist/#plist-keywords  Yes the learning curve is too damned steep to accomplish a very simple task of creating a binary package from these 7 files:

    ./share/applications/generate_user_report.desktop #Desktop application file
    ./lib/guru/Makefile #Makefile
    ./lib/guru/README.md #Standard Readme file written in MarkDown language
    ./lib/guru/Report_fred-ghostbsd-pc1_2020-04-05_example.txt #Example Report.txt File created from User_Report.sh file
    ./lib/guru/User_Report.py #Python script file to create the GUI interface with a couple buttons
    ./lib/guru/User_Report.sh #Shell Script file
    ./lib/guru/applets-screenshooter.png #Icon file



No creation of these files from a Makefile is needed.  I included a sample Makefile.

Freebsd pkg #manifest
Best simple use of "pkg create" tool Best description on the web
Packaging setup, usage, and explanation
How to make a binary package, using FreeBSD tools
Quick Porting example from Porters Handbook

https://forums.freebsd.org/threads/creating-a-pkg-with-pkg-create.88358/#post-602161 Pat Maddox March 2023 help with pkg creation
Section 3.2..2 porting pkg plist
How to create a simple package?  read up here http://lastsummer.de/creating-custom-packages-on-freebsd/
 
mkdir /tmp/stage       # create a temporary staging directory
STAGEDIR=/tmp/stage
echo ${STAGEDIR}
cd ${STAGEDIR}
 
# will use  a ${PRELIST} directory and maybe use a ${WORKDIR}  In this example, WORKDIR is not used.

"plist" file contents
$ cat plist
/usr/local/etc/my.conf
./share/applications/generate_user_report.desktop
./lib/generate_user_report/Makefile
./lib/generate_user_report/README.md
./lib/generate_user_report/Report_fred-ghostbsd-pc1_2020-04-05_example.txt
./lib/generate_user_report/User_Report.py
./lib/generate_user_report/User_Report.sh
./lib/generate_user_report/applets-screenshooter.png

"+MANIFEST" file contents
$ cat /tmp/stage/+MANIFEST
name: generate_user_report
version: "1.0_1"
origin: sysutils/generate_user_report
comment: "Generate User Report for Upload"
desc: "GURU documents all your configuration files for examination and comparison and sharing with others"
maintainer: fredfinster@gmail.com
www: https://github.com/wb7odyfred/Ghostbsd_apps/generate_user_report
prefix: /usr/local
deps: {
portlint: { version: "2.20.0", origin: ports-mgmt/portlint }
poudriere: { version: "3.3.7_1", origin: ports-mgmt/poudriere }
}
files: {
}
scripts: {
install: "#!/bin/sh\n\ncase \"$2\" in\n PRE-INSTALL)\n if [ ! -d ~/Desktop ] ; then\n mkdir -p ~/Desktop\n fi\n ;;\n POST-INSTALL)\n cp /usr/local/share/applications/generate_user_report.desktop ~/Desktop/generate_user_report.desktop\n cp /usr/local/lib/generate_user_report/Report_fred-ghostbsd-pc1_2020-04-05_example.txt ~/Desktop/Report_fred-ghostbsd-pc1_2020-04-05_example.txt \n ;;\nesac\n\nexit 0"
}


https://www.gsp.com/support/virtual/admin/unix/commands.html 13 commands to rule the world. Has zip and unzip commands
mkdir ~/guru
$ cd ~/guru
$ pwd
/home/fred/guru
$ zip -r tmp_stage_usr_local_lib_generate_user_report.zip /tmp/stage
adding: tmp/stage/ (stored 0%)
adding: tmp/stage/generate_user_report-1.0_1.pkg (deflated 0%)

$ unzip -l tmp_stage_usr_local_lib_generate_user_report.zip # see contents of this zip file
$ unzip -d / tmp_stage_usr_local_lib_generate_user_report.zip # use this command to extract files to /tmp/stage directory
$ tree /tmp/stage
/tmp/stage
├── +MANIFEST
├── +POST_INSTALL
├── +PRE_DEINSTALL
├── generate_user_report-1.0_1.pkg
├── plist
└── usr
└── local
├── etc
│ └── my.conf
├── lib
│ └── generate_user_report
│ ├── +MANIFEST
│ ├── Makefile
│ ├── README.md
│ ├── Report_fred-ghostbsd-pc1_2020-04-05_example.txt
│ ├── User_Report.py
│ ├── User_Report.sh
│ ├── applets-screenshooter.png
│ ├── generate_user_report.desktop
│ ├── pkg-descr
│ └── pkg-message
└── share
└── applications
└── generate_user_report.desktop

8 directories, 17 files
$  



#check the files and the staging directory of files setup
# -m ${STAGEDIR}   will find the '+MANIFEST' file in this directory
# -r  is the root directory
# -p  ${STAGEDIR}/plist  will use the 'plist' file to select which files to include in the package file
# -o  .     output the created package file into the present '.'  directory         

ls -lh ${STAGEDIR}
# verify that files plist and +MANIFEST exist here in this directory
# ${STAGEDIR}/usr/local/lib/generate_user_report/ files exist here referenced in plist filelist
# ${STAGEDIR}/usr/local/share/applications/generate_user_report.desktop
# cd ~/guru/
# issue this command to create a package file
pkg create -m ${STAGEDIR}/ -r ${STAGEDIR}/ -p ${STAGEDIR}/plist -o .

This should now have created a FreeBSD package in your present directory ~/guru/. Congratulations you are now a BSD package developer.

1 comment:

  1. On FreeBSD, use pkg install to add packages, but for customization, build from /usr/ports.

    Built packages can be shared with other machines and users.

    First create a signature file.
    ```
    # mkdir /root/repo && chmod 600 /root/repo
    # openssl genrsa -out /root/repo/repo.key 2048
    # openssl rsa -pubout -in /root/repo/repo.key -out /root/repo/public.key
    ```
    Next, write a Makefile.

    ```
    /root/src/pkg/Makefile

    all: rm -rf /usr/local/repo/repo/public.key
    rm -rf /usr/ports/packages/All/*
    pkg create -f tgz -o /usr/ports/packages/FreeBSD:13:amd64 -a
    pkg repo /usr/ports/packages/FreeBSD:13:amd64 /root/repo/repo.key
    ```
    Now all you have to do is make.

    ReplyDelete