You are not logged in.
TL;DR - uhm, I don't see what I'm doing wrong. I haven't seen a manual around the interwebz that tells me to specify anything differently.
Backstory: I want to migrate my Arch install from an old machine onto one that I just built. It'd be to annoying to manually pick every package again, manually.
yaourt -Q > yaourt.log
game me a handy list of what all I had installed on the old one. Both computers have the same graphic card manufacturer, so things stay simpler. Both are running ye ol' xf86-video-ati quite well.
So that yaourt.log file is formatted accordingly:
#output of yaourt -Q
[. . .]
extra/alsa-lib 1.0.25-1
extra/alsa-plugins 1.0.25-1
[. . .]
This allows me to use the '/' and ' 'characters as reference points to extract the package names themselves. Doesn't matter if there's a trailing space at the end of the yaourt -S ... in my derp.sh installer bash.
Now, I just need to get a bask script to turn that yaourt.log into a bash file. here's what I've got so far:
#!/bin/bash
#formatThis.sh
echo "yaourt -Syy --noconfirm ">derp.sh
while read line
do
COUNT=0
while ${line:COUNT}!="/"
do
COUNT+=1
done
COUNT+=1
COUNT2=0
while ${line:COUNT2}!=" "
do
COUNT2+=1
done
echo "${line:COUNT:(COUNT2-COUNT1)}">>derp.sh
echo "${line:COUNT:(COUNT2-COUNT1)}"
done
exit
And All that I get in derp.sh after running bash formatThis.sh yaourt.log is the simple yaourt -Syy --noconfirm that I start the file with.
Is there something I am completely missing here? I'm seeing plenty on reading files in the manuals, but I'm not finding where they tell me to do more.
And a kinda stupid, unrelated question: Are there any problems with migrating like this, so long as both systems are 64-bit, there's no multilib and/or wine complications, and no aur PKGBUILD changes are necessary to befuddle this operation?
Offline
yaourt doesn't have -Qq, like pacman?
Offline
Yes it does, now that you mention it. Wow, that was a bit of extra work for nothing. Thanks! That makes life a LOT easier!
But I still come back to my original question - how do I get the script to load the log file?
Offline
the log file is now just a list of package names, so just feed it to yaourt - you don't need a script for that.
Offline
the log file is now just a list of package names, so just feed it to yaourt - you don't need a script for that.
No, but it's a handy excuse for learning something useful, lol!
Offline
First of all, in your original question, to get the package names out (barring switches) you should just used a few "cut"s or a "sed" (I'm 100% positive there is an "awk" solution too).
cat log | cut -d'/' -f2 | cut -d' ' -f1
cat log | sed -r 's|.*/([^ ]+).*|\1|'
For why your bash script isn't working: by default read takes input from stdin. If you want to read from the log file you pass as an argument, try "cat"ing the file and pipe it into your loop.
cat "$1" | while read line
You can also redirect the file into the loop, like
done < "$1"
Your code to find where to cut the strings is very ugly, and probably very easy to forget what it was doing. It's not that hard to read, but when you can do it in one line, why bother? Besides that, nesting while loops is going to be very inefficient compared to cut/sed/awk.
Oh, and as for your final question: there is only one problem migrating like this. You lose the reason why you installed the packages -- as dependency, explicitly installed, etc. There is a tool somewhere for reconstructing the system directly from /var/log/pacman.log that is able to keep the install reason.
Last edited by jac (2012-07-08 12:49:52)
Offline
So much cat abuse... If a program can read from a pipe, it can read from a redirected file (or in the sed/awk/cut/grep/etc case it'll read a file as an argument)
Really, if your goal is just to transfer a list of packages...
# on the old install
pacman -Qqe | grep -xvFf <(pacman -Qqm) > pkglist
# and on the new install
pacman -S - < pkglist
This preserves explicitly installed packages that pacman knows about in sync DBs. dependencies will be filled in automatically, installed as dependencies.
Last edited by falconindy (2012-07-08 13:01:28)
Offline
So much cat abuse...
Haha, yeah. I don't particularly like cats much. At this stage for me it's just easier to not go back and delete my first instinct, and it helps if I need to add a command to the beginning of the pipe. Besides that I think it is clearer in the while read loop than finding out potentially much later the loop is reading from an argument and not stdin, but at least I gave both options for that one
It is good for Zazzman to know that the cat isn't necessary though.
Offline