Skip to content

Commit 48c7d67

Browse files
authored
Merge pull request #15 from Lolig4/main
change install.sh to use the setup scripts and make it multiplatform
2 parents bcf951a + 776e2e0 commit 48c7d67

File tree

1 file changed

+68
-239
lines changed

1 file changed

+68
-239
lines changed

install.sh

Lines changed: 68 additions & 239 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
goto windows
12
#!/bin/bash
23

34
set -e
@@ -8,7 +9,7 @@ CONTRIBUTERS
89
@Lolig4 | Setup scripts and bug help
910
"""
1011

11-
sleep (2)
12+
sleep 2
1213

1314
detect_environment() {
1415
if [ -d "/data/data/com.termux" ] || [ -d "/data/data/com.termux.fdroid" ]; then
@@ -301,264 +302,61 @@ EOF
301302
main
302303
}
303304

304-
pc_install() {
305-
echo "╔═══════════════════════════════════════════════════════════════╗"
306-
echo "║ Setup Android Studio ║"
307-
echo "║ PC Mode ║"
308-
echo "╚═══════════════════════════════════════════════════════════════╝"
309-
310-
echo "[*] Setting up PC development environment..."
311-
312-
if command -v inkscape >/dev/null 2>&1; then
313-
IMG_CMD="inkscape"
314-
elif command -v magick >/dev/null 2>&1; then
315-
IMG_CMD="magick"
316-
else
317-
echo "[*] Neither Inkscape or ImageMagick v7+ found. Please install one."
318-
echo "[*] Please note that ImageMagick can't produce a transparent background."
319-
exit 1
320-
fi
321-
322-
if ! command -v git >/dev/null 2>&1; then
323-
echo "[*] Git is not installed."
324-
echo "[*] Please install Git"
325-
exit 1
326-
fi
327-
305+
DOWNLOADER=""
306+
detect_downloader() {
328307
if command -v curl >/dev/null 2>&1; then
329308
DOWNLOADER="curl"
330309
elif command -v wget >/dev/null 2>&1; then
331310
DOWNLOADER="wget"
332311
else
333-
echo "[*] Neither curl or wget found. Please install one."
312+
echo "[*] Neither curl nor wget found. Please install one."
334313
exit 1
335314
fi
315+
}
336316

337-
echo "[*] Setting up Android Studio project structure..."
338-
339-
if [ ! -d "app" ]; then
340-
echo "[!] This script should be run from an Android Studio project root"
341-
echo "[!] Expected 'app' directory not found"
342-
echo ""
343-
echo "Instructions:"
344-
echo "1. Create a new Android Studio project"
345-
echo "2. Copy this script to the project root"
346-
echo "3. Run the script from there"
347-
exit 1
348-
fi
317+
pc_install() {
318+
SCRIPT_URL="https://raw.githubusercontent.com/CPScript/NFCman/main/setup/android_studio_setup.sh"
319+
SCRIPT_PATH="$(dirname "$(realpath "$0")")/android_studio_setup.sh"
349320

350-
URL="https://avatars.githubusercontent.com/u/83523587?s=48&v=4"
351-
DEST="ic_launcher.jpeg"
352-
readarray -t SVG_PATHS < <(find . -type f -iname '*.svg')
353-
count=${#SVG_PATHS[@]}
354-
355-
if (( count == 0 )); then
356-
echo "[*] No SVG found!"
357-
echo "[*] Would you like to use CPScript's profile picture as a fallback? (y/N)"
358-
read -r REPLY
359-
if [[ $REPLY =~ ^[Yy]$ ]]; then
360-
echo "[*] Download CPScript's profile picture..."
361-
if [[ $DOWNLOADER == "curl" ]]; then
362-
curl -L "$URL" -o "$DEST"
363-
elif [[ $DOWNLOADER == "wget" ]]; then
364-
wget -O "$DEST" "$URL"
365-
fi
366-
IMAGE=$DEST
367-
else
368-
echo "[*] Please drop a SVG into your Android Studio project."
369-
exit 1
370-
fi
371-
elif (( count == 1 )); then
372-
IMAGE="${SVG_PATHS[0]}"
373-
echo "[*] SVG found: $IMAGE"
321+
if [[ $DOWNLOADER == "curl" ]]; then
322+
curl -L "$SCRIPT_URL" -o "$SCRIPT_PATH"
374323
else
375-
echo "[*] More than one SVG found! Please ensure that only one SVG is in your Android Studio project."
376-
exit 1
377-
fi
378-
379-
echo "[*] Deleting default files..."
380-
rm -rf app/src/main/res
381-
rm -rf app/src/main/java/com/nfcclone/app
382-
rm -f app/src/main/AndroidManifest.xml
383-
384-
echo "[*] Cloning repository..."
385-
git clone https://github.com/CPScript/NFCman
386-
387-
echo "[*] Copying files into project..."
388-
cp -r NFCman/android/res app/src/main/
389-
cp -r NFCman/android/src/com app/src/main/java/
390-
cp NFCman/android/AndroidManifest.xml app/src/main/
391-
392-
echo "[*] Extracting EmulationControlReceiver class..."
393-
SOURCE_FILE="app/src/main/java/com/nfcclone/app/NfcEmulatorService.java"
394-
TARGET_FILE="app/src/main/java/com/nfcclone/app/EmulationControlReceiver.java"
395-
396-
if [ -f "$SOURCE_FILE" ]; then
397-
awk '
398-
/\/\* EmulationControlReceiver.java \*\// { inside=1; next }
399-
inside {
400-
brace_level += gsub(/\{/, "{")
401-
brace_level -= gsub(/\}/, "}")
402-
print
403-
if (brace_level == 0 && /}/) exit
404-
}
405-
' "$SOURCE_FILE" > "$TARGET_FILE"
406-
407-
awk '
408-
/\/\* EmulationControlReceiver.java \*\// { inside=1; next }
409-
inside {
410-
brace_level += gsub(/\{/, "{")
411-
brace_level -= gsub(/\}/, "}")
412-
if (brace_level == 0 && /}/) { inside=0; next }
413-
next
414-
}
415-
{ print }
416-
' "$SOURCE_FILE" > temp.java && mv temp.java "$SOURCE_FILE"
417-
418-
echo "[*] EmulationControlReceiver class extracted successfully"
324+
wget -O "$SCRIPT_PATH" "$SCRIPT_URL"
419325
fi
420326

421-
echo "[*] Cleaning XML files..."
422-
find app/src/main/res -type f -name "*.xml" -exec sed -i '/^<!-- .* -->$/d' {} + 2>/dev/null || \
423-
find app/src/main/res -type f -name "*.xml" -exec sed '/^<!-- .* -->$/d' {} \; 2>/dev/null || true
424-
425-
echo "[*] Create ic_launcher.png..."
426-
declare -A SIZES=(
427-
[mdpi]=48
428-
[hdpi]=72
429-
[xhdpi]=96
430-
[xxhdpi]=144
431-
[xxxhdpi]=192
432-
)
433-
434-
for DENSITY in "${!SIZES[@]}"; do
435-
SIZE=${SIZES[$DENSITY]}
436-
OUT_DIR="app/src/main/res/mipmap-$DENSITY"
437-
OUT_FILE="$OUT_DIR/ic_launcher.png"
438-
439-
echo "[*] Generating ${DENSITY} (${SIZE}×${SIZE})..."
440-
mkdir -p "$OUT_DIR"
441-
442-
if [[ $IMG_CMD == "inkscape" ]]; then
443-
inkscape "$IMAGE" \
444-
--export-background-opacity=0 \
445-
--export-filename="$OUT_FILE" \
446-
--export-width="$SIZE" \
447-
--export-height="$SIZE"
448-
elif [[ $IMG_CMD == "magick" ]]; then
449-
magick "$IMAGE" -resize "${SIZE}x${SIZE}" "$OUT_FILE"
450-
fi
451-
done
452-
453-
echo "[*] Setting up Gradle configuration..."
454-
455-
cat > app/build.gradle << 'EOF'
456-
apply plugin: 'com.android.application'
457-
458-
android {
459-
compileSdkVersion 34
460-
buildToolsVersion "34.0.0"
461-
462-
defaultConfig {
463-
applicationId "com.nfcclone.app"
464-
minSdkVersion 19
465-
targetSdkVersion 34
466-
versionCode 2
467-
versionName "2.0"
468-
469-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
470-
}
471-
472-
buildTypes {
473-
release {
474-
minifyEnabled false
475-
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
476-
debuggable false
477-
}
478-
debug {
479-
debuggable true
480-
minifyEnabled false
481-
}
482-
}
483-
484-
compileOptions {
485-
sourceCompatibility JavaVersion.VERSION_1_8
486-
targetCompatibility JavaVersion.VERSION_1_8
487-
}
488-
489-
packagingOptions {
490-
pickFirst '**/libjsc.so'
491-
pickFirst '**/libc++_shared.so'
492-
}
493-
}
494-
495-
dependencies {
496-
implementation 'androidx.appcompat:appcompat:1.6.1'
497-
implementation 'androidx.core:core:1.10.1'
498-
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
499-
implementation 'com.google.android.material:material:1.9.0'
500-
501-
testImplementation 'junit:junit:4.13.2'
502-
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
503-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
327+
chmod +x "$SCRIPT_PATH"
328+
exec "$SCRIPT_PATH" "$@"
504329
}
505-
EOF
506-
507-
cat > app/proguard-rules.pro << 'EOF'
508-
# Add project specific ProGuard rules here.
509-
510-
# Keep NFC related classes
511-
-keep class com.nfcclone.app.** { *; }
512-
513-
# Keep JSON parsing
514-
-keepattributes Signature
515-
-keepattributes *Annotation*
516-
-keep class org.json.** { *; }
517-
518-
# Keep NFC technology classes
519-
-keep class android.nfc.** { *; }
520-
-keep class android.nfc.tech.** { *; }
521330

522-
# Keep HCE service
523-
-keep class * extends android.nfc.cardemulation.HostApduService {
524-
public <init>(...);
525-
public <methods>;
526-
}
527-
528-
# Keep broadcast receivers
529-
-keep class * extends android.content.BroadcastReceiver {
530-
public <init>(...);
531-
public <methods>;
532-
}
533-
EOF
331+
update_script() {
332+
echo "[*] Updating script to latest version..."
333+
334+
SCRIPT_URL="https://raw.githubusercontent.com/CPScript/NFCman/main/install.sh"
335+
SCRIPT_PATH="$(realpath "$0")"
336+
TMP_FILE="$(mktemp)"
534337

535-
echo "[*] Cleaning up..."
536-
rm -rf NFCman
537-
if [[ $IMAGE == "ic_launcher.jpeg" ]]; then
538-
rm $IMAGE
338+
if [[ $DOWNLOADER == "curl" ]]; then
339+
curl -fsSL "$SCRIPT_URL" -o "$TMP_FILE"
340+
else
341+
wget -q "$SCRIPT_URL" -O "$TMP_FILE"
539342
fi
540343

344+
cp "$SCRIPT_PATH" "$SCRIPT_PATH.bak"
345+
mv "$TMP_FILE" "$SCRIPT_PATH"
346+
chmod +x "$SCRIPT_PATH"
347+
echo "[*] Restarting script with updated version..."
541348
echo ""
542-
echo "╔═══════════════════════════════════════════════════════════════╗"
543-
echo "║ PC Setup Complete ║"
544-
echo "╚═══════════════════════════════════════════════════════════════╝"
545-
echo "[+] Android Studio project structure created"
546-
echo "[+] Repository files copied to proper locations"
547-
echo "[+] App icon configured from SVG/fallback image"
548-
echo "[+] Gradle configuration applied"
549-
echo "[+] ProGuard rules configured"
550-
echo ""
551-
echo "Next steps:"
552-
echo "1. Open this project in Android Studio"
553-
echo "2. Sync the project (File → Sync Project with Gradle Files)"
554-
echo "3. Build the project (Build → Make Project)"
555-
echo "4. Generate APK (Build → Build Bundle(s) / APK(s) → Build APK(s))"
556-
echo "5. Install APK on your Android device"
557-
echo "6. Run the Termux script on your device: ./nfc_manager.sh"
558-
echo ""
349+
exec "$SCRIPT_PATH" "$@" "--updated"
559350
}
560351

561352
main() {
353+
detect_downloader
354+
355+
if [[ "$1" == "--updated" ]]; then
356+
shift
357+
else
358+
update_script "$@"
359+
fi
562360
local environment=$(detect_environment)
563361

564362
case $environment in
@@ -592,5 +390,36 @@ if [ "$FORCE_TERMUX" = "1" ]; then
592390
elif [ "$FORCE_PC" = "1" ]; then
593391
pc_install
594392
else
595-
main
393+
main "$@"
596394
fi
395+
exit 1
396+
397+
:windows
398+
@echo off
399+
400+
setlocal EnableDelayedExpansion
401+
402+
set "SCRIPT_URL=https://raw.githubusercontent.com/CPScript/NFCman/main/install.sh"
403+
set "THIS_SCRIPT=%~f0"
404+
set "TMP_FILE=%TEMP%\install_update.sh"
405+
406+
set "UPDATED=false"
407+
for %%A in (%*) do (
408+
if "%%A"=="--updated" set "UPDATED=true"
409+
)
410+
411+
if /I "!UPDATED!"=="false" (
412+
powershell -Command "Invoke-WebRequest -Uri '!UPDATE_URL!' -OutFile '!TMP_FILE!'"
413+
copy /Y "!THIS_SCRIPT!" "!THIS_SCRIPT!.bak" >nul
414+
move /Y "!TMP_FILE!" "!THIS_SCRIPT!" >nul
415+
start "" cmd /c ""!THIS_SCRIPT!" --updated"
416+
exit /b
417+
)
418+
419+
:: set "SCRIPT_URL=https://raw.githubusercontent.com/CPScript/NFCman/main/setup/windows_setup_script.bat"
420+
set "SETUP_URL=https://raw.githubusercontent.com/Lolig4/NFCman/main/setup/windows_setup_script.bat"
421+
set "SCRIPT_DIR=%~dp0"
422+
set "SETUP_PATH=%SCRIPT_DIR%android_studio_setup.bat"
423+
powershell -Command "Invoke-WebRequest -Uri '!SETUP_URL!' -OutFile '!SETUP_PATH!'"
424+
start "" cmd /c ""!SETUP_PATH!""
425+
exit /b

0 commit comments

Comments
 (0)