Compare commits

..

12 Commits

Author SHA1 Message Date
4ab64cc1f1 Had to unescape EXEX_REPLACEMENT that would've prevented the desktop file from being valid 2023-11-10 18:15:22 -06:00
b44ac4e4b4 Had to add the install disk at the end of the grub-install lines (didn't see that until I tried to install 3 times) 2023-11-10 17:03:28 -06:00
fc290a728d Had to fix typo when installing networkmanager, caused it to fail to install NM and wpa_supplicant 2023-11-10 16:36:36 -06:00
9f6f752a8a Had to replace yes with the --noconfirm command because it didn't work for the gnome installation (as it asks for you to pick your subsystems) 2023-11-10 16:21:46 -06:00
8a6eccb884 Had to alter my 'yes' calls. As I had put un-needed flags '-y' that caused the utility to error out, causing my install to fail 2023-11-10 16:13:25 -06:00
2133dd9d47 Had to fix it YET again. I didn't realize that bash had -b to verify if something is a block device 2023-11-10 16:07:47 -06:00
6da855a05f Had to change -d flag to -f as I forgot disks are considered special files 2023-11-10 16:06:11 -06:00
c0bc51e9a7 Added a functionality to pass arguments to install script 2023-11-10 16:04:47 -06:00
8f3d8912f3 Had to remove a few copied lines from the embedded script (kinda caused it to fail to fully install a couple times before I caught it 2023-11-10 15:59:14 -06:00
1cdd9342f9 Had to fix a path mispelling, and had to fix multiline comments in embeded script 2023-11-10 15:49:51 -06:00
ac608174fa Made a few changes to allow for both BIOS and EFI installations 2023-11-10 15:35:16 -06:00
9b91217a09 Started making scripted installer for archlinux with explanation about every part of the process 2023-11-10 14:08:41 -06:00
4 changed files with 465 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "DnD-Tools"]
path = DnD-Tools
url = GS:tristan/dnd-tools

1
DnD-Tools Submodule

Submodule DnD-Tools added at 824d0e2487

283
bare-arch-install.sh Executable file
View File

@@ -0,0 +1,283 @@
#!/usr/bin/bash
# BEGIN: Variables
HOSTNAME="ExampleHostname"
BOOT_METHOD="${1:?"Boot method was not provided. (BIOS, EFI)"}"
BOOT_METHOD="${BOOT_METHOD^^}"
[[ ! "$BOOT_METHOD" =~ ^(EFI|BIOS)$ ]] && {
echo "Your boot method $BOOT_METHOD, is not acceptible. Please provide a vaild one"
exit
}
DISK="${2:?"Disk was not provided"}"
[[ ! -b $DISK ]] && {
echo "Your disk ($DISK) does not exist. Please provide a valid one"
exit
}
EFI_PARTITION=${DISK}1
SWAP_PARTITION=${DISK}2
ROOT_PARTITION=${DISK}3
## New Login creds for your new user and the root user
ROOT_PASSWORD="root"
NEW_USER="username"
NEW_PASSWORD="password"
TIMEZONE_INFO=America/Chicago
LOCALE=en_US.UTF-8
## Commands to create disks un-interactively with fdisk
## will clean up comments later with grep command
FORMAT_DISK_COMMANDS_BIOS="
# Create MBR partition table
o
# Create bios header (area where boot information is stored at the beginning of the disk)
n
# Create Primary partition (which is technically the default anyway)
p
# Press Enter to select default partition number
# Press Enter to select default starting sector
# Allocate 10 MB at beginning of disk for BIOS table (you will do nothing with it)
+10MiB
# Create Swap Partition
n
# Create Primary partition (which is technically the default anyway)
p
# Press Enter to select default partition number
# Press Enter to select default starting sector
# Allocate 8GiB for swap partition
+8GiB
# Set the type to Linux Swap (82)
t
# Press Enter to select the last partition
# Set to type 82
82
# Create Root Partition
n
# Set as Primary (default)
p
# Press Enter to select default partition number
# Press Enter to select default starting sector
# Press Enter to allocate rest of disk to root partition
# Sync changes to disk
w
"
FORMAT_DISK_COMMANDS_EFI="
# Create GPT partition table
g
# Create efi partition
n
# Enter to select default partition number
# Enter to select default first sector
# Allocate only 500 MiB for the efi partition
+500MiB
# Set partition type
t
# Set partition type to efi (1)
1
# Create Swap Partition
n
# Enter to select default partition number
# Enter to select default first sector
# Allocate 8 GiB to swap partition
+8GiB
## Set partition type to Linux Swap (19)
t
### Enter to select default (last) partition (2)
### Set Type to swap (19)
19
# Create root partition (doing single partition format)
n
# Enter to select default partition number
# Enter to select default first sector
# Press Enter to allocate remaining disk to your final partition
# No need to set partition type
# Write changes to disk
w
"
## Declaring a "named" variable allows me to access the correct commands without a conditional
declare -n FORMAT_DISK_COMMANDS="FORMAT_DISK_COMMANDS_${BOOT_METHOD}"
# END: Variables
# BEGIN: Work
## BEGIN: Pre-Chroot Work
### Format Disk
#### For this example I will be using a sata disk (/dev/sda)
COMMANDS="$(echo -e "$FORMAT_DISK_COMMANDS" | grep -v \#)"
fdisk $DISK <<< "$COMMANDS"
### Format EFI Partition
#### The efi partition (mounted at /boot/efi) Needs to be formatted as fat32
[[ "$BOOT_METHOD" == "EFI" ]] && mkfs.fat -F32 $EFI_PARTITION
### Format SWAP partition
mkswap $SWAP_PARTITION
### Activate swap partition
swapon $SWAP_PARTITION
### Format Root Partition
#### We will be formatting it with ext4 because that's the default for most use-cases, especially when new linux users are concerned
mkfs.ext4 $ROOT_PARTITION
### Mounting the root partition to begin setting up the partitions where they need to be
mount $ROOT_PARTITION /mnt
### Calling the --mkdir flag for mount to create the necessary directories so that it can mount
[[ "$BOOT_METHOD" == "EFI" ]] && mount $EFI_PARTITION --mkdir /mnt/boot/efi
### Using pacstrap to install the necessities to be able to get a chroot env
: "
base:
This is a meta-package. One that will handle installing many of the necessary programs to have a basic install of arch to chroot into
linux:
This is the actual kernel being installed. It will install the kernel & kernel-modules necessary to boot
linux-headers:
This is many other family of distros (Debian, RedHat, etc) would name linux-dev || linux-devel
This is a package that contains all of the kernel's header files for compiling modules for your distrobutions kernel.
linux-firmware:
This is another meta package that contains just about all of the firmware drivers you system may need. It is just a dump of firmware, not all of them will be needed for your system.
sudo:
A program needed for privelege escalation. Basically to provide a user of an admin group (most often wheel in most distrobutions) to be able to execute binaries that require root level permissions in you system.
Installing it here because it is not installed by default. An alternative is doas, a utility to perform the same funciton.
"
pacstrap /mnt base linux linux-headers linux-firmware sudo
## Setting up fstab
genfstab -U /mnt > /mnt/etc/fstab
INSTALL_SYSTEM="
# Setting the hostname of your machine
echo '$HOSTNAME' > /etc/hostname
# Setting timezone of the machine
ln -sf /usr/share/zoneinfo/$TIMEZONE_INFO /etc/localtime
# Setting LOCALE of machine (uncommenting the entry)
cp /etc/locale.gen{,-bak}
sed -i s'/\#$LOCALE/$LOCALE/' /etc/locale.gen
# Generate local
locale-gen
## Configure locale.conf
echo 'LANG=$LOCALE' > /etc/locale.conf
# Install and Enable Networking Systems
##
#networkmanager:
#This is the system that will handle all networking for your system, allowing you to setup profiles and otherwise automatically configure your network as needed.
#
#wpa_supplicant:
#This is the service/program that will manage supplication (aka wireless handshakes) between your device and your Access Point/Router
##
## Installing networking packages
pacman -S --noconfirm networkmanager wpa_supplicant
## Enabling systemd services
systemctl enable wpa_supplicant NetworkManager
## Installing bootloader
#grub:
#Grub is a bootloader. A program that helps you boot into an installed system
#
#It is what actually load your kernel and init-system via your install's specific efi file located somewhere in (/boo/efi/EFI)
#
#
#efibootmgr:
#Is a tool that is used to edit boot manager settings (primarily to delete and move boot options around)
### Do bootloader install
`
case "${BOOT_METHOD,,}" in
efi)
echo "pacman -S --noconfirm grub efibootmgr"
echo "grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot/efi $DISK"
;;
bios)
echo "pacman -S --noconfirm grub"
echo "grub-install --target=i386-pc --boot-directory=/boot $DISK"
;;
esac
`
## Create grub config
grub-mkconfig -o /boot/grub/grub.cfg
## gnome:
# This is the gnome desktop enviorment. It's the default choice for most distros by default (due to fewer release cycles, meaning distro maintainers don't have to work as much to maintain it for their distro).
#
# There are other choices:
# - KDE/Plasma
# - xfce4
# - lxde
# ...
#
#KDE is usually the next choice for those wanting to have a very easy to use and integrated desktop with a lot of customizability.
#
## gdm \"Gnome Desktop Manager\":
# This is the default desktop manager (login screen) for gnome. This just handles the login screen and starting up your desktop session & windowing system based off of your choices.
## Install desktop env
#pacman -S --noconfirm gnome
## Enable desktop manager/login-screen
#systemctl enable gdm
## Setting root password
echo -e '$ROOT_PASSWORD\n$ROOT_PASSWORD\n' | passwd
## Creating new user and setting password
useradd -m $NEW_USER
echo -e '$NEW_PASSWORD\n$NEW_PASSWORD\n' | passwd $NEW_USER
## Adding new user to wheel group to be able to use sudo
usermod -aG wheel $NEW_USER
## Setting up wheel group in sudoers
# I am doing it this way because it's not a good idea to edit /etc/sudoers non-interactively, as you can break sudo for all other users except root.
#
# sudo will load all definitions from /etc/sudoers.d/ and won't break if there is an error in the extra files (unlike if you edit /etc/sudoers directly)
echo '%wheel ALL=(ALL:ALL) ALL' > /etc/sudoers.d/wheel
"
arch-chroot /mnt /bin/bash <<< "$INSTALL_SYSTEM"
# END: Work

178
install-discord-linux.sh Executable file
View File

@@ -0,0 +1,178 @@
#!/usr/bin/bash
# BEGIN: Variables
ACTION=""
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+'
INSTALL_DIR=~/Downloads
EXISTING_INSTALL=$INSTALL_DIR/Discord
BUILD_FILE=$EXISTING_INSTALL/resources/build_info.json
PACKAGE_DOWNLOAD_URL_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz'
ICON_DIR=~/.icons
# END: Variables
# BEGIN: Helper Functions
function get_remote_version(){
local REMOTE_VERSION=`curl $DOWNLOAD_URL | grep -Eo $VERSION_REGEX | head -n 1`
if [[ "$REMOTE_VERSION" ]]; then
echo "$REMOTE_VERSION"
return 0
else
echo "error: remote version not found"
return 1
fi
}
function do_download(){
local VERSION="${1:?"do_download : Version was not provided"}"
## If the provided version doesn't match the format #.#.#
if [[ ! "$VERSION" =~ ^$VERSION_REGEX$ ]]; then
echo "do_download : the version ($VERSION) provided, does not match format $VERSION_REGEX."
exit 2
fi
## Making the URL to download the package
### replacing all {VERSION} in PACKAGE_DOWNLOAD_URL_BASE with $REMOTE_VERSION using string substitution
PACKAGE_DOWNLOAD_URL="${PACKAGE_DOWNLOAD_URL_BASE//\{VERSION\}/$REMOTE_VERSION}"
## Getting filename from url
### Removing all characters from the last / back to leave only the filename
FILENAME="${PACKAGE_DOWNLOAD_URL/*\/}"
## Downloading the discord package (tar.gz)
curl "$PACKAGE_DOWNLOAD_URL" -o "$FILENAME" >/dev/null
}
function update_desktop_file() {
## Desktop file in the current/new install
DESKTOP_FILE=$EXISTING_INSTALL/discord.desktop
## Escaped becuase it would mess up the replacement syntax
PATH_TO_REPLACE=\/usr\/bin
PATH_REPLACEMENT=$EXISTING_INSTALL
## Escaped becuase it would mess up the replacement syntax
EXEC_TO_REPLACE=\/usr\/share\/discord\/Discord
EXEC_REPLACEMENT=$EXISTING_INSTALL/Discord
## Loading the desktop file contents into a variable to use replacement without sed
DESKTOP_FILE_CONTENTS="$(<$DESKTOP_FILE)"
## Replacing Path
DESKTOP_FILE_CONTENTS="${DESKTOP_FILE_CONTENTS/$PATH_TO_REPLACE/$PATH_REPLACEMENT}"
## Replacing Exec
DESKTOP_FILE_CONTENTS="${DESKTOP_FILE_CONTENTS/$EXEC_TO_REPLACE/$EXEC_REPLACEMENT}"
## Pushing replacement values to desktop file
echo -e "$DESKTOP_FILE_CONTENTS" > $DESKTOP_FILE
}
function do_install() {
cd "$INSTALL_DIR"
REMOTE_VERSION=`get_remote_version`
do_download "$REMOTE_VERSION"
## Error handling in case curl couldn't do the download (or error in script)
if [[ -f $FILENAME ]]; then
tar xf "$FILENAME"
else
echo "$FILENAME failed to download. Exiting now"
exit 1
fi
update_desktop_file
## If your icon dir (configured above) exists in the env variable
if [[ "$XDG_DATA_DIRS" != *$ICON_DIR* ]]; then
export XDG_DATA_DIRS=$XDG_DATA_DIRS:$ICON_DIR
if [[ $SHELL == *bash ]]; then
echo 'export XDG_DATA_DIRS=$XDG_DATA_DIRS':$ICON_DIR > ~/.bashrc
else
echo 'export XDG_DATA_DIRS=$XDG_DATA_DIRS':$ICON_DIR > ~/.profile
fi
fi
[[ ! -d $ICON_DIR ]] && mkdir -p $ICON_DIR
cp $EXISTING_INSTALL/discord.png $ICON_DIR/
desktop-file-isntall $DESKTOP_FILE
}
function do_upgrade(){
cd "$INSTALL_DIR"
REMOTE_VERSION=`get_remote_version`
do_download "$REMOTE_VERSION"
## FILENAME provided by do_download
FILENAME="${FILENAME:?"do_upgrade : FILENAME not set by do_download"}"
tar xf "$FILENAME"
update_desktop_file
}
# END: Helper Functions
# BEGIN: Pre-Work Check
if [[ -d $EXISTING_INSTALL ]] && [[ -f $BUILD_FILE ]]; then
LOCAL_VERSION=`grep -Eo $VERSION_REGEX $BUILD_FILE`
else
ACTION=INSTALL
fi
REMOTE_VERSION=`curl $DOWNLOAD_URL | grep -Eo $VERSION_REGEX | head -n 1`
# END: Pre-Work Check
# BEGIN: Work
## If ACTION hasn't already been set
if [[ ! $ACTION ]]; then
## Use read to get version numbers in arrays
OIFS=$IFS
IFS='.'
read -a local_versions <<< "$LOCAL_VERSION"
read -a remote_versions <<< "$REMOTE_VERSION"
IFS=$OIFS
## Check if the remote version is greater than the local
for (( i=0; i<3; i++)); do
## If at any point the remote version is greater than the local this will break and set NEEDS_UPGRADE flag
if [[ ${local_versions[$i]} -lt ${remote_versions[$i]} ]]; then
ACTION=UPGRADE
break
fi
done
fi
case $ACTION in
INSTALL)
do_install
;;
UPGRADE)
do_upgrade
;;
esac
# END: Work