# How can I save and then install from ftp all installed packages?



## Andrey (Nov 29, 2010)

I found small script: 
`# for p in `\ls /var/db/pkg`; do pkg_create -b ${p}; done`
is there a standard command for this operation ?
and then how to create an INDEX file ?


----------



## SirDice (Nov 29, 2010)

Andrey said:
			
		

> I found small script:
> `# for p in `\ls /var/db/pkg`; do pkg_create -b ${p}; done`
> is there a standard command for this operation ?


If there was the script wouldn't be needed.


----------



## Andrey (Nov 29, 2010)

So how can I make INDEX file from /var/db/pkg ? 
[CMD=""]# cache-init[/CMD] cache-init works only with the /usr/ports? from /var/db/pkg it can not do INDEX?
Even if I set
[CMD=""]# setenv PORTSDIR /var/db/pkg[/CMD]


----------



## wblock@ (Nov 29, 2010)

Andrey said:
			
		

> So how can I make INDEX file from /var/db/pkg ?
> [CMD=""]# cache-init[/CMD] cache-init works only with the /usr/ports?



No idea what that command is or does.



> from /var/db/pkg it can not do INDEX?
> Even if I set
> [CMD=""]# setenv PORTSDIR /var/db/pkg[/CMD]



Setting PORTSDIR elsewhere may not do what you want.  And that is really the question: what are you trying to do?  Are you trying to duplicate all the packages installed on one system onto another system?


----------



## Andrey (Nov 29, 2010)

Yes, I trying to duplicate the system, and simultaneously stored all packages on a CD, FLASH or local FTP... for faster installation than via the internet...


----------



## phoenix (Nov 29, 2010)

Andrey said:
			
		

> I found small script:
> `# for p in `\ls /var/db/pkg`; do pkg_create -b ${p}; done`
> is there a standard command for this operation ?
> and then how to create an INDEX file ?



First, what is it that you are trying to accomplish, exactly?  Are you just wanting to build packages on one machine and then install them on other machines?  Are you trying to create a local package mirror?  Something else?

Knowing what your goal is, will make it easier for people to make suggestions.

For example, if all you want to do is build packages on MachineA and then install them on Machines B through Q, the process is along the lines of:

Create /usr/ports/packages/ directory
Set *PACKAGES=/usr/ports/packages* in your shell's environment
Use *make package-recursive* to install your apps (or use portmaster(8) configured to save packages); packages will be saved under /usr/ports/packages/
Export /usr/ports/packages/ via NFS
Mount the packages export onto the client machines
Then use pkg_add(1) from within the NFS packages directory to install the packages.  Since all the dependencies are also in that directory, everything is installed via packages.


----------



## wblock@ (Nov 29, 2010)

Andrey said:
			
		

> Yes, I trying to duplicate the system, and simultaneously stored all packages on a CD, FLASH or local FTP... for faster installation than via the internet...



Besides what phoenix shows, consider also just duplicating the entire system with dump(8)/restore(8) (FAQ: New Huge Disk, Backup Options For FreeBSD).  That may actually be faster than installing all the packages.


----------



## SirDice (Nov 29, 2010)

phoenix said:
			
		

> Create /usr/ports/packages/ directory
> Set *PACKAGES=/usr/ports/packages* in your shell's environment


$PORTSDIR/packages is the default


----------



## Andrey (Nov 29, 2010)

make package-recursive - start downloading all packages from the Internet 

dump, restore - good method, but I want to keep everything in packages.tbz as
ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.1-release/Latest/ 

I decided to do so:
`# for p in `\ls /var/db/pkg`; do echo pkg_add -i ${p}.tbz >> install; done; chmod +x install`

will generate a file

```
pkg_add -i ImageMagick-6.6.1.10.tbz
pkg_add -i ORBit2-2.14.18_1.tbz
pkg_add -i Terminal-0.4.5.tbz
pkg_add -i Thunar-1.0.2.tbz
pkg_add -i a2ps-a4-4.13b_4.tbz
pkg_add -i aalib-1.4.r5_5.tbz
...
```


----------



## wblock@ (Nov 30, 2010)

Andrey said:
			
		

> `# for p in `\ls /var/db/pkg`; do echo pkg_add -i ${p}.tbz >> install; done; chmod +x install`



Backslash looks unnecessary.  But then...



> ```
> pkg_add -i ImageMagick-6.6.1.10.tbz
> pkg_add -i ORBit2-2.14.18_1.tbz
> pkg_add -i Terminal-0.4.5.tbz
> ...



Seems like you could just do
`# pkg_add -i packagedir/*`

or maybe

`# file packagedir -exec pkg_add -i {} \+`

(Untested, and not sure about the correctness of using -i and installing packages out of dependency order.)


----------



## Andrey (Nov 30, 2010)

wblock said:
			
		

> Seems like you could just do
> `# pkg_add -i packagedir/*`
> 
> or maybe
> ...


no your commands do not work...

but like this all ok!  
[CMD=""]# cd /packagedir[/CMD]
[CMD=""]# for p in `ls *.tbz`; do pkg_add -i ${p}; done;[/CMD]


----------



## Andrey (Nov 30, 2010)

With verify that do not install already installed packages
[CMD=""]# cd /packagedir[/CMD]
[CMD=""]# for p in `ls *.tbz`; do if [ ! -d /var/db/pkg/${p%.*} ]; then pkg_add -i ${p}; fi; done;[/CMD]


----------



## phoenix (Nov 30, 2010)

You can simplify the for loop a bit:
`# for p in *.tbz; ...`

The shell expansion of *.tbz will be the same as executing ls in a sub-shell, but it should be faster/more efficient.


----------

