Using ./setup install instead of ./install.sh

This commit is contained in:
clsty
2025-10-19 08:44:12 +08:00
parent 0e6779fafc
commit 8ca46aecdd
10 changed files with 118 additions and 173 deletions
+17
View File
@@ -287,3 +287,20 @@ function check_disk_space() {
return 0
}
function showhelp_global(){
echo -e "
Syntax:
$0 <subcommand> [OPTIONS]...
Subcommands:
install Idempotent installation for dotfiles.
exp-uninstall Experimental uninstall
exp-update Experimental update
help Show this help message
Please run the following for details:
$0 <subcommand> -h
"
}
-74
View File
@@ -1,74 +0,0 @@
# This is NOT a script for execution, but for loading functions, so NOT need execution permission or shebang.
# NOTE that you NOT need to `cd ..' because the `$0' is NOT this file, but the script file which will source this file.
# shellcheck shell=bash
showhelp_global(){
echo -e "Syntax: $0 [subcommand] [options]...
Idempotent installation script for dotfiles.
If no option nor subcommand is specified, run default install process.
Subcommand:
install The default subcommand which can be omitted.
Options for install:
-h, --help Print this help message and exit
-f, --force (Dangerous) Force mode without any confirm
-c, --clean Clean the build cache first
--skip-allgreeting Skip the whole process greeting
--skip-alldeps Skip the whole process installing dependency
--skip-allsetups Skip the whole process setting up permissions/services etc
--skip-allfiles Skip the whole process copying configuration files
-s, --skip-sysupdate Skip system package upgrade e.g. \"sudo pacman -Syu\"
--skip-hyprland Skip installing the config for Hyprland
--skip-fish Skip installing the config for Fish
--skip-plasmaintg Skip installing plasma-browser-integration
--skip-miscconf Skip copying the dirs and files to \".configs\" except for
AGS, Fish and Hyprland
--exp-files Use experimental script for the third step copying files
--fontset <set> (Unavailable yet) Use a set of pre-defined font and config
--via-nix (Unavailable yet) Use Nix to install dependencies
Subcommand:
exp-uninstall Using experimental uninstall script.
Subcommand:
exp-update Using experimental update script.
Options for exp-update:
-f, --force Force check all files even if no new commits (update script)
-p, --packages Enable package checking and building (update script)
-n, --dry-run Show what would be done without making changes (update script)
-v, --verbose Enable verbose output (update script)
--skip-notice Skip warning notice (for experimental scripts)
--non-interactive Run without prompting for user input
"
}
# Handle subcommand
case $1 in
# subcommand specified
install|exp-uninstall|exp-update)
SCRIPT_SUBCOMMAND=$1
shift
;;
# Global help
help|--help|-h)
showhelp_global;exit
;;
# no subcommand (has options: -* ; no options: "")
-*|"")
SCRIPT_SUBCOMMAND=install
;;
# wrong subcommand
*)echo "Unknown subcommand \"$1\", aborting...";exit 1;;
esac
# Handle options for subcommand
case ${SCRIPT_SUBCOMMAND} in
install)
source ./sdata/lib/options-install.sh
;;
exp-update)
source ./sdata/lib/options-exp-update.sh
;;
esac
@@ -2,7 +2,7 @@
# shellcheck shell=bash
showhelp(){
echo -e "Usage: install.sh exp-update [OPTIONS]...
echo -e "Usage: $0 exp-update [OPTIONS]...
Experimental updating without full reinstall.
Updates dotfiles by syncing configuration files to home directory.
@@ -62,18 +62,24 @@ eval set -- "$para"
while true ; do
case "$1" in
## Ones without parameter
-f|--force) FORCE_CHECK=true;shift;;
# log_info "Force check mode enabled - will check all files regardless of git changes"
-p|--packages) CHECK_PACKAGES=true;shift;;
# log_info "Package checking enabled"
-n|--dry-run) DRY_RUN=true;shift;;
# log_info "Dry-run mode enabled - no changes will be made"
-v|--verbose) VERBOSE=true;shift;;
# log_info "Verbose mode enabled"
--skip-notice) SKIP_NOTICE=true;shift;;
# log_warning "Skipping notice about script being untested"
--non-interactive) NON_INTERACTIVE=true;shift;;
# log_info "Non-interactive mode enabled"
-f|--force) FORCE_CHECK=true;shift
log_info "Force check mode enabled - will check all files regardless of git changes"
;;
-p|--packages) CHECK_PACKAGES=true;shift
log_info "Package checking enabled"
;;
-n|--dry-run) DRY_RUN=true;shift
log_info "Dry-run mode enabled - no changes will be made"
;;
-v|--verbose) VERBOSE=true;shift
log_info "Verbose mode enabled"
;;
--skip-notice) SKIP_NOTICE=true;shift
log_warning "Skipping notice about script being untested"
;;
--non-interactive) NON_INTERACTIVE=true;shift
log_info "Non-interactive mode enabled"
;;
## Ending
--) break ;;
@@ -1,9 +1,9 @@
# Handle args for subcmd: install
# shellcheck shell=bash
showhelp(){
echo -e "Syntax: $0 [OPTIONS]...
echo -e "Syntax: $0 install [OPTIONS]...
Idempotent installation script for dotfiles.
Idempotent installation for dotfiles.
Options for install:
-h, --help Print this help message and exit
+2 -2
View File
@@ -5,7 +5,7 @@
printf 'Hi there!\n'
printf 'This script 1. will uninstall [end-4/dots-hyprland > illogical-impulse] dotfiles\n'
printf ' 2. will try to revert *mostly everything* installed using install.sh, so it'\''s pretty destructive\n'
printf ' 2. will try to revert *mostly everything* installed using "./setup install", so it'\''s pretty destructive\n'
printf ' 3. has not been tested, use at your own risk.\n'
printf ' 4. will show all commands that it runs.\n'
printf 'Ctrl+C to exit. Enter to continue.\n'
@@ -77,4 +77,4 @@ Ctrl+C to exit, or press Enter to proceed" p
v yay -Rns illogical-impulse-{audio,backlight,basic,bibata-modern-classic-bin,fonts-themes,hyprland,kde,microtex-git,oneui4-icons-git,portal,python,screencapture,toolkit,widgets} plasma-browser-integration
printf "${STY_CYAN}Uninstall Complete.\n${STY_RST}"
printf "${STY_CYAN}Hint: If you had agreed to backup when you ran \"install.sh\", you should be able to find it under \"$BACKUP_DIR\".\n${STY_RST}"
printf "${STY_CYAN}Hint: If you had agreed to backup when you ran \"./setup install\", you should be able to find it under \"$BACKUP_DIR\".\n${STY_RST}"
+15 -34
View File
@@ -75,29 +75,11 @@ run_test() {
fi
}
# Test 1: Script exists and is executable
test_script_exists() {
log_test "Checking if install.sh exists and is executable"
if [[ ! -f "install.sh" ]]; then
log_fail "install.sh not found"
return 1
fi
if [[ ! -x "install.sh" ]]; then
log_fail "install.sh is not executable"
return 1
fi
log_pass "Script exists and is executable"
return 0
}
# Test 2: Script has no syntax errors
test_syntax() {
log_test "Checking script syntax"
if bash -n install.sh; then
if bash -n setup; then
log_pass "No syntax errors found"
return 0
else
@@ -110,7 +92,7 @@ test_syntax() {
test_help_option() {
log_test "Testing --help option"
if ./install.sh exp-update --help 2>&1 | grep -qiE "(Usage|Options|exp-update)"; then
if ./setup exp-update --help 2>&1 | grep -qiE "(Usage|Options|exp-update)"; then
log_pass "Help option works"
return 0
else
@@ -411,11 +393,11 @@ test_dry_run() {
cd "$test_repo" || { log_fail "Failed to cd to test directory"; return 1; }
# Copy necessary files for install.sh to run
cp "$ORIGINAL_DIR/install.sh" .
# Copy necessary files for setup to run
cp "$ORIGINAL_DIR/setup" .
cp -r "$ORIGINAL_DIR/sdata" .
cp -r "$ORIGINAL_DIR/dots" .
chmod +x install.sh
chmod +x setup
# Create a test config file in repo
mkdir -p dots/.config/test-app
@@ -428,7 +410,7 @@ test_dry_run() {
rm -rf "${HOME}/.config/test-app" 2>/dev/null || true
# Use non-interactive mode and check for DRY-RUN marker
./install.sh exp-update -n --skip-notice --non-interactive 2>&1 | tee dry_run_output.txt
./setup exp-update -n --skip-notice --non-interactive 2>&1 | tee dry_run_output.txt
if grep -q "DRY-RUN" dry_run_output.txt; then
log_pass "Dry-run mode detected in output"
@@ -461,7 +443,7 @@ test_flags() {
local all_passed=true
for flag in "${flags[@]}"; do
if ./install.sh exp-update "$flag" 2>&1 | grep -qiE "(Usage|Options|exp-update)"; then
if ./setup exp-update "$flag" 2>&1 | grep -qiE "(Usage|Options|exp-update)"; then
log_test "$flag recognized"
else
log_test "$flag not recognized"
@@ -487,7 +469,7 @@ test_shellcheck() {
return 0
fi
if shellcheck -e SC1090,SC1091,SC2148,SC2034,SC2155,SC2164 install.sh; then
if shellcheck -e SC1090,SC1091,SC2148,SC2034,SC2155,SC2164 setup then
log_pass "shellcheck passed"
return 0
else
@@ -507,10 +489,10 @@ test_lock_file() {
cd "$test_repo" || { log_fail "Failed to cd to test directory"; return 1; }
# Copy necessary files
cp "$ORIGINAL_DIR/install.sh" .
cp "$ORIGINAL_DIR/setup" .
cp -r "$ORIGINAL_DIR/sdata" .
mkdir -p dots/.config
chmod +x install.sh
chmod +x setup
git add .
git commit -m "Add files" -q
@@ -519,7 +501,7 @@ test_lock_file() {
echo "99999" > .update-lock
# Try to run update - should fail due to lock
if ./install.sh exp-update --skip-notice --non-interactive > lock_test_output.txt 2>&1; then
if ./setup exp-update --skip-notice --non-interactive > lock_test_output.txt 2>&1; then
if grep -q "stale lock" lock_test_output.txt; then
log_pass "Lock file mechanism works (detected stale lock)"
cd "$ORIGINAL_DIR"
@@ -777,16 +759,15 @@ main() {
echo -e "${BLUE} Update.sh Test Suite (Enhanced)${NC}"
echo -e "${BLUE}================================${NC}\n"
if [[ ! -f "install.sh" ]]; then
log_error "Please run this test from the directory containing install.sh"
if [[ ! -f "setup" ]]; then
log_error "Please run this test from the directory containing setup"
exit 1
fi
chmod +x install.sh 2>/dev/null || true
chmod +x setup 2>/dev/null || true
# Define tests
tests=(
"test_script_exists"
"test_syntax"
"test_help_option"
"test_dots_structure"
@@ -844,4 +825,4 @@ trap cleanup EXIT INT TERM
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi
fi
+1 -1
View File
@@ -748,7 +748,7 @@ if [[ "$SKIP_NOTICE" == false ]]; then
log_warning "THIS SCRIPT IS NOT FULLY TESTED AND MAY CAUSE ISSUES!"
log_warning "It might be safer if you want to preserve your modifications and not delete added files,"
log_warning " but this can cause partial updates and therefore unexpected behavior like in #1856."
log_warning "In general, prefer install.sh for updates if available."
log_warning "In general, prefer \"./setup install\" for updates if available."
safe_read "Continue? (y/N): " response "N"
if [[ ! "$response" =~ ^[Yy]$ ]]; then