Create what is only needed pkgs repository in Alpine Linux install (Part 1)

Some questions answered here.

  1. How to create a partial mirror?
  2. How to curate packages for ram-installs or a sys-installer master disk for schools/students?
  3. How to generate downloadable pkgs list with deps for sharing with new users?
  4. How can I make ram-installs permanent after reboot with no internet?

WIP (work in progress)

  • TODO:

A bit about rolling releases

  • TODO

Something about your alpine cache

  • Cache is only created with remote urls (eg. http[s]) in /etc/repositories.
  • Which means that pkgs in /cache are not created with method described below.
  • Packages from /cache dir may be utilized, depending upon how apk resolves the version number during install calls.

About alpine diskless(ram based) basic install

  • TODO

How to create your needed pkgs mirror in alpinelinux installations

  1. Method described below is presently meant for ram-based installs. It may not be effective on other methods of installs.
  2. Method assumes you have a basic internet ready ram-based install/setup up and running.

Directory/files structures - of alpine boot disk with curated pkgs

    (1)
    /media/usb/
    |-- apks   <- installed from alpine-standard-3.18.3-armv7.iso
    |   `-- x86_64
    |       |-- APKINDEX.tar.gz
    |       |-- acct-6.6.4-r2.apk
    |       |-- ....
    |       `-- zstd-libs-1.5.5-r4.apk
    |-- apks2   <- custom curated apk pkgs folder
    |   `-- v3.18
    |       |-- fetch-apk.sh   <- helper script to download apks
    |       |-- main
    |       |   `-- x86_64
    |       |       |-- APKINDEX.tar.gz
    |       |       `-- ... .apk
    |       `-- community
    |           `-- x86_64
    |               |-- APKINDEX.tar.gz
    |               `-- ... .apk
    |-- boot
    |   |-- System.map-lts
    |   |-- ....
    |   `-- vmlinuz-lts
    |-- cache
    |   `-- installed
    |-- efi
    |   `-- boot
    |       `-- bootx64.efi
    |-- localhost.20240727210601.tar.gz
    |-- localhost.apkovl.tar.gz
    `-- lost+found

Method 1 (basic/manual)

mkdir -p /media/usb/apks2/alpine/v3.18/community/x86_64
cd /media/usb/apks2/alpine/v3.18/community/
wget http://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
mv APKINDEX.tar.gz ./x86_64/

# add following in /etc/apk/repositories
/media/usb/apks2/alpine/v3.18/community
# run usual update/add from apk
apk update

# manually manage the downloadable list, of what is needed
wget -i myapk.lst --base=http://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/
mv *.apk ./x86_64/

Method 2 (download with dependencies)

File: fetch-apk.sh [3].

#!/bin/sh

VER=v3.18
ARCH=x86_64

# -------------------------------------------------------------------
# main/community/testing
# -------------------------------------------------------------------
set_apks_url() {
    local branch=$1
    echo '>>> set branch: '$branch
    url=https://dl-cdn.alpinelinux.org/alpine/${VER}/${branch}/${ARCH}
    dest=/media/usb/apks2/alpine/${VER}/${branch}/${ARCH}/
}

# -------------------------------------------------------------------
make_fetch_apks_list() {
    # altenative methods:
    # 1. apk add ffmpeg > a.lst 2>&1
    # 2. 'apk add --simulate' and process the output
    # 3. 'apk fetch --recursive <pkg name>',
    #     useful if pkgs downloaded can be sorted
    apk fix > a.lst 2>&1

    grep '^(' a.lst | awk -F' ' '{print $3 " " $4}' > b.lst
    local branch=$1; local F="${branch}.lst"; rm -f ${F}
    echo ">>> creating ${F}"
    cat 'b.lst' | while read f; do \
        local name=$(echo $f | awk '{print $1}')
        local file=$(echo $f | sed 's/ //g' | sed 's/(/-/' | sed 's/)//')
        local b=$(apk policy ${name} | grep -c ${branch})
        # local b=$(grep -c "^P:${name}$" 'APKINDEX') # alt method
        if [ $b -gt 0 ]; then
            echo "adding + $b $file"; echo ${file} >> ${F}
        fi
    done
    echo "... list created, run fetch cmd"
    rm -f a.lst b.lst
}

fetch_apks() {
    local branch=$1
    cat ${branch}.lst | while read f; do \
        echo ">>> fetching: $url/$f.apk"
        wget -c --no-check-certificate $url/$f.apk
    done
}

if [ x"$1" = 'xmain' -o x"$1" = 'xcommunity' -o x"$1" = 'xtesting' ]; then
    set_apks_url $1
    # cd /tmp
    if [ x"$2" = 'xmklist' ]; then make_fetch_apks_list "$1"; fi
    if [ x"$2" = 'xfetch' ]; then fetch_apks "$1"; fi
fi

# -------------------------------------------------------------------
# -------------------------------------------------------------------

With current entry in /etc/apk/repositories and internet available.

cat /etc/apk/repositories
/media/usb/apks

Script that binds them all

# 1.
MYREPO=/media/usb/apks2/alpine/v3.18
MYCOMMUNITY=${MYREPO}/community/
mkdir -p ${MYCOMMUNITY}/x86_64
cd ${MYREPO}
# copy paste here the script above as 'fetch-apk.sh'
# or download updated code from git repo (see link below)

# 2a.
# get index file
wget http://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
mv APKINDEX.tar.gz ./community/x86_64/

# 2b.
# add following in /etc/apk/repositories
/media/usb/apks2/alpine/v3.18/community

# 2c.
apk update

# 3a.
# run usual 'apk add'
apk add <pkg name here>

# 3b.
# get apks pkgs from community repo
sh fetch-apk.sh community mklist
sh fetch-apk.sh community fetch
mv *.apk ./community/x86_64/

# 4a.
apk fix # this will install pkgs as added in step 3a above

# NOTE: this whole process can be repeated for other branches too,
# namely: main, testing
# Lists created by mklist call above, can be copied and shared with
# other alpine users for pre/quick download of pkgs.

Author

V.Krishn


Resources


Edit - History - Print - Recent Changes - Search
Page last modified on November 10, 2024, at 07:46 PM