Help me do this script right

@admindev @cekim @鳥の鞄

Alright I want to do this bash script right. So if I fuck up linux mint I can just use a script and get back to my working environment LOL. I have made a lot of hodge podge crappy scripts before and would appreciate help making a good one with proper form here. My knowledge of bash is about as good as my knowledge of making Batch files on windows HAH.

So I am going to describe what I do to setup my system. I realize there will be some manual steps left over because they require selection in a GUI but I would like to automate the bulk of it.

The process:

First thing I like to do before anything is go into the GUI and make my sources selection and configuration the following. It just speeds things up. I want to know if there is a way to do this in terminal? I enable source packages so I can do build-dep with ease

The next thing I like to do is making my environment in the terminal a little more easy. I like it this way. So I go in and edit bashrc (/etc/bashrc and .bashrc) but is there a way to just do one? and source the other? I guess there might be. I place the following at the end:

export EDITOR=nano
export VISUAL=nano

Then I edit the sudo file via sudo nano /etc/sudoers and I make sure it reflects this

Defaults        env_reset
Defaults        pwfeedback
Defaults        insults

Regulatory is never set properly so I have to go in and sudo nano /etc/default/crda and make sure its equal to

US

Now for my sysctl tweaks obviously I sudo nano /etc/sysctl.conf and add this to the end.

# Maximum socket buffer size
net.core.optmem_max = 134217728

# Maximum receive socket buffer size
net.core.rmem_max = 134217728 

# Maximum send socket buffer size
net.core.wmem_max = 134217728 

# Minimum, initial and max TCP Receive buffer size in Bytes
net.ipv4.tcp_rmem = 4096 33554432 134217728 

# Minimum, initial and max buffer space allocated
net.ipv4.tcp_wmem = 4096 33554432 134217728 

# Minimum, initial and max buffer space allocated
net.ipv4.tcp_mem = 6672016 6682016 7185248

# Maximum number of packets queued on the input side
net.core.netdev_max_backlog = 300000 

# Auto tuning
net.ipv4.tcp_moderate_rcvbuf =1

# Don't cache ssthresh from previous connection
net.ipv4.tcp_no_metrics_save = 1

# Congestion Control
net.ipv4.tcp_congestion_control=reno

# If you are using jumbo frames set this to avoid MTU black holes.
net.ipv4.tcp_mtu_probing = 1

# Define mine free vm memory
vm.min_free_kbytes = 524288

# Extra TCP Tweaks
net.ipv4.tcp_sack = 1
net.ipv4.tcp_timestamps = 1
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_low_latency = 1
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_rfc1337=1
net.ipv4.tcp_workaround_signed_windows=1
net.ipv4.tcp_window_scaling=1
net.ipv4.ip_no_pmtu_disc=0
net.ipv4.tcp_mtu_probing=1

# Enable for wireless internet links only (Wireless Fiber for ex)
# net.ipv4.tcp_frto=2
# net.ipv4.tcp_frto_response=2
# Set swappiness. Unused RAM is wasted RAM
vm.swappiness=10

Some audio tweaks are next via sudo nano /etc/pulse/daemon.conf

default-sample-format = s24le
default-sample-rate = 96000
alternate-sample-rate = 48000
default-sample-channels = 2
default-channel-map = front-left,front-right
default-fragments = 2
default-fragment-size-msec = 125
resample-method = soxr-vhq
enable-lfe-remixing = no
high-priority = yes
nice-level = -11
realtime-scheduling = yes
realtime-priority = 9
rlimit-rtprio = 9
daemonize = no

and sudo nano /etc/asound.conf I only do 2.1 setups so I slave alsa to pulse.

# Use PulseAudio plugin hw
pcm.!default {
   type plug
   slave.pcm hw
}

Now I build my environment and execute the following

sudo dpkg --add-architecture i386
sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade -y
sudo apt build-dep curl

sudo apt install build-essential cmake g++ dkms acpid lshw software-properties-common llvm clang amd64-microcode gcc-multilib curl wget apt-transport-https dirmngr git linux-headers-$(uname -r) mint-meta-codecs vlc gimp libreoffice openjdk-11* numlockx geda kicad freecad ngspice dconf-cli uuid-runtime

sudo apt build-dep linux

Here is where shit starts breaking and always requires fix broken. I break it out into steps because having multiple broken packages is a headache LOL.

Starting with the Atom editor that I really love: (it breaks due to missing libraries that you think would be auto installed but require the last command.

wget https://atom.io/download/deb -O atom.deb
sudo dpkg -i atom.deb
sudo apt install --fix-broken -y

Spotify

curl -sS https://download.spotify.com/debian/pubkey.gpg | sudo apt-key add - 
echo "deb http://repository.spotify.com stable non-free" | sudo tee /etc/apt/sources.list.d/spotify.list
sudo apt-get update && sudo apt-get install -y spotify-client
sudo apt install --fix-broken -y

Google Chrome

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt update && sudo apt install -y google-chrome-stable

Minecraft

wget -O ~/Minecraft.deb https://launcher.mojang.com/download/Minecraft.deb
sudo dpkg -i Minecraft.deb
sudo apt install --fix-broken -y

Microsoft Fonts with automation because screw it stopping my terminal installation.

echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections
sudo apt-get install ttf-mscorefonts-installer -y

Tusk because I do use evernote

The issue here is how to grab the latest build everytime?

wget -O tusk.deb https://github.com/klaussinani/tusk/releases/download/v0.23.0/tusk_0.23.0_amd64.deb
sudo dpkg -i tusk.deb
sudo apt install --fix-broken -y

Set some firewall settings

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw enable

Install veracrypt because I used encrypted containerization over encrypted hard drives.

sudo add-apt-repository -y ppa:unit193/encryption
sudo apt update && sudo apt install -y veracrypt

Okay so this is where Its harder. I want to automate the installation of the latest but I am not sure how to do this?

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
### Need a way to install the latest complete package including nvidia settings
sudo ubuntu-drivers autoinstall

This never installs nvidia stuff properly. It always forgets packages and then sometimes when you install the package the whole system breaks or it will forget DKMS. I hate how cumbersome this is.
Now:
sudo reboot

Verilog Tools

sudo apt install iverilog verilog gtkwave -y

Install terminal drop down and themes

sudo apt install guake -y
bash -c  "$(wget -qO- https://git.io/vQgMr)"
pass 56 183 164 31

How can I automate passing those in ?

This is where I just have to manually grab stuff:

Themes:
Cinnamon: https://www.cinnamon-look.org/p/1247470/
Icon: https://www.cinnamon-look.org/s/Cinnamon/p/1279924

Finally ending with:

sudo apt autoremove -y && sudo apt autoclean -y && sudo apt clean -y

Its a lot of stuff but it setups up linux the way I like it and the remainder is some light GUI customization which is easy. I just kind of want to step through from the beginning of how to do this with “good form”.

Any help would be appreciated. Step by step so I can learn properly.

I obviously start with

#!/bin/bash

I think this is simply /etc/apt/sources.list so uncomment/edit the required lines

1 Like

Okay awesome I will look into this perhaps having a file in the directory of the script ready to overwrite it? Or is that a bad idea?

just use sed to uncomment the required line and throw an error if it doesnt find it

1 Like

Copy that gonna man sed to understand the entire command.