bin sh iso_dir pkg_list dpkg -l sed -n ii pkg_list dpkg -l sed -n ii c

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#!/bin/sh
iso_dir="${1}"
#pkg_list=`dpkg -l | sed -n s'/^ii\s*\([^ \n\t]*\).*$/\1/p'`
pkg_list=`dpkg -l|sed -n 's/^ii[ ]*\([^ ]*\).*/\1/p'`
#copy debs from local cache
src_debs="/var/cache/apt/archives"
#additional debs, not in your cache
add_debs=""
#GPG name for signing local repository (gpg keys must be created)
pgp_name="Stefan Zerkalica"
#repository label / disk info
label="ubuntu_nxr"
#some internal variables for temporary processing
arch=`dpkg --print-installation-architecture`
dist_name=`lsb_release -cs`
dist_root="dists/${dist_name}"
components="main"
usage()
{
echo "Simplest debian/ubuntu repository from cache creator"
echo "example: $0 dest_dir"
echo "and add deb file:/cdrom ${dist_name} ${components} in /etc/apt/sources.list"
}
copy_debs()
{
rm -rf ${iso_dir}/pool
mkdir -p ${iso_dir}/pool
cp -vf ${src_debs}/* ${iso_dir}/pool/
if [ "${add_debs}" != "" ]; then
cp -vf ${add_debs}/* ${iso_dir}/pool/
fi
}
make_repo()
{
cdr=`pwd`
cd "${iso_dir}"
rm -rf dists
dest_debs="${dist_root}/${components}/binary-${arch}"
mkdir -p ${dest_debs}
rm ${dest_debs}/Packages
apt-ftparchive packages pool>${dest_debs}/Packages
cat ${dest_debs}/Packages | gzip -9c>${dest_debs}/Packages.gz
cd "${cdr}"
}
gen_release()
{
cdr=`pwd`
cd "${iso_dir}"
lapt="${TMP}/lapt.conf"
cat > ${lapt} << EOF
APT::FTPArchive::Release {
Origin "APT-Move";
Label "APT-Move";
Suite "${dist_name}";
Codename "${dist_name}";
Architectures "${arch}";
Components "${components}";
Description "${label}";
};
EOF
rm ${dist_root}/Release
apt-ftparchive -c ${lapt} release ${dist_root}/>Release
mv Release ${dist_root}
rm ${lapt}
cd "${cdr}"
}
sign_rep()
{
cdr=`pwd`
cd "${iso_dir}"
gpg -bao ./${dist_root}/Release.gpg ./${dist_root}/Release
gpg --export -a "${pgp_name}" > public.key
mkdir -p .disk
echo ${label} `date +%Y-%m-%d` > .disk/info
echo "${components}">.disk/base_components
cd "${cdr}"
}
if [ -z "${iso_dir}" ]; then
usage
exit 1
else
echo "Making pool"
copy_debs
echo "Creating local repository"
make_repo
echo "Generate Release file"
gen_release
echo "Sign repository"
sign_rep
echo "Repository created, use:"
echo "deb file:/media/cdrom ${dist_name} ${components}"
fi