Skip to content

Commit

Permalink
added shellcheck in workflow and updated all sh files
Browse files Browse the repository at this point in the history
  • Loading branch information
mfgbhatti authored and picodotdev committed Aug 31, 2022
1 parent 8325214 commit cc78804
Show file tree
Hide file tree
Showing 31 changed files with 502 additions and 419 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

name: Shellcheck
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
16 changes: 10 additions & 6 deletions alis-cloud-init-ssh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ VM_TYPE="virtualbox"
VM_NAME="Arch Linux"
CONFIG_FILE_SH=""

while getopts "b:c:i:t:n:" arg; do
while getopts "b:c:i:t:n:u:" arg; do
case $arg in
b)
BRANCH="$OPTARG"
Expand All @@ -29,26 +29,30 @@ while getopts "b:c:i:t:n:" arg; do
u)
GITHUB_USER=${OPTARG}
;;
*)
echo "Unknown option: $arg"
exit 1
;;
esac
done

if [ "$BRANCH" == "sid" ]; then
BRANCH_QUALIFIER="-sid"
fi

if [ "$IP_ADDRESS" == "" -a "$VM_TYPE" != "" -a "$VM_NAME" != "" ]; then
if [ "$IP_ADDRESS" == "" ] && [ "$VM_TYPE" != "" ]&& [ "$VM_NAME" != "" ]; then
IP_ADDRESS=$(VBoxManage guestproperty get "${VM_NAME}" "/VirtualBox/GuestInfo/Net/0/V4/IP" | cut -f2 -d " ")
fi

set -o xtrace
ssh-keygen -R "$IP_ADDRESS"
ssh-keyscan -H "$IP_ADDRESS" >> ~/.ssh/known_hosts

ssh -t -i cloud-init/alis.key root@$IP_ADDRESS "bash -c \"curl -sL https://raw.githubusercontent.com/${GITHUB_USER}/alis/${BRANCH}/download${BRANCH_QUALIFIER}.sh | bash\""
ssh -t -i cloud-init/alis.key root@"$IP_ADDRESS" "bash -c \"curl -sL https://raw.githubusercontent.com/${GITHUB_USER}/alis/${BRANCH}/download${BRANCH_QUALIFIER}.sh | bash\""

if [ -z "$CONFIG_FILE_SH" ]; then
ssh -t -i cloud-init/alis.key root@$IP_ADDRESS
ssh -t -i cloud-init/alis.key root@"$IP_ADDRESS"
else
ssh -t -i cloud-init/alis.key root@$IP_ADDRESS "bash -c \"configs/$CONFIG_FILE_SH\""
ssh -t -i cloud-init/alis.key root@$IP_ADDRESS "bash -c \"./alis.sh -w\""
ssh -t -i cloud-init/alis.key root@"$IP_ADDRESS" "bash -c \"configs/$CONFIG_FILE_SH\""
ssh -t -i cloud-init/alis.key root@"$IP_ADDRESS" "bash -c \"./alis.sh -w\""
fi
120 changes: 62 additions & 58 deletions alis-commons.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/usr/bin/env bash
# shellcheck disable=SC2034,SC2001,SC2155,SC2153,SC2143
# SC2034: foo appears unused. Verify it or export it.
# SC2001: See if you can use ${variable//search/replace} instead.
# SC2155 Declare and assign separately to avoid masking return values
# SC2153: Possible Misspelling: MYVARIABLE may not be assigned. Did you mean MY_VARIABLE?
# SC2143: Use grep -q instead of comparing output with [ -n .. ].

set -eu

# Arch Linux Install Script (alis) installs unattended, automated
Expand Down Expand Up @@ -63,7 +70,7 @@ function check_variables_list() {
local REQUIRED="$4"
local SINGLE="$5"

if [ "$REQUIRED" == "" -o "$REQUIRED" == "true" ]; then
if [ "$REQUIRED" == "" ] || [ "$REQUIRED" == "true" ]; then
check_variables_value "$NAME" "$VALUE"
fi

Expand All @@ -72,7 +79,7 @@ function check_variables_list() {
exit 1
fi

if [ "$VALUE" != "" -a -z "$(echo "$VALUES" | grep -F -w "$VALUE")" ]; then
if [ "$VALUE" != "" ] && [ -z "$(echo "$VALUES" | grep -F -w "$VALUE")" ]; then #SC2143
echo "$NAME environment variable value [$VALUE] must be in [$VALUES]."
exit 1
fi
Expand Down Expand Up @@ -101,13 +108,12 @@ function check_variables_size() {

function configure_network() {
if [ -n "$WIFI_INTERFACE" ]; then
iwctl --passphrase "$WIFI_KEY" station $WIFI_INTERFACE connect "$WIFI_ESSID"
iwctl --passphrase "$WIFI_KEY" station "$WIFI_INTERFACE" connect "$WIFI_ESSID"
sleep 10
fi

# only one ping -c 1, ping gets stuck if -c 5
ping -c 1 -i 2 -W 5 -w 30 $PING_HOSTNAME
if [ $? -ne 0 ]; then
if ! ping -c 1 -i 2 -W 5 -w 30 "$PING_HOSTNAME"; then
echo "Network ping check failed. Cannot continue."
exit 1
fi
Expand All @@ -120,33 +126,33 @@ function facts_commons() {
BIOS_TYPE="bios"
fi

if [ -f "$ALIS_ASCIINEMA_FILE" -o -f "$RECOVERY_ASCIINEMA_FILE" ]; then
if [ -f "$ALIS_ASCIINEMA_FILE" ] || [ -f "$RECOVERY_ASCIINEMA_FILE" ]; then
ASCIINEMA="true"
else
ASCIINEMA="false"
fi

if [ -n "$(lscpu | grep GenuineIntel)" ]; then
if lscpu | grep -q "GenuineIntel"; then
CPU_VENDOR="intel"
elif [ -n "$(lscpu | grep AuthenticAMD)" ]; then
elif lscpu | grep -q "AuthenticAMD"; then
CPU_VENDOR="amd"
fi

if [ -n "$(lspci -nn | grep "\[03" | grep -i intel)" ]; then
if lspci -nn | grep "\[03" | grep -qi "intel"; then
GPU_VENDOR="intel"
elif [ -n "$(lspci -nn | grep "\[03" | grep -i amd)" ]; then
elif lspci -nn | grep "\[03" | grep -qi "amd"; then
GPU_VENDOR="amd"
elif [ -n "$(lspci -nn | grep "\[03" | grep -i nvidia)" ]; then
elif lspci -nn | grep "\[03" | grep -qi "nvidia"; then
GPU_VENDOR="nvidia"
elif [ -n "$(lspci -nn | grep "\[03" | grep -i vmware)" ]; then
elif lspci -nn | grep "\[03" | grep -qi "vmware"; then
GPU_VENDOR="vmware"
fi

if [ -n "$(systemd-detect-virt | grep -i oracle)" ]; then
if systemd-detect-virt | grep -qi "oracle"; then
VIRTUALBOX="true"
fi

if [ -n "$(systemd-detect-virt | grep -i vmware)" ]; then
if systemd-detect-virt | grep -qi "vmware"; then
VMWARE="true"
fi

Expand All @@ -169,14 +175,14 @@ function init_log_file() {
local ENABLE="$1"
local FILE="$2"
if [ "$ENABLE" == "true" ]; then
exec &> >(tee -a $FILE)
exec &> >(tee -a "$FILE")
fi
}

function pacman_uninstall() {
local ERROR="true"
set +e
IFS=' ' local PACKAGES=($1)
IFS=' ' local PACKAGES="$1"
local PACKAGES_UNINSTALL=()
for PACKAGE in "${PACKAGES[@]}"
do
Expand All @@ -186,12 +192,11 @@ function pacman_uninstall() {
local PACKAGES_UNINSTALL+=("$PACKAGE")
fi
done
if [ -z "${PACKAGES_UNINSTALL[@]}" ]; then
if [ -z "${PACKAGES_UNINSTALL[*]}" ]; then
return
fi
local COMMAND="pacman -Rdd --noconfirm ${PACKAGES_UNINSTALL[@]}"
execute_sudo "$COMMAND"
if [ $? == 0 ]; then
local COMMAND="pacman -Rdd --noconfirm ${PACKAGES_UNINSTALL[*]}"
if execute_sudo "$COMMAND"; then
local ERROR="false"
fi
set -e
Expand All @@ -203,12 +208,11 @@ function pacman_uninstall() {
function pacman_install() {
local ERROR="true"
set +e
IFS=' ' local PACKAGES=($1)
IFS=' ' local PACKAGES="$1"
for VARIABLE in {1..5}
do
local COMMAND="pacman -Syu --noconfirm --needed ${PACKAGES[@]}"
execute_sudo "$COMMAND"
if [ $? == 0 ]; then
local COMMAND="pacman -Syu --noconfirm --needed ${PACKAGES[*]}"
if execute_sudo "$COMMAND"; then
local ERROR="false"
break
else
Expand All @@ -228,12 +232,11 @@ function aur_install() {
if [ "$AUR_COMMAND" != "0" ]; then
aur_command_install "$USER_NAME" "$AUR_PACKAGE"
fi
IFS=' ' local PACKAGES=($1)
IFS=' ' local PACKAGES="$1"
for VARIABLE in {1..5}
do
local COMMAND="$AUR_COMMAND -Syu --noconfirm --needed ${PACKAGES[@]}"
execute_aur "$COMMAND"
if [ $? == 0 ]; then
local COMMAND="$AUR_COMMAND -Syu --noconfirm --needed ${PACKAGES[*]}"
if execute_aur "$COMMAND"; then
local ERROR="false"
break
else
Expand All @@ -250,20 +253,20 @@ function aur_command_install() {
pacman_install "git"
local USER_NAME="$1"
local COMMAND="$2"
execute_aur "rm -rf /home/$USER_NAME/.alis && mkdir -p /home/$USER_NAME/.alis/aur && cd /home/$USER_NAME/.alis/aur && git clone https://aur.archlinux.org/$COMMAND.git && (cd $COMMAND && makepkg -si --noconfirm) && rm -rf /home/$USER_NAME/.alis"
execute_aur "rm -rf /home/$USER_NAME/.alis && mkdir -p /home/$USER_NAME/.alis/aur && cd /home/$USER_NAME/.alis/aur && git clone https://aur.archlinux.org/${COMMAND}.git && (cd $COMMAND && makepkg -si --noconfirm) && rm -rf /home/$USER_NAME/.alis"
}

function systemd_units() {
IFS=' ' local UNITS=($SYSTEMD_UNITS)
for U in ${UNITS[@]}; do
IFS=' ' local UNITS="$SYSTEMD_UNITS"
for U in "${UNITS[@]}"; do
local ACTION=""
local UNIT=${U}
if [[ $UNIT == -* ]]; then
local ACTION="disable"
local UNIT=$(echo $UNIT | sed "s/^-//g")
local UNIT=${UNIT//^-/}
elif [[ $UNIT == +* ]]; then
local ACTION="enable"
local UNIT=$(echo $UNIT | sed "s/^+//g")
local UNIT=${UNIT//^+/}
elif [[ $UNIT =~ ^[a-zA-Z0-9]+ ]]; then
local ACTION="enable"
local UNIT=$UNIT
Expand All @@ -278,7 +281,7 @@ function systemd_units() {
function execute_flatpak() {
local COMMAND="$1"
if [ "$SYSTEM_INSTALLATION" == "true" ]; then
arch-chroot ${MNT_DIR} bash -c "$COMMAND"
arch-chroot "$MNT_DIR" bash -c "$COMMAND"
else
bash -c "$COMMAND"
fi
Expand All @@ -287,9 +290,9 @@ function execute_flatpak() {
function execute_aur() {
local COMMAND="$1"
if [ "$SYSTEM_INSTALLATION" == "true" ]; then
arch-chroot ${MNT_DIR} sed -i 's/^%wheel ALL=(ALL:ALL) ALL$/%wheel ALL=(ALL:ALL) NOPASSWD: ALL/' /etc/sudoers
arch-chroot ${MNT_DIR} bash -c "echo -e \"$USER_PASSWORD\n$USER_PASSWORD\n$USER_PASSWORD\n$USER_PASSWORD\n\" | su $USER_NAME -s /usr/bin/bash -c \"$COMMAND\""
arch-chroot ${MNT_DIR} sed -i 's/^%wheel ALL=(ALL:ALL) NOPASSWD: ALL$/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
arch-chroot "$MNT_DIR" sed -i 's/^%wheel ALL=(ALL:ALL) ALL$/%wheel ALL=(ALL:ALL) NOPASSWD: ALL/' /etc/sudoers
arch-chroot "$MNT_DIR" bash -c "echo -e $USER_PASSWORD\n$USER_PASSWORD\n$USER_PASSWORD\n$USER_PASSWORD\n | su $USER_NAME -s /usr/bin/bash -c $COMMAND"
arch-chroot "$MNT_DIR" sed -i 's/^%wheel ALL=(ALL:ALL) NOPASSWD: ALL$/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
else
bash -c "$COMMAND"
fi
Expand All @@ -298,7 +301,7 @@ function execute_aur() {
function execute_sudo() {
local COMMAND="$1"
if [ "$SYSTEM_INSTALLATION" == "true" ]; then
arch-chroot ${MNT_DIR} bash -c "$COMMAND"
arch-chroot "$MNT_DIR" bash -c "$COMMAND"
else
sudo bash -c "$COMMAND"
fi
Expand All @@ -308,15 +311,15 @@ function execute_user() {
local USER_NAME="$1"
local COMMAND="$2"
if [ "$SYSTEM_INSTALLATION" == "true" ]; then
arch-chroot ${MNT_DIR} bash -c "su $USER_NAME -s /usr/bin/bash -c \"$COMMAND\""
arch-chroot "$MNT_DIR" bash -c "su $USER_NAME -s /usr/bin/bash -c \"$COMMAND\""
else
bash -c "$COMMAND"
fi
}

function do_reboot() {
umount -R ${MNT_DIR}/boot
umount -R ${MNT_DIR}
umount -R "$MNT_DIR"/boot
umount -R "$MNT_DIR"
reboot
}

Expand Down Expand Up @@ -411,44 +414,45 @@ function partition_options() {
function partition_mount() {
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
# mount subvolumes
mount -o "subvol=${BTRFS_SUBVOLUME_ROOT[1]},$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" ${MNT_DIR}
mkdir -p ${MNT_DIR}/boot
mount -o "$PARTITION_OPTIONS_BOOT" "$PARTITION_BOOT" ${MNT_DIR}/boot
mount -o "subvol=${BTRFS_SUBVOLUME_ROOT[1]},$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" "$MNT_DIR"
mkdir -p "$MNT_DIR"/boot
mount -o "$PARTITION_OPTIONS_BOOT" "$PARTITION_BOOT" "$MNT_DIR"/boot
for I in "${BTRFS_SUBVOLUMES_MOUNTPOINTS[@]}"; do
IFS=',' SUBVOLUME=($I)
if [ ${SUBVOLUME[0]} == "root" ]; then
IFS=',' SUBVOLUME=("$I")
if [ "${SUBVOLUME[0]}" == "root" ]; then
continue
fi
if [ ${SUBVOLUME[0]} == "swap" -a -z "$SWAP_SIZE" ]; then
if [ "${SUBVOLUME[0]}" == "swap" ] && [ -z "$SWAP_SIZE" ]; then
continue
fi
if [ ${SUBVOLUME[0]} == "swap" ]; then
mkdir -p -m 0755 "${MNT_DIR}${SUBVOLUME[2]}"
if [ "${SUBVOLUME[0]}" == "swap" ]; then
mkdir -p "$MNT_DIR${SUBVOLUME[2]}"
chmod 0755 "$MNT_DIR${SUBVOLUME[2]}"
else
mkdir -p "${MNT_DIR}${SUBVOLUME[2]}"
mkdir -p "$MNT_DIR${SUBVOLUME[2]}"
fi
mount -o "subvol=${SUBVOLUME[1]},$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" "${MNT_DIR}${SUBVOLUME[2]}"
mount -o "subvol=${SUBVOLUME[1]},$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" "$MNT_DIR${SUBVOLUME[2]}"
done
else
# root
mount -o "$PARTITION_OPTIONS" "$DEVICE_ROOT" ${MNT_DIR}
mount -o "$PARTITION_OPTIONS" "$DEVICE_ROOT" "$MNT_DIR"

# boot
mkdir -p ${MNT_DIR}/boot
mount -o "$PARTITION_OPTIONS_BOOT" "$PARTITION_BOOT" ${MNT_DIR}/boot
mkdir -p "$MNT_DIR"/boot
mount -o "$PARTITION_OPTIONS_BOOT" "$PARTITION_BOOT" "$MNT_DIR"/boot

# mount points
for I in "${PARTITION_MOUNT_POINTS[@]}"; do
if [[ "$I" =~ ^!.* ]]; then
continue
fi
IFS='=' PARTITION_MOUNT_POINT=($I)
if [ "${PARTITION_MOUNT_POINT[1]}" == "/boot" -o "${PARTITION_MOUNT_POINT[1]}" == "/" ]; then
IFS='=' PARTITION_MOUNT_POINT=("$I")
if [ "${PARTITION_MOUNT_POINT[1]}" == "/boot" ] || [ "${PARTITION_MOUNT_POINT[1]}" == "/" ]; then
continue
fi
local PARTITION_DEVICE="$(partition_device "${DEVICE}" "${PARTITION_MOUNT_POINT[0]}")"
mkdir -p "${MNT_DIR}${PARTITION_MOUNT_POINT[1]}"
mount -o "$PARTITION_OPTIONS" "${PARTITION_DEVICE}" "${MNT_DIR}${PARTITION_MOUNT_POINT[1]}"
mkdir -p "$MNT_DIR${PARTITION_MOUNT_POINT[1]}"
mount -o "$PARTITION_OPTIONS" "${PARTITION_DEVICE}" "$MNT_DIR${PARTITION_MOUNT_POINT[1]}"
done
fi
}
Loading

0 comments on commit cc78804

Please sign in to comment.