Change lsb-release contents using a script [Solved]

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
jand

Change lsb-release contents using a script [Solved]

Post by jand »

I am trying to write a script to automate the software installation process on new Mint (Cinnamon) installations. So after I added some PPAs and repos and stuff, I am stuck at the point where I need to temporarily alter the contents of /etc/lsb-release file in order to launch the Intel Graphics Driver update utility and install the drivers.

echo and cat commands can't be used with sudo to clear the contents of the lsb-release file, althought can be used when I switch to root. All I want to do is to clear all text and add Ubuntu's data:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"
So can someone pretty please help me with this problem? I am sure that's an easy thing to do with sed but I'm probably too stupid to find out how...

Also, is there a way to pause the script until after the Intel drivers are installed, the utility's window is closed and the original lsb-release file restored?

This is what I have so far and what I'm trying to achieve:

Code: Select all

#Intel Graphics Driver update utility
echo "deb https://download.01.org/gfx/ubuntu/14.04/main trusty main" | sudo tee /etc/apt/sources.list.d/intellinuxgraphics.list
wget --no-check-certificate https://download.01.org/gfx/RPM-GPG-KEY-ilg -O - | sudo apt-key add -
sudo apt-get update && sudo apt-get install intel-linux-graphics-installer -y
sudo cp /etc/lsb-release /etc/lsb-release.bak
????? <--- alter contents of /etc/lsb-release
sudo intel-linux-graphics-installer  <--- Pause script, open window & install drivers
sudo cp /etc/lsb-release.bak /etc/lsb-release

...Script continues with other stuff...
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
kurotsugi

Re: Change lsb-release contents using a script

Post by kurotsugi »

Code: Select all

#first of all, replace cp with mv.
mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo "DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"" > /etc/apt/sources.list
the > command works similar with tee which you used above. as for the other question, the easiest way to pause the script is using 'sleep <time in second>' command but I'm not sure if it will work with your script design.
jand

Re: Change lsb-release contents using a script

Post by jand »

Thanks for your input, kurotsugi. (no pun intended :P)
Unfortunately your command won't work because 'sudo echo' is a no go in Ubuntu. Also the distro identifiers have to go in /etc/lsb-release.
Anyway, I solve it using sudo sh -c 'echo... which also allowed me to replace tee with >.

So (if anyone interested) the section of the script for installing the Intel's drivers is:

Code: Select all

sudo sh -c 'echo "deb https://download.01.org/gfx/ubuntu/14.04/main trusty main" > /etc/apt/sources.list.d/intellinuxgraphics.list'
wget --no-check-certificate https://download.01.org/gfx/RPM-GPG-KEY-ilg -O - | sudo apt-key add -
sudo apt-get update && sudo apt-get install intel-linux-graphics-installer -y
sudo cp /etc/lsb-release /etc/lsb-release.bak
sudo sh -c 'echo "DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"" > /etc/lsb-release'
sudo intel-linux-graphics-installer
sudo cp /etc/lsb-release.bak /etc/lsb-release
The good thing is that the rest of the script is not executing when the Intel app's window is open, so you have all the time in the world to install the drivers before the /etc/lsb-release changes back to Mint's default.
(You also have to add this section at the very beginning or near the end of the script so you won't have to wait for this part to execute or stall the whole script if you are afk.)

Thanks again.
Locked

Return to “Scripts & Bash”