우분투 패키지 설정 파일 완벽 관리 dpkg-maintscript-helper 실습 가이드

개요

우분투 및 데비안 패키지 업데이트 과정에서 설정 파일(conffile)의 충돌 없이 안전하게 파일을 삭제하거나 경로를 변경하는 방법을 다룹니다. dpkg-maintscript-helper 명령어의 핵심 문법과 주요 파라미터를 실습을 통해 단계별로 학습합니다.

dpkg-maintscript-helper 기본 개념 및 지원 옵션 확인

dpkg-maintscript-helper 실습을 진행하기에 앞서 시스템 내 실행 파일의 설치 경로를 확인하기 위해 which dpkg-maintscript-helper 명령어를 실행합니다.

which dpkg-maintscript-helper

dpkg-maintscript-helper 명령어는 데비안 및 우분투 패키지의 메인테이너 스크립트에서 설정 파일(conffile) 변경, 이름 변경, 삭제 등의 작업을 안전하게 처리하도록 돕는 도구입니다.
--help 옵션을 실행하여 지원하는 서브 명령어 목록과 기본 사용법을 확인합니다.
⚙️ [주요 옵션]

supports <command> : 지정한 서브 명령어가 현재 시스템의 dpkg-maintscript-helper에서 지원되는지 여부를 확인합니다.
rm_conffile <conffile> : 패키지 업그레이드 시 더 이상 사용하지 않는 구버전 설정 파일을 안전하게 제거합니다.
mv_conffile <old-conf> <new-conf> : 기존 설정 파일의 이름이나 경로를 새로운 설정 파일로 안전하게 변경합니다.
symlink_to_dir <pathname> <old-symlink-target> : 기존 심볼릭 링크를 일반 디렉터리로 안전하게 전환합니다.
dir_to_symlink <pathname> <new-symlink-target> : 기존 디렉터리를 심볼릭 링크로 안전하게 전환합니다.

dpkg-maintscript-helper –help

rm_conffile 옵션을 활용한 이전 설정 파일 안전 제거 실습

설정 파일 폐기 테스트를 진행할 임시 디렉터리 구조를 생성하기 위해 mkdir -p /tmp/dpkg_helper_lab/etc 명령어를 실행합니다.

mkdir -p /tmp/dpkg_helper_lab/etc

구버전 패키지에서 사용하던 가상의 레거시 설정 파일을 생성하기 위해 echo 'legacy_setting=active' > /tmp/dpkg_helper_lab/etc/legacy.conf 명령어를 실행합니다.

echo ’legacy_setting=active’ > /tmp/dpkg_helper_lab/etc/legacy.conf

생성된 레거시 설정 파일의 내용이 올바르게 작성되었는지 확인하기 위해 cat /tmp/dpkg_helper_lab/etc/legacy.conf 명령어를 실행합니다.

cat /tmp/dpkg_helper_lab/etc/legacy.conf

dpkg-maintscript-helper rm_conffile /tmp/dpkg_helper_lab/etc/legacy.conf 1.0.0-1 my-test-pkg -- preinst 2.0.0-1 명령어는 패키지를 2.0.0-1 버전으로 업그레이드할 때 1.0.0-1 버전까지 존재하던 구버전 설정 파일(legacy.conf)을 패키지 사전 설치(preinst) 단계에서 안전하게 폐기하도록 처리합니다.
사용자가 해당 파일을 수정했는지 여부를 감지하고, 수정되지 않은 경우 불필요한 설정 파일이 시스템에 남지 않도록 이름 변경 및 제거 준비 작업을 수행합니다.

dpkg-maintscript-helper rm_conffile /tmp/dpkg_helper_lab/etc/legacy.conf 1.0.0-1 my-test-pkg – preinst 2.0.0-1

mv_conffile 옵션을 통한 설정 파일 마이그레이션 실습

설정 파일 경로 변경 실습에 사용할 기존 설정 파일을 생성하기 위해 echo 'server_port=8080' > /tmp/dpkg_helper_lab/etc/service_old.conf 명령어를 실행합니다.

echo ‘server_port=8080’ > /tmp/dpkg_helper_lab/etc/service_old.conf

dpkg-maintscript-helper mv_conffile /tmp/dpkg_helper_lab/etc/service_old.conf /tmp/dpkg_helper_lab/etc/service_new.conf 1.0.0-1 my-test-pkg -- preinst 2.0.0-1 명령어는 패키지를 2.0.0-1 버전으로 업그레이드할 때 기존 설정 파일(service_old.conf)을 새 경로(service_new.conf)로 안전하게 마이그레이션하도록 사전 설치(preinst) 단계에서 준비합니다.
사용자가 기존 설정 파일에 수정한 내용이 있을 경우 변경 사항을 유실하지 않고 새로운 설정 파일에 온전하게 반영되도록 처리합니다.

dpkg-maintscript-helper mv_conffile /tmp/dpkg_helper_lab/etc/service_old.conf /tmp/dpkg_helper_lab/etc/service_new.conf 1.0.0-1 my-test-pkg – preinst 2.0.0-1

명령어 실행 후 임시 디렉터리 내 설정 파일들의 상태를 확인하기 위해 ls -l /tmp/dpkg_helper_lab/etc/ 명령어를 실행합니다.
preinst 단계에서는 기존 파일이 즉시 새 파일명으로 교체되지 않고 내부 추적 상태로 관리되므로 파일 목록에 service_old.conf가 그대로 남아 있음을 확인할 수 있습니다.

ls -l /tmp/dpkg_helper_lab/etc/

데비안 유지관리자 스크립트(maintscript) 작성 및 실무 적용 패턴

패키지 메인테이너 스크립트를 작성할 디렉터리 환경을 구성하기 위해 mkdir -p /tmp/dpkg_helper_lab/debian 명령어를 실행합니다.

mkdir -p /tmp/dpkg_helper_lab/debian

패키지 설치 완료 후 구버전 설정 파일 제거 작업을 안전하게 처리하도록 메인테이너 스크립트 템플릿을 생성하기 위해 cat << 'EOF' > /tmp/dpkg_helper_lab/debian/postinst 명령어를 실행합니다.
postinst 스크립트 내에 dpkg-maintscript-helper rm_conffile 명령어를 포함하여 패키지 업그레이드 시 전달되는 인자("$@")를 헬퍼 도구로 넘겨주는 표준 연동 구조를 정의합니다.

cat « ‘EOF’ > /tmp/dpkg_helper_lab/debian/postinst
#!/bin/sh
set -e
dpkg-maintscript-helper rm_conffile /etc/legacy.conf 1.0.0-1 my-test-pkg – “$@”
#DEBHELPER#
exit 0
EOF

작성된 postinst 스크립트를 패키지 설치 시 시스템에서 실행할 수 있도록 실행 권한을 부여하기 위해 chmod +x /tmp/dpkg_helper_lab/debian/postinst 명령어를 실행합니다.

chmod +x /tmp/dpkg_helper_lab/debian/postinst

생성된 postinst 스크립트의 내용과 헬퍼 명령어 연동 구조가 표준에 맞게 작성되었는지 확인하기 위해 cat /tmp/dpkg_helper_lab/debian/postinst 명령어를 실행합니다.
출력 결과를 통해 스크립트 실행 중단 옵션(set -e), dpkg-maintscript-helper 연동 구문, 그리고 데비안 헬퍼 치환 토큰(#DEBHELPER#)이 올바르게 구성되어 있음을 확인할 수 있습니다.

cat /tmp/dpkg_helper_lab/debian/postinst

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

rm -rf /tmp/dpkg_helper_lab

지금까지 dpkg-maintscript-helper를 활용해 우분투 패키지 업그레이드 시 설정 파일을 안전하게 관리하고 이전하는 방법을 실습과 함께 살펴보았습니다.
패키지 유지보수 스크립트 작성 시 설정 파일 유실이나 충돌 없이 안정적인 배포 환경을 구축하는 데 유용하게 활용해 보시기 바랍니다.