Skip to content

Commit 998b6f7

Browse files
fix. backup-restore + added docs
1 parent e1a2703 commit 998b6f7

File tree

2 files changed

+96
-43
lines changed

2 files changed

+96
-43
lines changed

src/plugins/terminal/www/Terminal.js

Lines changed: 91 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -246,71 +246,124 @@ const Terminal = {
246246
}, reject);
247247
});
248248
},
249-
250-
backup(){
249+
/**
250+
* Creates a backup of the Alpine Linux installation
251+
* @async
252+
* @function backup
253+
* @description Creates a compressed tar archive of the Alpine installation
254+
* @returns {Promise<string>} Promise that resolves to the file URI of the created backup file (aterm_backup.tar)
255+
* @throws {string} Rejects with "Alpine is not installed." if Alpine is not currently installed
256+
* @throws {string} Rejects with command output if backup creation fails
257+
* @example
258+
* try {
259+
* const backupPath = await backup();
260+
* console.log(`Backup created at: ${backupPath}`);
261+
* } catch (error) {
262+
* console.error(`Backup failed: ${error}`);
263+
* }
264+
*/
265+
backup() {
251266
return new Promise(async (resolve, reject) => {
252-
if(!await this.isInstalled()){
253-
reject("Alpine is not installed.")
254-
return
267+
if (!await this.isInstalled()) {
268+
reject("Alpine is not installed.");
269+
return;
255270
}
271+
256272
const cmd = `
257273
set -e
258-
259-
INCLUDE_FILES="$PREFIX/alpine $PREFIX/.downloaded $PREFIX/.extracted $PREFIX/axs"
260-
274+
275+
INCLUDE_FILES="alpine .downloaded .extracted axs"
261276
if [ "$FDROID" = "true" ]; then
262-
INCLUDE_FILES="$INCLUDE_FILES $PREFIX/libtalloc.so.2 $PREFIX/libproot-xed.so"
277+
INCLUDE_FILES="$INCLUDE_FILES libtalloc.so.2 libproot-xed.so"
263278
fi
264-
265-
266-
tar -cf $PREFIX/aterm_backup.tar $INCLUDE_FILES
279+
280+
EXCLUDE="--exclude=alpine/data --exclude=alpine/system --exclude=alpine/vendor --exclude=alpine/sdcard --exclude=alpine/storage"
281+
282+
tar -cf "$PREFIX/aterm_backup.tar" -C "$PREFIX" $EXCLUDE $INCLUDE_FILES
267283
echo "ok"
268-
`
269-
const result = await Executor.execute(cmd)
270-
if(result === "ok"){
271-
resolve(cordova.file.dataDirectory + "aterm_backup.tar")
272-
}else{
273-
reject(result)
274-
}
284+
`;
285+
286+
const result = await Executor.execute(cmd);
287+
if (result === "ok") {
288+
resolve(cordova.file.dataDirectory + "aterm_backup.tar");
289+
} else {
290+
reject(result);
291+
}
275292
});
276293
},
277-
restore(){
294+
/**
295+
* Restores Alpine Linux installation from a backup file
296+
* @async
297+
* @function restore
298+
* @description Restores the Alpine installation from a previously created backup file (aterm_backup.tar).
299+
* This function stops any running Alpine processes, removes existing installation files, and extracts
300+
* the backup to restore the previous state. The backup file must exist in the expected location.
301+
* @returns {Promise<string>} Promise that resolves to "ok" when restoration completes successfully
302+
* @throws {string} Rejects with "Backup File does not exist" if aterm_backup.tar is not found
303+
* @throws {string} Rejects with command output if restoration fails
304+
* @example
305+
* try {
306+
* await restore();
307+
* console.log("Alpine installation restored successfully");
308+
* } catch (error) {
309+
* console.error(`Restore failed: ${error}`);
310+
* }
311+
*/
312+
restore() {
278313
return new Promise(async (resolve, reject) => {
279-
if(await this.isAxsRunning()){
280-
await this.stopAxs()
314+
if (await this.isAxsRunning()) {
315+
await this.stopAxs();
281316
}
317+
282318
const cmd = `
283319
set -e
284-
320+
285321
if [ -f "$PREFIX/aterm_backup.tar" ]; then
286-
322+
: # do nothing
287323
else
288324
echo "Backup File does not exist"
325+
exit 1
289326
fi
290-
291-
327+
292328
INCLUDE_FILES="$PREFIX/alpine $PREFIX/.downloaded $PREFIX/.extracted $PREFIX/axs"
293-
329+
294330
if [ "$FDROID" = "true" ]; then
295331
INCLUDE_FILES="$INCLUDE_FILES $PREFIX/libtalloc.so.2 $PREFIX/libproot-xed.so"
296332
fi
297-
333+
298334
for item in $INCLUDE_FILES; do
299335
rm -rf -- "$item"
300336
done
301-
302-
303-
tar -xf $PREFIX/aterm_backup.tar -C $PREFIX
337+
338+
tar -xf "$PREFIX/aterm_backup.tar" -C "$PREFIX"
304339
echo "ok"
305-
`
306-
const result = await Executor.execute(cmd)
307-
if(result === "ok"){
308-
resolve(result)
309-
}else{
310-
reject(result)
311-
}
340+
`;
341+
342+
const result = await Executor.execute(cmd);
343+
if (result === "ok") {
344+
resolve(result);
345+
} else {
346+
reject(result);
347+
}
312348
});
313349
},
350+
/**
351+
* Uninstalls the Alpine Linux installation
352+
* @async
353+
* @function uninstall
354+
* @description Completely removes the Alpine Linux installation from the device by deleting all
355+
* Alpine-related files and directories. This function stops any running Alpine processes before
356+
* removal. NOTE: This does not perform cleanup of $PREFIX
357+
* @returns {Promise<string>} Promise that resolves to "ok" when uninstallation completes successfully
358+
* @throws {string} Rejects with command output if uninstallation fails
359+
* @example
360+
* try {
361+
* await uninstall();
362+
* console.log("Alpine installation removed successfully");
363+
* } catch (error) {
364+
* console.error(`Uninstall failed: ${error}`);
365+
* }
366+
*/
314367
uninstall(){
315368
return new Promise(async (resolve, reject) => {
316369
if(await this.isAxsRunning()){

www/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@
165165

166166
<title>Acode</title>
167167
<!--styles-->
168-
<link rel="stylesheet" href="./css/build/218.css">
169-
<link rel="stylesheet" href="./css/build/32.css">
170-
<link rel="stylesheet" href="./css/build/383.css">
171-
<link rel="stylesheet" href="./css/build/53.css">
172-
<link rel="stylesheet" href="./css/build/609.css">
173168
<link rel="stylesheet" href="./css/build/about.css">
174169
<link rel="stylesheet" href="./css/build/customTheme.css">
175170
<link rel="stylesheet" href="./css/build/donate.css">
176171
<link rel="stylesheet" href="./css/build/fileBrowser.css">
177172
<link rel="stylesheet" href="./css/build/main.css">
178173
<link rel="stylesheet" href="./css/build/plugins.css">
174+
<link rel="stylesheet" href="./css/build/src_pages_quickTools_quickTools_js.css">
175+
<link rel="stylesheet" href="./css/build/src_sidebarApps_extensions_index_js.css">
176+
<link rel="stylesheet" href="./css/build/src_sidebarApps_files_index_js.css">
177+
<link rel="stylesheet" href="./css/build/src_sidebarApps_notification_index_js.css">
178+
<link rel="stylesheet" href="./css/build/src_sidebarApps_searchInFiles_index_js.css">
179179
<link rel="stylesheet" href="./css/build/themeSetting.css">
180180
<!--styles_end-->
181181
</head>

0 commit comments

Comments
 (0)