차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
| linuxfromscratch:auto-lfs [2024/05/27 10:57] – [파일 다운로드 링크 처리] baecy | linuxfromscratch:auto-lfs [2026/04/15 17:58] (현재) – baecy | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| - | ===== Host에서 LFS 디렉토리로 chroot ===== | + | === 디렉터리/ |
| + | < | ||
| + | ls -d1 * | sed ' | ||
| + | find . -maxdepth 1 -type d -not -path ' | ||
| + | </ | ||
| + | === LC_COLLATE 문제로 빌드 터지기 싫음 === | ||
| + | < | ||
| + | ### Toggle LANG C.UTF-8 <-> ko_KR.UTF-8 | ||
| + | function tg-lang() { | ||
| + | # 현재 LANG 확인 | ||
| + | case " | ||
| + | ko_KR*) | ||
| + | export LANG=C.UTF-8 | ||
| + | ;; | ||
| + | *) | ||
| + | export LANG=ko_KR.UTF-8 | ||
| + | ;; | ||
| + | esac | ||
| + | # LC_ALL 로 인한 우선순위 변경 방지 | ||
| + | unset LC_ALL | ||
| + | |||
| + | # PS1 재설정 | ||
| + | if [ -f "/ | ||
| + | source / | ||
| + | fi | ||
| + | |||
| + | echo -e " | ||
| + | } | ||
| + | ## alias 별도 관리 | ||
| + | # alias tl=' | ||
| + | </ | ||
| + | |||
| + | === 파이썬 모듈 빌드하고 설치하기 귀찮음 === | ||
| + | < | ||
| + | # | ||
| + | |||
| + | ## Get Package Name | ||
| + | if [[ -r $PWD/ | ||
| + | PKG_NAME=$(grep -i ' | ||
| + | else | ||
| + | echo " | ||
| + | read -p "Enter Package Name: " PKG_NAME | ||
| + | fi | ||
| + | |||
| + | ## Permission Check | ||
| + | PERM_ELEV="" | ||
| + | [[ $UID -ne 0 ]] && PERM_ELEV=" | ||
| + | |||
| + | ## Clean Previous Build | ||
| + | rm -rf dist | ||
| + | |||
| + | ## Build and Install | ||
| + | pip3 wheel -w dist --no-cache-dir --no-build-isolation --no-deps $PWD | ||
| + | |||
| + | ${PERM_ELEV} pip3 install --no-index --find-links dist " | ||
| + | </ | ||
| + | === ./configure --docdir= 입력하기 귀찮음 개선판 === | ||
| + | < | ||
| + | # | ||
| + | |||
| + | ## 기본값은 현재 디렉터리를 선택하도록 0 지정 | ||
| + | DEPTH=${1: | ||
| + | |||
| + | ## 인자가 숫자인지 확인 | ||
| + | if ! [[ " | ||
| + | echo " | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | ## 기본 디렉터리 및 대상 디렉터리 초기값 설정 | ||
| + | ORIGINAL_PWD=$(pwd) | ||
| + | TARGET_PATH=$ORIGINAL_PWD | ||
| + | |||
| + | # 주어진 인자(숫자) 만큼 상위 디렉터리 이름 반환 | ||
| + | for (( i=0; i< | ||
| + | # Stop when reach the top directory | ||
| + | if [ " | ||
| + | break | ||
| + | fi | ||
| + | TARGET_PATH=$(dirname " | ||
| + | done | ||
| + | |||
| + | ## 실제 반환할 값 | ||
| + | DOCDIR_VALUE=$(basename " | ||
| + | |||
| + | ## 인자(숫자)만큼 이동한 결과가 "/" | ||
| + | ## 최종 반환값이 "/ | ||
| + | ## 현재 디렉터리에서 한단계 상위 디렉터리 이름 반환 | ||
| + | if [ " | ||
| + | TARGET_PATH=$ORIGINAL_PWD | ||
| + | RECOVER_DEPTH=$(( DEPTH > 0 ? 1 : 0 )) | ||
| + | |||
| + | for (( i=0; i< | ||
| + | TARGET_PATH=$(dirname " | ||
| + | done | ||
| + | DOCDIR_VALUE=$(basename " | ||
| + | fi | ||
| + | |||
| + | ## 최종 반환값 | ||
| + | echo "/ | ||
| + | |||
| + | unset DEPTH ORIGINAL_PWD TARGET_PATH RECOVER_DEPTH DOCDIR_VALUE | ||
| + | </ | ||
| + | |||
| + | === ./confiugre --docdir= 입력하기 귀찮음 === | ||
| + | < | ||
| + | # | ||
| + | |||
| + | ## 별도의 빌드 디렉터리를 사용하는 경우 | ||
| + | ## 아무 인자나 입력하면 이전 디렉터리명 사용 | ||
| + | ## 예: ./configure --prefux=usr --docdir=$(docdir 1) | ||
| + | if [ -z $1 ]; then | ||
| + | DOCDIR_VALUE=$(basename $(pwd)) | ||
| + | else | ||
| + | DOCDIR_VALUE=$(basename $(dirname $(pwd))) | ||
| + | fi | ||
| + | |||
| + | echo "/ | ||
| + | unset DOCDIR_VALUE | ||
| + | |||
| + | </ | ||
| + | ----- | ||
| + | === LFS mount and chroot script v.0.2 === | ||
| + | 아직도 쓸데없이 길고 함수로 정리할 필요 있음. | ||
| + | 갈길이 멀었음. | ||
| + | |||
| + | lfs-dive.sh | ||
| + | < | ||
| + | # | ||
| + | # if [[ -z ${LFS} ]]; then echo "Enter the LFS 13.0" | is same follow | ||
| + | : ${LFS: | ||
| + | echo "Base path - ${LFS}" | ||
| + | export LFS | ||
| + | |||
| + | |||
| + | if [[ $UID == 0 ]]; then USER_ELEV=""; | ||
| + | |||
| + | # Source code packages Repo. mount | ||
| + | mountpoint -q $LFS/ | ||
| + | |||
| + | # 1. If already mounted virtural kernel file system then execute chroot script. | ||
| + | # 2. if need mount virtual kernel file system. | ||
| + | |||
| + | if mountpoint -q $LFS/dev; then | ||
| + | lfs-redive.sh | ||
| + | exit 0 | ||
| + | else | ||
| + | ${USER_ELEV} mount -v --bind /dev $LFS/dev | ||
| + | ${USER_ELEV} mount -vt devpts devpts -o gid=5, | ||
| + | ${USER_ELEV} mount -vt proc proc $LFS/proc | ||
| + | ${USER_ELEV} mount -vt sysfs sysfs $LFS/sys | ||
| + | ${USER_ELEV} mount -vt tmpfs tmpfs $LFS/run | ||
| + | if [ -h $LFS/ | ||
| + | ${USER_ELEV} install -v -d -m 1777 $LFS$(realpath /dev/shm) | ||
| + | else | ||
| + | ${USER_ELEV} mount -vt tmpfs -o nosuid, | ||
| + | fi | ||
| + | lfs-redive.sh | ||
| + | fi | ||
| + | </ | ||
| + | lfs-redive.sh | ||
| + | < | ||
| + | if [[ ! -f " | ||
| + | if [[ $UID == 0 ]]; then USER_ELEV=""; | ||
| + | |||
| + | ${USER_ELEV} chroot " | ||
| + | HOME=/ | ||
| + | TERM=" | ||
| + | PS1=' | ||
| + | PATH=/ | ||
| + | MAKEFLAGS=" | ||
| + | TESTSUITEFLAGS=" | ||
| + | /bin/bash --login | ||
| + | </ | ||
| + | === Host에서 LFS 디렉토리로 chroot | ||
| + | 다시 보니 별 의미없이 장황하고 가독성 떨어짐. | ||
| 6장 완료후 책의 끝까지 유용하게 사용하는 스크립트 | 6장 완료후 책의 끝까지 유용하게 사용하는 스크립트 | ||
| 줄 103: | 줄 278: | ||
| esac | esac | ||
| ## End ~/ | ## End ~/ | ||
| - | </ | + | </ |
| - | ===== 파일 다운로드 링크 처리 ===== | + | ---- |
| + | === 파일 다운로드 링크 처리 === | ||
| + | <wrap hi> | ||
| 다음과 같이 등록하고 사용해야 '' | 다음과 같이 등록하고 사용해야 '' | ||
| 줄 125: | 줄 302: | ||
| - wget, git, gawk 설치 여부 확인 | - wget, git, gawk 설치 여부 확인 | ||
| + | 수정할 사항 | ||
| + | - git clone 사용 할 때 작업 디렉터리에 먼저 받고 source 디렉터리에 복사하는 방식으로 변경 필요. | ||
| + | == 작성 == | ||
| <code user=user host=host lang=bash> | <code user=user host=host lang=bash> | ||
| user@host:[ ~ ] $ pre-stage | user@host:[ ~ ] $ pre-stage | ||
| 줄 215: | 줄 395: | ||
| fi | fi | ||
| + | |||
| + | unset InputStringType BuildBase SourceBase TargetFile GitDirCheck GitCheck ZipCheck TargetDir NotFoundMsg1 | ||
| </ | </ | ||
| + | == 구글 AI 모드로 정리: 미확인 상태 == | ||
| + | < | ||
| + | # 쉬뱅(#! / | ||
| + | |||
| + | # 1. tput을 이용한 색상 정의 | ||
| + | BOLD=$(tput bold) | ||
| + | BLUE=$(tput setaf 4) | ||
| + | GREEN=$(tput setaf 2) | ||
| + | BIGREEN=" | ||
| + | RED=$(tput setaf 1) | ||
| + | YELLOW=$(tput setaf 3) | ||
| + | RESET=$(tput sgr0) | ||
| + | |||
| + | # OpenRC 스타일 상태 출력 함수 | ||
| + | print_status() { | ||
| + | local msg=" | ||
| + | local status=$2 | ||
| + | local col=$(tput cols) | ||
| + | printf " ${BLUE}${BOLD}*${RESET} %s" " | ||
| + | tput hpa $((col - 7)) | ||
| + | [ $status -eq 0 ] && printf " | ||
| + | } | ||
| + | |||
| + | # 2. 초기 체크 (p4c 별칭 확인) | ||
| + | if [ " | ||
| + | echo -e "p4c is not ${YELLOW}alias registered${RESET}, | ||
| + | # source 시에만 동작하도록 | ||
| + | [ -f " | ||
| + | return 2 2>/ | ||
| + | fi | ||
| + | |||
| + | # 3. 변수 설정 | ||
| + | if [ -z " | ||
| + | echo -e " | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | # 기본 경로 설정 (LFS 환경 변수 활용) | ||
| + | BuildBase=" | ||
| + | SourceBase=" | ||
| + | TargetFile=$(basename " | ||
| + | TargetDir=$(echo " | ||
| + | InputScheme=$(echo " | ||
| + | |||
| + | # 4. 권한 체크 | ||
| + | if [ ! -w " | ||
| + | echo -e "Check ${RED}$BuildBase${RESET} Ownership/ | ||
| + | return | ||
| + | fi | ||
| + | |||
| + | # 5. 디렉토리 이동 함수 (가장 최근 디렉토리 이동 로직 포함) | ||
| + | chg_dir() { | ||
| + | if [ -d " | ||
| + | cd " | ||
| + | else | ||
| + | local latest=$(ls -tcA -w1 | head -n1) | ||
| + | cd " | ||
| + | echo -e " | ||
| + | echo -e "Moved to latest: ${YELLOW}$latest${RESET}" | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | # 작업 시작 | ||
| + | [ " | ||
| + | |||
| + | # 6. 원격 파일 다운로드 (http, https, ftp) | ||
| + | case " | ||
| + | http|https|ftp) | ||
| + | wget --no-verbose -nc -P " | ||
| + | print_status " | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | # 7. 소스 처리 (Git vs Archive) | ||
| + | if [[ " | ||
| + | # Git 처리 | ||
| + | GitName=$(basename -s .git " | ||
| + | if [ -d " | ||
| + | chg_dir " | ||
| + | else | ||
| + | pushd " | ||
| + | [ -d " | ||
| + | git clone " | ||
| + | popd >/ | ||
| + | chg_dir " | ||
| + | print_status "Git Clone: $GitName" | ||
| + | fi | ||
| + | else | ||
| + | # 압축 파일 처리 | ||
| + | if [[ " | ||
| + | mkdir -p " | ||
| + | unzip -q " | ||
| + | print_status " | ||
| + | else | ||
| + | if [ ! -d " | ||
| + | tar -xf " | ||
| + | print_status " | ||
| + | fi | ||
| + | chg_dir " | ||
| + | fi | ||
| + | fi | ||
| + | |||
| + | # 변수 정리 (local을 쓰지 못하는 source 환경이므로 직접 unset) | ||
| + | unset BOLD BLUE GREEN BIGREEN RED YELLOW RESET BuildBase SourceBase TargetFile TargetDir InputScheme GitName | ||
| + | </ | ||