Skip to content

Commit 62f2b7f

Browse files
committed
chore: some fixes in the batch file and updated README
1 parent 7751948 commit 62f2b7f

File tree

3 files changed

+63
-48
lines changed

3 files changed

+63
-48
lines changed

APPw

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# --- Configuration (Non-Overridable) ---
44
APP_NAME="APP"
55
APP_DIR=".APP"
6-
RELEASE_URL="https://example.com/releases/foo-latest.tgz"
6+
RELEASE_URL="https://example.com/releases/.../foo-latest.tgz"
77
# ---------------------------------------
88

99
# 1. Setup essential variables needed for config loading
@@ -21,14 +21,8 @@ LOG_LEVEL=
2121
load_config() {
2222
local config_file="$1"
2323
if [ -f "$config_file" ]; then
24-
LOG "Loading configuration from $config_file..."
25-
# Use a temporary file to strip comments and source the clean output
26-
local temp_config
27-
temp_config=$(mktemp)
28-
# Strip lines starting with # or containing only whitespace, then source
29-
grep -v '^\s*#' "$config_file" | grep -v '^\s*$' > "$temp_config"
30-
source "$temp_config" 2>/dev/null
31-
rm "$temp_config"
24+
#LOG "Loading configuration from $config_file..."
25+
source "$config_file" 2>/dev/null
3226
fi
3327
}
3428

@@ -50,7 +44,7 @@ LAST_CHECKED_FILE="$CACHE_DIR/last_checked"
5044
LOG() {
5145
# Only echo the log message if LOG_LEVEL is not empty
5246
if [ -n "$LOG_LEVEL" ]; then
53-
echo "[Installer] $1"
47+
echo "[$APP_NAME Bootstrap] $1"
5448
fi
5549
}
5650

APPw.cmd

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ setlocal enableExtensions enableDelayedExpansion
44
rem --- Configuration (Non-Overridable) ---
55
set APP_NAME=APP
66
set APP_DIR=.APP
7-
set RELEASE_URL=https://example.com/releases/foo-latest.zip
7+
set RELEASE_URL=https://example.com/releases/.../foo-latest.zip
88
rem ---------------------------------------
99

1010
rem 1. Setup essential variables needed for config loading
1111
set "HOME_DIR=%USERPROFILE%"
12-
set "APP_HOME=%HOME_DIR%\.%APP_DIR%"
12+
set "APP_HOME=%HOME_DIR%\%APP_DIR%"
1313

1414
rem 2. Define default overridable variables
1515
rem The update period in days (e.g., 3 means check if the last_checked file is older than 3 days)
1616
set UPDATE_PERIOD=3
1717
rem Logging level (default empty/silent; set to anything, e.g., 'DEBUG', to enable logging)
1818
set LOG_LEVEL=
1919

20+
goto :START
21+
2022
rem --- Configuration Loading ---
2123
rem Helper subroutine to load configuration from a file
2224
:LOAD_CONFIG
@@ -26,35 +28,16 @@ rem Helper subroutine to load configuration from a file
2628
rem /F "tokens=1,2 delims==" splits lines by '='. 'skip=0' is default. 'eol=#' handles comments.
2729
for /f "tokens=1* delims== eol=#" %%a in ('type "%CONFIG_FILE%"') do (
2830
rem %%a is the key (before '=') and %%b is the value (after '=')
29-
rem Handle specific known variable overrides here
30-
if /I "%%a" == "UPDATE_PERIOD" (
31-
set UPDATE_PERIOD=%%b
32-
)
33-
rem Add other overridable variables here if needed
31+
set %%a=%%b
3432
)
3533
)
3634
goto :eof
3735

38-
rem Load user-wide configuration (if exists)
39-
call :LOAD_CONFIG "%APP_HOME%\bootstrap.cfg"
40-
41-
rem Load local configuration (if exists)
42-
call :LOAD_CONFIG ".\%APP_DIR%\bootstrap.cfg"
43-
44-
rem -----------------------------
45-
46-
rem 3. Define the remaining path variables using the (potentially overridden) NAME/UPDATE_PERIOD
47-
set "CACHE_DIR=%APP_HOME%\cache"
48-
set "BIN_DIR=%APP_HOME%\bin"
49-
set "APP_EXE=%BIN_DIR%\%APP_NAME%.cmd"
50-
set "ARCHIVE_FILE=%CACHE_DIR%\release.zip"
51-
set "LAST_CHECKED_FILE=%CACHE_DIR%\last_checked"
52-
5336
rem Helper function for logging
5437
:LOG
5538
rem Only echo the log message if LOG_LEVEL is not empty
5639
if not "%LOG_LEVEL%"=="" (
57-
echo [Installer] %~1
40+
echo [%APP_NAME% Bootstrap] %~1
5841
)
5942
goto :eof
6043

@@ -177,6 +160,23 @@ rem --- Core Logic Functions ---
177160
)
178161
goto :eof
179162

163+
:START
164+
165+
rem Load user-wide configuration (if exists)
166+
call :LOAD_CONFIG "%APP_HOME%\bootstrap.cfg"
167+
168+
rem Load local configuration (if exists)
169+
call :LOAD_CONFIG ".\%APP_DIR%\bootstrap.cfg"
170+
171+
rem -----------------------------
172+
173+
rem 3. Define the remaining path variables using the (potentially overridden) NAME/UPDATE_PERIOD
174+
set "CACHE_DIR=%APP_HOME%\cache"
175+
set "BIN_DIR=%APP_HOME%\bin"
176+
set "APP_EXE=%BIN_DIR%\%APP_NAME%.cmd"
177+
set "ARCHIVE_FILE=%CACHE_DIR%\release.zip"
178+
set "LAST_CHECKED_FILE=%CACHE_DIR%\last_checked"
179+
180180
rem --- Execution Flow ---
181181

182182
rem 1. Installation/Update Check
@@ -200,7 +200,7 @@ if /I NOT "%SCRIPT_DIR_CLEAN%" EQU "%BIN_DIR%" (
200200
call :LOG "Handing over execution to the installed application: %APP_EXE%"
201201
rem Use 'start' to run the application and allow the current script to exit immediately.
202202
rem %* passes all arguments to the new process.
203-
start "" "%APP_EXE%" %*
203+
"%APP_EXE%" %*
204204
goto :eof
205205
)
206206

README.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,25 @@ Configuration is managed in two ways:
2424

2525
These variables are defined directly at the top of the scripts and **should not** be overridden by bootstrap.cfg.
2626

27-
| Variable | Default Value (Example) | Description |
28-
|:-----------------|:------------------------|:---------------------------------------------------------------------------------|
29-
| **NAME** | APP | The short name of the application. |
30-
| **APP_HOME** | ~/.APP | The installation directory of the application. |
31-
| **RELEASE_URL** | https://example.com/... | The direct download URL for the release archive (.tgz for Bash, .zip for Batch). |
27+
| Variable | Default Value (Example) | Description |
28+
|:----------------|:--------------------------|:---------------------------------------------------------------------------------|
29+
| **APP_NAME** | `APP` | The short name of the application. |
30+
| **APP_DIR** | `.APP` | The installation directory name of the application. |
31+
| **RELEASE_URL** | `https://example.com/...` | The direct download URL for the release archive (.tgz for Bash, .zip for Batch). |
3232

3333
### **2\. Overridable Variables**
3434

3535
These variables have defaults set within the script but can be overridden by placing them in one of the following configuration files (in order of precedence):
3636

37-
1. `$HOME/.\<NAME\>/bootstrap.cfg` (User-wide defaults)
38-
2. `./.\<NAME\>/bootstrap.cfg` (Folder-specific overrides)
37+
1. `$HOME/<APP_DIR>/bootstrap.cfg` (User-wide defaults)
38+
2. `./<APP_DIR>/bootstrap.cfg` (Local overrides)
3939

40-
The format for the configuration files is simple KEY=VALUE, with comments starting with \#.
40+
The format for the configuration files is simple `KEY=VALUE`, with comments starting with `#`.
4141

42-
| Variable | Default Value | Description |
43-
|:------------------| :---- | :---- |
44-
| **UPDATE_PERIOD** | 3 | The number of days after which an update check must be performed. If the last\_checked file is older than this period, the script will attempt to contact the server. |
42+
| Variable | Default Value | Description |
43+
|:------------------|:--------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
44+
| **UPDATE_PERIOD** | 3 | The number of days after which an update check must be performed. If the last\_checked file is older than this period, the script will attempt to contact the server. |
45+
| **LOG_LEVEL** | \<empty> | Logging level. Default empty/silent; set to anything, e.g., 'DEBUG', to enable logging |
4546

4647
**Example bootstrap.cfg content:**
4748

@@ -65,8 +66,8 @@ UPDATE_PERIOD=7
6566

6667
## **Usage**
6768

68-
1. **Configure:** Edit the `NAME` and `RELEASE_URL` variables (and possibly `APP_HOME` if you want a different name than the default) at the top of both scripts (`APPw` and `APPw.bat`).
69-
2. **Rename & Place:** Rename the scripts to match your application's name. Common usage is to have the name of the scripts end in the letter “w” to indicate they are “wrapper” scripts (e.g., if NAME=foo, rename to foow and foow.bat).
69+
1. **Configure:** Edit the `NAME` and `RELEASE_URL` variables (and possibly `APP_DIR` if you want a different name than the default) at the top of both scripts (`APPw` and `APPw.bat`).
70+
2. **Rename:** Rename the scripts to match your application's name. Common usage is to have the name of the scripts end in the letter “w” to indicate they are “wrapper” scripts (e.g., if `APP_NAME=foo`, rename to `foow` and `foow.bat`).
7071
3. **Execute:** Place the scripts in a directory where you want the command to be available and run it:
7172

7273
```
@@ -77,4 +78,24 @@ UPDATE_PERIOD=7
7778
.\foow.cmd /flag
7879
```
7980

80-
The first time you run it, the application will download and install itself to the user’s home directory ($HOME/.foo). Subsequent runs will check for updates if the configured period has passed.
81+
The first time you run it, the application will download and install itself to the user’s home directory (`$HOME/$APP_DIR`). Subsequent runs will check for updates if the configured period has passed.
82+
83+
### Force new version check
84+
85+
To force an update check, you can delete the `last_checked` file located in the application's installation directory, eg:
86+
87+
```
88+
rm $HOME/.APP/cache/last_checked
89+
```
90+
91+
Then the next execution of the script will check for updates.
92+
93+
### Force update/reinstall
94+
95+
To force a complete reinstallation of the application, delete the application's `cache` directory, eg:
96+
97+
```
98+
rm -rf $HOME/.APP/cache
99+
```
100+
101+
Then the next execution of the script will download and install the application afresh.

0 commit comments

Comments
 (0)