You are not logged in.

#1 2016-11-15 03:23:18

Zorbik
Member
Registered: 2016-08-09
Posts: 42

How to create Arch Install Script

I've installed Arch Linux on my laptop a LOT of times, sometimes for learning purposes, others because I broke my system too much.
I love the manual installation because of the amount of customization that Arch offers and I can make it something that truly fits my needs.
The only issue with manual installation is that it takes a LONG time to get a fully operational system up and running (I'm a little too obsessed with minor improvements to system security)
I would use someone else's install script but I feel like I don't have the same amount of control, plus where's the fun in that?
I wanted to challenge myself to see if I could cut down on the amount of time it takes to rebuild/configure my system by creating my own custom install script.
The only problem, I have no idea where to start. What kind of things do I have to consider when making this script?
Any tips on where to start are greatly appreciated.

Offline

#2 2016-11-18 08:40:07

j.pinje
Member
Registered: 2014-07-24
Posts: 7

Re: How to create Arch Install Script

Yuo can have a look at his script, I never used it but maybe it will help!

https://github.com/helmuthdu/aui


“I would love to change the world, but they won’t give me the source code”

Offline

#3 2016-11-18 08:54:58

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: How to create Arch Install Script

Just use the distribution tools instead of random scripts from the internet:

https://github.com/Earnestly/pkgbuilds/ … g/PKGBUILD


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#4 2016-11-18 09:41:40

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: How to create Arch Install Script

Alad, how is j.pinje's link any different from what you have linked. Both are random to anyone who isn't familiar with the tools involved. The OP asked for tips on where to get started with making a script and both of your links should be helpful for the purpose.

Offline

#5 2016-11-18 11:41:59

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: How to create Arch Install Script

Well, it's different in that you have a 4000* line bash script against a simple 80 line example of a format (PKGBUILD) every Arch user should be familiar with. If more explanation is needed, I'm happy to provide it.

* To put that number in context, that's about as high as makepkg itself.

Last edited by Alad (2016-11-18 11:47:11)


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#6 2016-12-14 23:13:49

Dokter Bibber
Member
Registered: 2016-09-19
Posts: 65

Re: How to create Arch Install Script

Zorbik wrote:

I've installed Arch Linux on my laptop a LOT of times,
.
.
Any tips on where to start are greatly appreciated.

Next time when you're about to install Arch :

First run the following command from terminal :

echo $HISTSIZE

If you're getting a low number like 500 or so, make Bash's history unlimited with the following :

HISTSIZE=-1; HISTFILESIZE=-1

This won't survive the first reboot (because you're still in the USB/DVD Live environment).
Also copy the file /root/.bashrc to a USB stick. (You might need it. See further down.)

Just before every reboot, copy your /root/.bash_history file to a USB stick (or anywhere that will still be there after a reboot or shutdown). Keep doing this until the installation is completely finished.
If after the first reboot you log in with a regular user account and sudo the commands, you should copy ~/.bash_history into safety from now on. Again, just before each reboot, and until the installation is completely finished.
Also copy .bash_history after the last command of the whole installation.
Prefix the copies with a sequence number. Something like .01-root-bash_history, .02-robert-bash_history, .03-robert-bash_history, etcetera. (Or not.)

After the first reboot only, and logged into your actual installed Arch for the first time, first thing to do is to make Bash's history permanently unlimited.
Open up ~/.bashrc and add (at the bottom) somewhere :

export HISTSIZE=-1
export HISTFILESIZE=-1

Do the same for /root/.bashrc. (Create the file if it doesn't exist by restoring the copy you made earlier to /root and make sure that it's owned by root:root. I had to do that each and every time..)

To make your huge Bash history more managable create (if not there) ~/.inputrc and copy the following piece of code into it.
If for example you want to recall a previous executed gconftool-2 command that you used, type the first few characters of the start of that previous command, for example type gconftool-2 and then use the up and down arrows to cycle through all previous commands starting with gconftool-2.
Use the left and right arrow keys on the currently retrieved command to further limit or increase the history you can scroll through. Only what's to the right of the cursor position will change when using the up and down arrow keys.
If your cursor is on a folder name of a path, only the remainder of the command which is to the right of that folder name will change when using the up and down arrow keys.

"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char

All the commands that you typed (good and failed) are in the copied .bash_history files.
The first copy (from when you were logged in as root in the Live environment) and the last copy (from when you were logged in as regular or root user in the shiny new Arch), stitched together, should contain every command from beginning to end.

Create a shell script file (.sh) with whatever name you like.
Add this at the start of the file. (You can also check $EUID instead of using the id command.) :

#!/bin/bash

# Is root running this script ?                    THIS CHECK SHOULD ALWAYS BE THE FIRST CODE THAT'S EXECUTED.
if [ "`id -u`" -ne 0 ]
then
  echo -e "\n\nRun this script as root!\n\n"
  exit -1
fi

Copy and paste the first copy (from when you were logged in as root in the Live environment) and then last copy (from when you were logged in as regular or root user in the shiny new Arch) of .bash_history after that.
Save and start cleaning up.
Afterwards you should make the script executable to run it.

This will not automate any manual modifications you have made to config files.
You will still have to do those.
Or use a combination of sed, awk, echo, and grep to automate configuration in your installer scripts.
This one is more dangerous :
Or restore the *.conf and *.rules files that were backed up in Part 1 below. (But always make copies before overwriting. If a config setting was dropped or renamed you will have at least some sort of fallback.)
Try not to restore desktop environment configuration files when you switch from one desktop to another.

And one last tip. Chop your script into pieces/steps.
And run them in sequence from a main script or manually/interactively from the command line.
It gives you more control.
I have my installation script chopped into 6 separate scripts. Down from 14 initially, mainly due to the disk preparation part.
Make sure to keep hard coding (of for example user names, paths, etcetera) to a minimum. Use variables instead of copy+pasting the same user name or partial path 10 or more times.

Part 1 : Script to incrementally backup files with rsync -avHEAX from :
/home : everything
/root : everything
/etc : mainly policykit *.rules files, X11 *.conf files, font *.conf files, entire lightdm folder.
/usr : entire xgreeters folder, gtk-3.0/settings.ini file.
/srv : git-repos, Apache folders, Nginx folders.
And various log files into a Miscellaneous folder.

Part 2 : Script to partition, format, and then create the LVM layer.

Part 3 : Script to do the base Arch installation.

I make a full backup at this point, so that in the future I can restore the base Arch, then update it (pacman -Syu) and then start from part 4.

Part 4 : Script to install GPU drivers, X, and Alsa, etcetera.

Part 5 : Script to install a desktop environment, or window manager. I have one script for Gnome only. Another script for KDE only. Etcetera.

Part 6 : Script to install all programs/packages you always install. This will probably be a different script for each desktop environment.

This was from the top of my head and reflects what I'm doing. This might not be suited to you at all though.

Last edited by Dokter Bibber (2016-12-15 00:22:04)

Offline

#7 2016-12-15 06:13:02

woodape
Member
Registered: 2015-03-25
Posts: 159

Re: How to create Arch Install Script

I wrote a script like this to install arch to a USB stick. It really isn't so hard, just go through the installation guide on the wiki and put the commands into a bash script. You should then have a different script to install all the programs you need. For instance if you have a file "my_packages" with:

gvim
tmux
bspwm
...

you could do

cat "my_packages" | xargs sudo pacman -S --noconfirm

to install them all. Then yet another script to install your dotfiles, which hopefully you're version controlling with git.

So 3 scripts, one for base install, one containing the packages you want - one per line, and another for dotfiles. The only thing causing a time constraint is your internet connection.

Offline

#8 2016-12-21 09:53:52

severach
Member
Registered: 2015-05-23
Posts: 192

Re: How to create Arch Install Script

I keep all my install lines in a text file. I enable sshd on the ISO and log in with PuTTY and paste the lines in. My lines include custom patches and instructions where needed.

Offline

Board footer

Powered by FluxBB