Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

Теперь Вы можете запустить его в формате ./create_zone.sh <zone-name> <zone-ip-domain> <zone-ip-node> , например!:

./create_zone.sh zone02 192.168.0 3

...

Code Block
languagebash
cat > make_repo.sh <<EOT
#!/bin/bash

# File create for save temporary values
>list_one
>list_two
>pkg_dep
>tmp0
>tmp1
>tmp

function get_depends()## If you need log then put here the name of the log file
#LOG_FILE="list_deps"
LOG_FILE=""
function print_log {
  ##if This function get depends for build component[[ "\$LOG_FILE" != "" ]]; then
   [ -zecho "\$(grep -f pkg_dep <<< \$1)" ] &&
  apt-get install -s \$1 2>/dev/null | grep Inst | awk '{print \$2}'| sort -u &&
  echo \$pkg >> pkg_dep
}

function all_dep()
{
  ## This recursion function for get recursion depends for build conmponents
  for pkg in \$@; do
    all_dep \$(get_depends \$pkg)
  done
}

## Loop for get depends for build components
while read component; do
  if [[ "" == "\$component" ]]; then
    continue
  fi
  echo -e "\\033[33;1;4m =====> Getting depends for \$component... \\033[0m"
  apt-get --dry-run build-dep \$component 2>/dev/null | grep Inst | awk '{print \$2}' >> list_one
done < list_component

while read pkg; do
  if [[ "" == "\$pkg" ]]; then
    continue
  fi$1" >> \$LOG_FILE
  fi
}

## Loop for get depends for build components
## The list_component is a subject to check dependencies
sed -i '/^[ \\t]*\$/d' list_component
cp list_component list_to_check
## Prepare the final list of packages. Initially it is empty
echo "" > final_list
end=\$(cat list_to_check)
## Working while there is a subject to check
while [[ "\$end" != "" ]]; do
  ## Create an temporary file to collect dependencies
  echo "" > temp
  ## Check components one-by-one
  while read comp; do
    if [[ "" == "\$comp" ]]; then
      ## Skip empty line
      continue
    fi
    ## Check if this component is already checked
    res=\$(grep "^[ \\t]*\$comp[ \\t]*\\\$" final_list)
    if [[ "" != "\$res" ]]; then
      ## Skip already checked component
      continue
    fi
    ## Check component dependencies
    echo -e "\\033[33m =====> Getting depends for \$comp... \\033[0m"
    res=\$(apt-rdepends --build-depends --follow=DEPENDS \$comp | sed 's/^[ \\t]*Build-Depends:[ \\t]*//; s/^[ \\t]*Build-Depends-Indep:[ \\t]*//' | sed "s/^[ \\\\t]*\${component}[ \\\\t]*\\\$//; /^[ \\\\t]*\\\$/d; s/[ \\\\t]*(.*)\\\$//")
    ## Put dependencies to the temporary file
    echo "\$res" >> temp
    ## Put the component name to the list of already checked components
    echo "\$comp" >> final_list
  done < list_to_check

  ## Remove duplucated dependenciers and put them to the list of subjects to check
  sort -u temp > list_to_check
  sed -i '/^[ \\t]*\$/d' list_to_check
  sed -i '/^[ \\t]*\$/d' final_list
  end=\$(cat list_to_check)
done

## Loop for download dependencies
## Clear the final list from empty strings
sed -i '/^[ \\t]*\$/d' final_list
rm -f temp
rm -f list_to_check
## Scan the final list of packages one-by-one
while read pkg; do
  echo -e "\\033[36m =====> Check \$pkg... \\033[0m"
  ## Check if the package exists
  res=\$(apt-cache show \$pkg | grep "Package: \$pkg")
  if [[ "\$res" != "" ]]; then
    ## Download the package
    echo -e "\\033[35m =====> Downloading package \$pkg... \\033[0m"
    res=\$(apt-get download \$pkg | grep "E:" | sed -n 's/E://')
    ## Check the result of downloading
    if [[ "\$res" == "" ]]; then
      print_log "\$pkg : OK"
    else
      echo -e "\\033[31;1;4m \$res \\033[0m"
      print_log "\$pkg: \$res"
    fi
  else
    echo -e "\\033[3231;1;4m =====> Installing \$pkg...\$pkg: No package found \\033[0m"
  apt-get install -secho "\$pkg: 2>/dev/null | grep Inst | awk '{print \$2}' >> list_two
done < list_pkg_sec

cat list_one       >> tmp0
cat list_two       >> tmp0
cat list_component >> tmp0
cat list_pkg_sec   >> tmp0
cat tmp0 | sort -u >> tmp1No package found" >> list_deps
  fi
done < final_list

## Uploading *.deb packages to the local repo
echo -e "\\033[32;1m =====> Uploading *.deb packages... \\033[0m"
reprepro -b /data/repo --export=never -C main includedeb du2-prebuild /data/repo/pkg/*.deb

## Loop for get depends, use function 'all_dep'
while read pkg; do
  if [[ "" == "\$pkg" ]]; then
    continue
  fisources
while read component; do
  ## Download source files
  echo -e "\\033[33;1m =====> Downloading sources for \$component... \\033[0m"
  apt-get source --download-only $component
  ## Upload source files to the repo
  echo -e "\\033[36;132;4m1m =====> GettingUploading dependssources for \$pkg$component... \\033[0m"
  all_dep \$pkg >/dev/null
done < tmp1

cat pkg_dep        >> tmp1
cat tmp1 | sort -u >> tmp

while read pkg; do
  if [[ "" == "\$pkg" ]]; then
    continue
  fi
 reprepro -b /data/repo --export=never -C main includedsc du2-prebuild \$component*.dsc
  rm -rf \$component*
done < list_component

## Creating index for local repo
echo -e "\\033[32;1m =====> Creating indices for local repo... \\033[0m"
reprepro -Vb /data/repo export du2-prebuild
echo -e "\\033[3532;1;4m1m =====> DownloadingDONE \$pkg... \\033[0m"
if  sudo apt-get download \$pkg
done < tmp[[ "\$LOG_FILE" != "" ]]; then
  echo "Downloaded package list is put to \$LOG_FILE"
fi
EOT

Сделайте этот файл исполняемым:

...