@@ -91,9 +91,15 @@ const Terminal = {
9191 * @returns {Promise<boolean> } - Returns true if installation completes with exit code 0
9292 */
9393 async install ( logger = console . log , err_logger = console . error ) {
94- if ( await this . isInstalled ( ) ) return true ;
9594 if ( ! ( await this . isSupported ( ) ) ) return false ;
9695
96+ try {
97+ //cleanup before insatll
98+ await this . uninstall ( ) ;
99+ } catch ( e ) {
100+ //supress error
101+ }
102+
97103 const filesDir = await new Promise ( ( resolve , reject ) => {
98104 system . getFilesDir ( resolve , reject ) ;
99105 } ) ;
@@ -107,18 +113,25 @@ const Terminal = {
107113 let axsUrl ;
108114 let prootUrl ;
109115 let libTalloc ;
116+ let libproot = null ;
117+ let libproot32 = null ;
110118
111119 if ( arch === "arm64-v8a" ) {
120+ libproot = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libproot.so" ;
121+ libproot32 = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libproot32.so" ;
112122 libTalloc = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libtalloc.so" ;
113123 prootUrl = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libproot-xed.so" ;
114124 axsUrl = `https://github.com/bajrangCoder/acodex_server/releases/latest/download/axs-musl-android-arm64` ;
115125 alpineUrl = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-minirootfs-3.21.0-aarch64.tar.gz" ;
116126 } else if ( arch === "armeabi-v7a" ) {
127+ libproot = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm32/libproot.so" ;
117128 libTalloc = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm32/libtalloc.so" ;
118129 prootUrl = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm32/libproot-xed.so" ;
119130 axsUrl = `https://github.com/bajrangCoder/acodex_server/releases/latest/download/axs-musl-android-armv7` ;
120131 alpineUrl = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/armhf/alpine-minirootfs-3.21.0-armhf.tar.gz" ;
121132 } else if ( arch === "x86_64" ) {
133+ libproot = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libproot.so" ;
134+ libproot32 = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libproot32.so" ;
122135 libTalloc = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libtalloc.so" ;
123136 prootUrl = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libproot-xed.so" ;
124137 axsUrl = `https://github.com/bajrangCoder/acodex_server/releases/latest/download/axs-musl-android-x86_64` ;
@@ -166,6 +179,27 @@ const Terminal = {
166179 resolve , reject
167180 ) ;
168181 } ) ;
182+
183+ if ( libproot != null ) {
184+ await new Promise ( ( resolve , reject ) => {
185+ cordova . plugin . http . downloadFile (
186+ libproot , { } , { } ,
187+ cordova . file . dataDirectory + "libproot.so" ,
188+ resolve , reject
189+ ) ;
190+ } ) ;
191+ }
192+
193+ if ( libproot32 != null ) {
194+ await new Promise ( ( resolve , reject ) => {
195+ cordova . plugin . http . downloadFile (
196+ libproot32 , { } , { } ,
197+ cordova . file . dataDirectory + "libproot32.so" ,
198+ resolve , reject
199+ ) ;
200+ } ) ;
201+ }
202+
169203 }
170204
171205 logger ( "✅ All downloads completed" ) ;
@@ -198,9 +232,9 @@ const Terminal = {
198232 return installResult ;
199233
200234 } catch ( e ) {
201- err_logger ( "Installation failed:" , e ) ;
202- console . error ( "Installation failed:" , e ) ;
203- return false ;
235+ err_logger ( "Installation failed:" , e ) ;
236+ console . error ( "Installation failed:" , e ) ;
237+ return false ;
204238 }
205239 } ,
206240
@@ -232,7 +266,13 @@ const Terminal = {
232266 } , reject ) ;
233267 } ) ;
234268
235- resolve ( alpineExists && downloaded && extracted ) ;
269+ const configured = alpineExists && await new Promise ( ( resolve , reject ) => {
270+ system . fileExists ( `${ filesDir } /.configured` , false , ( result ) => {
271+ resolve ( result == 1 ) ;
272+ } , reject ) ;
273+ } ) ;
274+
275+ resolve ( alpineExists && downloaded && extracted && configured ) ;
236276 } ) ;
237277 } ,
238278
@@ -358,10 +398,10 @@ const Terminal = {
358398 * console.error(`Uninstall failed: ${error}`);
359399 * }
360400 */
361- uninstall ( ) {
401+ uninstall ( ) {
362402 return new Promise ( async ( resolve , reject ) => {
363- if ( await this . isAxsRunning ( ) ) {
364- await this . stopAxs ( )
403+ if ( await this . isAxsRunning ( ) ) {
404+ await this . stopAxs ( ) ;
365405 }
366406
367407 const cmd = `
@@ -378,13 +418,13 @@ const Terminal = {
378418 done
379419
380420 echo "ok"
381- `
382- const result = await Executor . execute ( cmd )
383- if ( result === "ok" ) {
384- resolve ( result )
385- } else {
386- reject ( result )
387- }
421+ ` ;
422+ const result = await Executor . execute ( cmd ) ;
423+ if ( result === "ok" ) {
424+ resolve ( result ) ;
425+ } else {
426+ reject ( result ) ;
427+ }
388428 } ) ;
389429 }
390430} ;
0 commit comments