lavabit / robox

The tools needed to robotically create/configure/provision a large number of operating systems, for a variety of hypervisors, using packer.
626 stars 139 forks source link

Docs request: how to override env vars #176

Open danielhoherd opened 3 years ago

danielhoherd commented 3 years ago

https://github.com/lavabit/robox/blob/a0d6f21eb4cb971f8f2560d1ac59aad7baaf49c8/scripts/ubuntu1604/lineage.sh#L459

The referenced line asks us to "Override the above environment variables in your Vagrantfile to alter the build configuration", but for the life of me I cannot figure out how to actually do this. It seems way more elegant than my solution, which is to vagrant ssh in, sudo pkill -f lineage-build.sh edit /home/vagrant/lineage-build.sh to have the right env vars, then re-run vagrant init.

I would love to see a documentation example on how to accomplish what we are instructed to do. Bonus points if the instruction is updated to contain a hyperlink to the documentation example, EG a https://git.io link to the lavabit/robox wiki entry.

ladar commented 3 years ago

@danielhoherd hello. It's been so long that I don't recall what I intended when I set it up... but I was able to whip up a quick example. Basically you just need to set the environment variables inside the guest before the lineage-build.sh is run. The tricky part making that happen before the default embedded provisioning logic gets run. The easiest method is like so:

vagrant init lineage/lineage && vagrant up --provider=libvirt --no-provision && vagrant ssh --command 'export DEVICE="pro1"; export BRANCH="lineage-17.1"; export VENDOR="fxtec"; /home/vagrant/lineage-build.sh'

That is what I generally do, because I'm want to try building a different branch, etc. But that won't preserve the config/settings for future use, so I understand the desire to have the logic self-contained inside the Vagrangfile. To do that, you'll need to Vagrantfile that loos something like:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "lineage/lineage"
  config.vm.boot_timeout = 1800
  config.vm.ignore_box_vagrantfile = true
  config.vm.usable_port_range = 20000..30000
  config.vm.synced_folder ".", "/vagrant", disabled: true

  config.vm.provision "shell", run: "always", inline: <<-SHELL
    su -l vagrant -c 'export DEVICE="pro1"; export BRANCH="lineage-17.1"; export VENDOR="fxtec"; /home/vagrant/lineage-build.sh'
  SHELL

  config.vm.provider :libvirt do |v, override|
    v.driver = "kvm"
    v.video_vram = 256
    v.memory = 8192
    v.cpus = 6
  end

end

It's worth noting that when I created the box script, I intended it to be as easy as:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "lineage/lineage"
  config.vm.provision "shell", run: "always", inline: <<-SHELL
    su -l vagrant -c 'export DEVICE="pro1"; export BRANCH="lineage-17.1"; export VENDOR="fxtec"; /home/vagrant/lineage-build.sh'
  SHELL

end

But that doesn't appear to work. I'm wondering whether "naming" the embedded provisioner would allow the user to override, or even better, run provisioning commands before, the embedded provisioner. If you could write the environment variables to the vagrant user .bashrc file, then they should get picked up when the script gets run. But don't have the time right now to play with it.

Once upon a time I had great plans for the Lineage boxes. I wanted to embed the blobs for a variety of common/popular dev phones, so users could build ROMs using Vagrant one liners. My intention was to also create device specific boxes, like the linegage-nash variant, which would compile for a specific by default. But I never found the time to make all that happen. I never even finished the nash variant (the keyboard Moto Mod I was waiting on got cancelled), so I never finished it.

Despite the large number of downloads, I never got much feedback from the community on whether the boxes were helpful, and/or being used. I've heard that a lot of the downloads are actually being used for other things (besides compiling Lineage), and they get used because they have the right combination of dependencies pre-installed. Naturally, if there is interest from the communit, I would welcome help/pull requests which improve it.

As for my current plans. I'm waiting on Sprint/T-mobile to let me activate my Fxtec Pro1. I tried this summer, but the Sprint system wouldn't let allot me to activate the phone because the IMEI wasn't on their approved list. I tried again in August, once the Sprint system was merged with the T-mobile system, but didn't get any further. (T-mobile is GSM, but because I have a "Sprint" account they can't give me a GSM SIM card for it). I haven't had a chance to try again. If I'm ever able to activate the phone, I plan to update the Lineage boxes so they compile a ROMs for the Pro1 instead of the XT897.

danielhoherd commented 3 years ago

@ladar Thanks for the detailed feedback! I was unaware of vagrant up --no-provision, but that seems like a great middle ground, and will accomplish what I want just fine.

It's a bit remarkable that vagrant doesn't appear to have a mechanism to inherit environment variables into provisioners.

I've never installed a custom ROM onto an Android device before, but I have this SM-T700 sitting around and your software is the best setup I've found for building linageOS for it, so thank you for building this and making it public. I wish more projects had a simple vagrant up, docker-compose up, etc. step available for easily reproducible builds like this does.

ladar commented 3 years ago

I used to have an SM-T700... until it died. I replaced it with an S2 ... which still works, barely. Part of the reason I picked it was because someday I might want to put Lineage on it.

Like I said, I wish I had the time to gather up the blobs for more platforms, and embed in the box image so people would build images easily. But there isn't really a good place to get them... good as in trust that they aren't trojaned, etc. Yes you can extract them from the official ROM, but that is quite the pain as well.

Like I said, if you're willing to take the lead, I'd welcome PR requests which improve the embedded build script, and add more blobs, etc to the box image so builds really do work properly.

brokep commented 3 years ago

@ladar Thanks for the detailed feedback! I was unaware of vagrant up --no-provision, but that seems like a great middle ground, and will accomplish what I want just fine.

It's a bit remarkable that vagrant doesn't appear to have a mechanism to inherit environment variables into provisioners.

I've never installed a custom ROM onto an Android device before, but I have this SM-T700 sitting around and your software is the best setup I've found for building linageOS for it, so thank you for building this and making it public. I wish more projects had a simple vagrant up, docker-compose up, etc. step available for easily reproducible builds like this does.

I used to be a ROM addict... if you'd like to sync up and work together on this i'd be happy to. Sometimes Samsung phones can be a pain with their "secure bootloader" I've found Pixel 3 or Pixel 3a (available of swappa.com for ~100USD) are great development phones.