Skip to content

Commit

Permalink
1.4.6
Browse files Browse the repository at this point in the history
* Temp dir enhanced
  • Loading branch information
murkl authored Apr 7, 2024
1 parent 581be6a commit 8821ad9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Ignore cache dir
.arch-os-installer.*
# Ignore temp dir
.tmp.*

# Created by scripts
installer.conf
Expand Down
45 changes: 24 additions & 21 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export MODE="$1" # Start debug: ./installer.sh debug
# LICENCE: GPL 2.0

# VERSION
VERSION='1.4.5'
VERSION='1.4.6'
VERSION_GUM="0.13.0"

# ENVIRONMENT
SCRIPT_CONFIG="./installer.conf"
SCRIPT_LOG="./installer.log"

# CACHE
SCRIPT_CACHE="$(mktemp -d "./.arch-os-installer.XXXXX")"
ERROR_MSG="${SCRIPT_CACHE}/installer.err"
PROCESS_LOG="${SCRIPT_CACHE}/process.log"
PROCESS_RET="${SCRIPT_CACHE}/process.ret"
# TEMP
SCRIPT_TMP_DIR="$(mktemp -d "./.tmp.XXXXX")"
ERROR_MSG="${SCRIPT_TMP_DIR}/installer.err"
PROCESS_LOG="${SCRIPT_TMP_DIR}/process.log"
PROCESS_RET="${SCRIPT_TMP_DIR}/process.ret"

# COLORS
COLOR_WHITE=251
Expand Down Expand Up @@ -56,21 +56,25 @@ main() {
rm -f "$SCRIPT_CONFIG"
fi

# Properties step begin...
local first_run="true" # Set first run (skip edit on refresh)
while (true); do # Loop properties step to update screen if user edit properties
# Set script properties
local ARCH_OS_VARIANT='' # User env
local FIRST_RUN="true" # Set first run (skip edit on refresh)

# Loop properties step to update screen if user edit properties
while (true); do

# Print Welcome
print_header && print_title "Welcome to Arch OS Installation"

# Prepare properties
if [ -f "$SCRIPT_CONFIG" ]; then
properties_source # Load properties file (if exists) and auto export variables
else
until select_variant; do :; done # Select installation variant
until select_variant; do :; done # Select installation variant preset
fi

# Prepare properties
properties_generate # Generate properties file (needed on first start of installer)
# Generate properties file (needed on first start of installer)
properties_generate

# Selectors
until select_username; do :; done
Expand All @@ -89,15 +93,15 @@ main() {
until select_enable_manager; do :; done

# Edit properties?
if [ "$first_run" = "true" ] && gum_confirm "Edit Properties?"; then
if [ "$FIRST_RUN" = "true" ] && gum_confirm "Edit Properties?"; then
log_info "Edit properties..."
local gum_header="Exit with CTRL + C and save with CTRL + D or ESC"
if gum_write --height=10 --width=100 --header=" ${gum_header}" --value="$(cat "$SCRIPT_CONFIG")" >"${SCRIPT_CONFIG}.new"; then
mv "${SCRIPT_CONFIG}.new" "${SCRIPT_CONFIG}" && properties_source
fi
rm -f "${SCRIPT_CONFIG}.new" # Remove tmp properties
gum_confirm "Change Password?" && until select_password --force; do :; done
first_run="false" && continue # Restart properties step to refresh log above if changed
FIRST_RUN="false" && continue # Restart properties step to refresh log above if changed
fi

print_info "Properties successfully initialized"
Expand Down Expand Up @@ -148,11 +152,11 @@ gum_init() {
local gum_url # Prepare URL with version os and arch
# https://github.com/charmbracelet/gum/releases
gum_url="https://github.com/charmbracelet/gum/releases/download/v${VERSION_GUM}/gum_${VERSION_GUM}_$(uname -s)_$(uname -m).tar.gz"
if ! curl -Lsf "$gum_url" >"${SCRIPT_CACHE}/gum.tar.gz"; then echo "Error downloading ${gum_url}" && exit 1; fi
if ! tar -xf "${SCRIPT_CACHE}/gum.tar.gz" --directory "$SCRIPT_CACHE"; then echo "Error extracting ${SCRIPT_CACHE}/gum.tar.gz" && exit 1; fi
if ! mv "${SCRIPT_CACHE}/gum" ./gum; then echo "Error moving ${SCRIPT_CACHE}/gum to ./gum" && exit 1; fi
if ! curl -Lsf "$gum_url" >"${SCRIPT_TMP_DIR}/gum.tar.gz"; then echo "Error downloading ${gum_url}" && exit 1; fi
if ! tar -xf "${SCRIPT_TMP_DIR}/gum.tar.gz" --directory "$SCRIPT_TMP_DIR"; then echo "Error extracting ${SCRIPT_TMP_DIR}/gum.tar.gz" && exit 1; fi
if ! mv "${SCRIPT_TMP_DIR}/gum" ./gum; then echo "Error moving ${SCRIPT_TMP_DIR}/gum to ./gum" && exit 1; fi
if ! chmod +x ./gum; then echo "Error chmod +x ./gum" && exit 1; fi
rm -rf "$SCRIPT_CACHE" # # Clean cache dir
rm -rf "$SCRIPT_TMP_DIR" # # Clean cache dir
fi
}

Expand All @@ -177,9 +181,8 @@ trap_exit() {
# Read error msg from file (written in error trap)
local error && [ -f "$ERROR_MSG" ] && error="$(<"$ERROR_MSG")" && rm -f "$ERROR_MSG"

# Remove files
rm -f "$PROCESS_RET" # Remove process return info
rm -f "$PROCESS_LOG" # Remove prcoess log
# Remove cache files
rm -rf "$SCRIPT_TMP_DIR"

# When ctrl + c pressed exit without other stuff below
[ "$result_code" = "130" ] && print_warn "Exit..." && exit 1
Expand Down

0 comments on commit 8821ad9

Please sign in to comment.