How to install pkg offline?

Here is a little something I wrote for fetching pkg files for offline use. Saw this thread and thought of sharing. It fetches packages in the quarterly directory, not latest. Adjust for taste.

Call it with the URL you want to download, as the argument, without a trailing slash:
./mirror.sh https://pkg.freebsd.org/FreeBSD:14:amd64

In this example, a new directory FreeBSD_14_amd64 will be created, and the structure will be replicated inside that directory. Just leave it to run, and it will fetch everything. Personally, though, I prefer rsync when it's available, because that just allows you to download changes only - and even allows you to replace updated versions automatically, with minimal bandwidth used.

Code:
#!/bin/csh

# We are interested in the latest packages
setenv PKGREPO "quarterly"

# Copy base URL
setenv BASEURL $1

# Transform colons in URL into underscores and remove everything up to the last slash
setenv BASEDIR `echo $BASEURL | sed -e 's/:/_/g;s:.*/::'`

if (! -d "$BASEDIR" ) then
    mkdir "$BASEDIR"
    echo "Downloading metadata into $BASEDIR ..."
    cd "$BASEDIR"
        wget -q "$BASEURL/$PKGREPO/data.pkg"
        wget -q "$BASEURL/$PKGREPO/data.txz"
        wget -q "$BASEURL/$PKGREPO/meta"
        wget -q "$BASEURL/$PKGREPO/meta.conf"
        wget -q "$BASEURL/$PKGREPO/packagesite.pkg"
        wget -q "$BASEURL/$PKGREPO/packagesite.txz"
        mkdir "Latest"
        cd "Latest"
            wget -q "$BASEURL/$PKGREPO/Latest/pkg-devel.pkg"
            wget -q "$BASEURL/$PKGREPO/Latest/pkg.pkg"
            wget -q "$BASEURL/$PKGREPO/Latest/pkg.pkg.sig"
            cd ..
        mkdir "All"
        cd "All"
            echo "Preparing package list for download ..."
            xzcat ../packagesite.txz | tar xfO - packagesite.yaml | jq -r '.repopath' | sed -e "s|.*|wget $BASEURL/$PKGREPO/&|" | sort | csh
        cd ..
    cd ..
endif
 
I tend to do a mass fetch of the entire package repo every 6 months or so. You can either scrape the packages off http://pkg.freebsd.org/ (used to be easier with FTP) or you can use pkg fetch -a to grab everything.

https://www.freebsd.org/cgi/man.cgi?query=pkg-fetch

Once you have a big directory with everything in it, when you want to install something, just cd into the directory and run:

Code:
# pkg add <package>.txz

Dependencies will be resolved automatically and offline. I don't think so many people use it like this (kind of like pre-pkgng), but it works well offline and I dislike being tied to the internet (worst part about UNIX and Linux in my opinion).
DEar kpedersen:
what command will be running to download full of package and dependencies of freebsd14.1 ? please show me the step and detail .thanks. . i want to download full of it. thanks.
 
DEar kpedersen:
what command will be running to download full of package and dependencies of freebsd14.1 ? please show me the step and detail .thanks. . i want to download full of it. thanks.
It should just be a simple:

$ pkg fetch -a

You can specify the output directory with -o. I.e:

$ pkg fetch -o offline_backup -a

Some more info here (pkg-fetch(8))
 
Back
Top