우분투 dpkg-gencontrol 핵심 옵션 실습 가이드

개요

dpkg-gencontrol은 데비안 및 우분투 패키지 빌드 과정에서 DEBIAN/control 메타데이터 파일을 자동 생성하는 핵심 도구입니다. 본 글에서는 실습 패키지 환경을 구축하고 주요 옵션별 실행 결과와 생성되는 제어 파일의 차이점을 한눈에 살펴봅니다.

dpkg-dev 설치 및 기본 데비안 빌드 환경 구성

dpkg-gencontrol 실습에 필요한 데비안 패키지 개발 도구를 준비하기 위해 apt-get update -qq && apt-get install -y dpkg-dev 명령어를 실행합니다.

apt-get update -qq && apt-get install -y dpkg-dev

패키지 빌드 실습을 진행할 디렉터리와 데비안 메타데이터 경로를 생성하고 이동하기 위해 mkdir -p /tmp/pkg_demo/debian && cd /tmp/pkg_demo 명령어를 실행합니다.

mkdir -p /tmp/pkg_demo/debian && cd /tmp/pkg_demo

소스 패키지 정보와 빌드 대상 패키지의 기본 속성을 정의하기 위해 debian/control 파일을 작성합니다.

![cat « ‘EOF’ > debian/control Source: demo-tool Section: utils Priority: optional Maintainer: Test User [email protected] Standards-Version: 4.6.0

Package: demo-tool Architecture: any Description: Demo tool package A sample package for dpkg-gencontrol testing. EOF](captures/s01_c03_cat_____EOF____debian_control_Source__demo-tool_Se.png)

패키지의 버전 정보와 배포 이력을 정의하기 위해 debian/changelog 파일을 생성합니다.

![cat « ‘EOF’ > debian/changelog demo-tool (1.0.0-1) unstable; urgency=medium

  • Initial release.

– Test User [email protected] Mon, 01 Jan 2024 00:00:00 +0000 EOF](captures/s01_c04_cat_____EOF____debian_changelog_demo-tool__1_0_0-1.png)

dpkg-gencontrol 명령어는 소스 메타데이터와 변경 이력을 분석하여 바이너리 패키지용 제어 파일(DEBIAN/control)을 자동 생성합니다.
⚙️ [주요 옵션]

-p<package> : 제어 정보를 생성할 대상 바이너리 패키지 이름을 지정합니다.
-P<packagebuilddir> : 바이너리 패키지 빌드 트리가 위치한 디렉터리 경로를 지정합니다.
-c<controlfile> : 기본 debian/control 대신 읽어올 주 제어 파일의 경로를 지정합니다.
-l<changelogfile> : 기본 debian/changelog 대신 읽어올 변경 이력 파일의 경로를 지정합니다.
-F<changelogformat> : 변경 이력 파일(changelog)의 형식을 지정합니다.
-v<version> : changelog에 기록된 버전 대신 적용할 패키지 버전을 직접 지정합니다.
-O[<filename>] : 제어 파일 내용을 지정한 파일 경로 또는 표준 출력으로 출력합니다.

dpkg-gencontrol -pdemo-tool -Pdebian/demo-tool

dpkg-gencontrol 실행 결과로 생성된 최종 제어 파일의 내용을 확인하기 위해 cat debian/demo-tool/DEBIAN/control 명령어를 실행합니다.

cat debian/demo-tool/DEBIAN/control

-v 및 -D 옵션을 활용한 패키지 버전 및 필드 오버라이드

패키지 메타데이터가 준비된 실습 디렉터리로 이동하기 위해 cd /tmp/pkg_demo 명령어를 실행합니다.

cd /tmp/pkg_demo

debian/changelog에 기록된 기본 버전 대신 새로운 패키지 버전을 강제로 적용하여 제어 파일을 생성하기 위해 -v2.0.0-1custom 옵션을 추가하여 dpkg-gencontrol 명령어를 실행합니다.

dpkg-gencontrol -pdemo-tool -Pdebian/demo-tool -v2.0.0-1custom

생성된 DEBIAN/control 파일에서 패키지 버전이 지정한 값으로 올바르게 재정의되었는지 확인하기 위해 cat debian/demo-tool/DEBIAN/control | grep '^Version:' 명령어를 실행합니다.

cat debian/demo-tool/DEBIAN/control | grep ‘^Version:’

debian/control에 정의된 기존 필드 값을 덮어쓰고 패키지 분류(Section)와 설치 우선순위(Priority)를 직접 변경하기 위해 -D 옵션을 지정하여 dpkg-gencontrol 명령어를 실행합니다.

dpkg-gencontrol -pdemo-tool -Pdebian/demo-tool -DSection=net -DPriority=required

DEBIAN/control 파일에서 Section과 Priority 필드가 전달한 값으로 성공적으로 재정의되었는지 확인하기 위해 cat debian/demo-tool/DEBIAN/control | grep -E '^(Section|Priority):' 명령어를 실행합니다.

cat debian/demo-tool/DEBIAN/control | grep -E ‘^(Section|Priority):’

-V 매크로 치환 변수 정의 및 -u substvars 파일 적용

변수 치환 실습을 진행하기 위해 패키지 메타데이터가 위치한 /tmp/pkg_demo 디렉터리로 이동합니다.

cd /tmp/pkg_demo

제어 파일 내에서 동적으로 치환할 사용자 정의 변수(${custom:ReleaseName}) 필드를 추가하기 위해 echo 'Custom-Extra: ${custom:ReleaseName}' >> debian/control 명령어를 실행합니다.

echo ‘Custom-Extra: ${custom:ReleaseName}’ » debian/control

외부 파일 기반의 치환 변수 목록을 구성하기 위해 debian/substvars 파일에 custom:ReleaseName 값을 정의합니다.

echo ‘custom:ReleaseName=EnterpriseEdition’ > debian/substvars

-u 옵션을 통해 지정한 substvars 파일(debian/substvars)의 변수 값을 읽어 제어 파일의 매크로를 치환하도록 dpkg-gencontrol 명령어를 실행합니다.

dpkg-gencontrol -pdemo-tool -Pdebian/demo-tool -udebian/substvars

생성된 DEBIAN/control 파일에서 변수 치환이 정상적으로 적용되어 Custom-Extra: 필드에 파일에 정의된 값이 반영되었는지 확인하기 위해 cat debian/demo-tool/DEBIAN/control | grep 'Custom-Extra:' 명령어를 실행합니다.

cat debian/demo-tool/DEBIAN/control | grep ‘Custom-Extra:’

-V 옵션을 사용하여 명령행에서 직접 변수 값을 지정함으로써 기존 substvars 파일의 내용을 덮어쓰고 제어 파일을 생성하도록 dpkg-gencontrol 명령어를 실행합니다.

dpkg-gencontrol -pdemo-tool -Pdebian/demo-tool -V"custom:ReleaseName=CommunityEdition"

명령행 옵션(-V)으로 재정의한 변수 값이 최종 DEBIAN/control 파일의 Custom-Extra: 필드에 올바르게 반영되었는지 확인하기 위해 cat debian/demo-tool/DEBIAN/control | grep 'Custom-Extra:' 명령어를 실행합니다.

cat debian/demo-tool/DEBIAN/control | grep ‘Custom-Extra:’

-O 및 -c 옵션으로 파일 저장 없이 표준 출력 및 커스텀 control 지정

실습 파일들이 위치한 작업 경로로 이동하기 위해 cd /tmp/pkg_demo 명령어를 실행합니다.

cd /tmp/pkg_demo

기본 제어 파일을 보존하면서 별도의 커스텀 템플릿 제어 파일을 생성하기 위해 cp debian/control debian/control.custom 명령어를 실행합니다.

cp debian/control debian/control.custom

새로 복사한 커스텀 제어 파일에 패키지 공식 웹사이트 정보를 추가하기 위해 echo 'Homepage: https://example.com/demo-tool' >> debian/control.custom 명령어를 실행합니다.

echo ‘Homepage: https://example.com/demo-tool’ » debian/control.custom

기본 파일 대신 -c 옵션으로 지정한 커스텀 제어 파일을 읽고, 파일로 저장하지 않고 -O 옵션을 통해 터미널 표준 출력으로 즉시 메타데이터 결과를 확인하기 위해 dpkg-gencontrol -pdemo-tool -cdebian/control.custom -O 명령어를 실행합니다.

dpkg-gencontrol -pdemo-tool -cdebian/control.custom -O

실습 과정에서 생성된 모든 임시 파일과 작업 디렉터리를 깔끔하게 정리하기 위해 rm -rf /tmp/pkg_demo 명령어를 실행합니다.

rm -rf /tmp/pkg_demo

지금까지 우분투 환경에서 데비안 패키지 제어 파일을 생성하는 dpkg-gencontrol의 핵심 옵션과 실습 과정을 간단하게 살펴보았습니다.
각 옵션의 역할을 잘 활용하여 실무 패키징 작업에서도 목적에 맞는 메타데이터를 유연하고 정확하게 구성해 보시기 바랍니다.