Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Uninstaller Script #114

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions build_all.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#!/bin/bash

[[ "$OSTYPE" == "darwin"* ]] && export C_INCLUDE_PATH=/usr/local/opt/libusb/include
if [ "$EUID" -ne 0 ]
if [[ "$EUID" -ne 0 ]] && [[ "$OSTYPE" != "darwin"* ]]
then echo "Please run as root! (sudo ./build_all.sh)"
exit
fi
[[ "$OSTYPE" == "darwin"* ]] && export C_INCLUDE_PATH=/usr/local/opt/libusb/include
(
cd IMSProg_programmer
rm -rf build/
mkdir build/
cmake -S . -B build/
cmake --build build/ --parallel
cmake --build build/ --parallel
cmake --install build/
rm -rf build/
cd .. #IMSProg
)
(
cd IMSProg_editor
rm -rf build/
mkdir build/
cmake -S . -B build/
cmake --build build/ --parallel
cmake --build build/ --parallel
cmake --install build/
rm -rf build/
# Reloading the USB rules
[[ "$OSTYPE" != "darwin"* ]] && udevadm control --reload-rules
)
# Reloading the USB rules or creating the app bundles for macOS
[[ "$OSTYPE" != "darwin"* ]] && udevadm control --reload-rules || ./create_macos_appbundles.sh
96 changes: 96 additions & 0 deletions create_macos_appbundles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env bash

CONTENTSDIR1='IMSProg.app/Contents'
CONTENTSDIR2='IMSProg Editor.app/Contents'
CONTENTSDIR3='IMSProg Database Update.app/Contents'

create_directories() {
local CONTENTSDIR=$1
mkdir -p "$CONTENTSDIR/MacOS"
mkdir -p "$CONTENTSDIR/Resources"
}

generate_iconset() {
local INPUT_IMG=$1
local OUTPUT_ICONS=$2

mkdir icon.iconset
sips -z 16 16 -s format png "$INPUT_IMG" --out icon.iconset/icon_16x16.png
sips -z 32 32 -s format png "$INPUT_IMG" --out icon.iconset/icon_16x16@2x.png
sips -z 32 32 -s format png "$INPUT_IMG" --out icon.iconset/icon_32x32.png
sips -z 64 64 -s format png "$INPUT_IMG" --out icon.iconset/icon_32x32@2x.png
sips -z 128 128 -s format png "$INPUT_IMG" --out icon.iconset/icon_128x128.png
sips -z 256 256 -s format png "$INPUT_IMG" --out icon.iconset/icon_128x128@2x.png
sips -z 256 256 -s format png "$INPUT_IMG" --out icon.iconset/icon_256x256.png
sips -z 512 512 -s format png "$INPUT_IMG" --out icon.iconset/icon_256x256@2x.png

iconutil -c icns icon.iconset -o "$OUTPUT_ICONS"
rm -rf icon.iconset
}

# Update Info.plist
update_plist() {
local CONTENTSDIR=$1
local ICON_NAME=$2
local EXECUTABLE_NAME=$3

/usr/libexec/PlistBuddy -c 'Add :CFBundleDevelopmentRegion string English' "$CONTENTSDIR/Info.plist" 1>/dev/null
/usr/libexec/PlistBuddy -c "Add :CFBundleIconFile string $ICON_NAME" "$CONTENTSDIR/Info.plist"
/usr/libexec/PlistBuddy -c 'Add :CFBundleInfoDictionaryVersion string 6.0' "$CONTENTSDIR/Info.plist"
/usr/libexec/PlistBuddy -c 'Add :CFBundlePackageType string APPL' "$CONTENTSDIR/Info.plist"
/usr/libexec/PlistBuddy -c 'Add :CFBundleShortVersionString string 0.2' "$CONTENTSDIR/Info.plist"
/usr/libexec/PlistBuddy -c 'Add :CFBundleVersion string 0.2-10' "$CONTENTSDIR/Info.plist"
/usr/libexec/PlistBuddy -c 'Add :NSPrincipalClass string NSApplication' "$CONTENTSDIR/Info.plist"
/usr/libexec/PlistBuddy -c "Add :CFBundleExecutable string $EXECUTABLE_NAME" "$CONTENTSDIR/Info.plist"
/usr/libexec/PlistBuddy -c 'Add :LSUIElement bool true' "$CONTENTSDIR/Info.plist"
}

# Create app launch script
create_launch_script() {
local CONTENTSDIR=$1
local EXECUTABLE_NAME=$2
local COMMAND=$3

cat << ENDOFSCRIPT > "$CONTENTSDIR/MacOS/$EXECUTABLE_NAME"
#!/usr/bin/env bash

export PATH=$PATH:/usr/local/bin/IMSProg_editor
bash -c "$COMMAND > /dev/null 2>&1 &"
ENDOFSCRIPT

chmod u+x "$CONTENTSDIR/MacOS/$EXECUTABLE_NAME"
}

move_app() {
local APP_NAME=$1
mv "$APP_NAME" /Applications/"$APP_NAME"
}

create_imsprog_app() {
create_directories "$CONTENTSDIR1"
generate_iconset "img/logo_IMSProg.svg" "$CONTENTSDIR1/Resources/IMSProg.icns"
update_plist "$CONTENTSDIR1" "IMSProg.icns" "IMSProg"
create_launch_script "$CONTENTSDIR1" "IMSProg" "/usr/local/bin/IMSProg"
move_app "IMSProg.app"
}

create_imsprog_editor_app() {
create_directories "$CONTENTSDIR2"
generate_iconset "IMSProg_editor/img/chipEdit64.png" "$CONTENTSDIR2/Resources/IMSProg_editor.icns"
update_plist "$CONTENTSDIR2" "IMSProg_editor.icns" "IMSProg_Editor"
create_launch_script "$CONTENTSDIR2" "IMSProg_Editor" "/usr/local/bin/IMSProg_editor"
move_app "IMSProg Editor.app"
}

create_imsprog_database_update_app() {
create_directories "$CONTENTSDIR3"
generate_iconset "IMSProg_programmer/img/IMSProg_database_update.png" "$CONTENTSDIR3/Resources/IMSProg_database_update.icns"
update_plist "$CONTENTSDIR3" "IMSProg_database_update.icns" "IMSProg_database_update"
create_launch_script "$CONTENTSDIR3" "IMSProg_database_update" "/usr/local/bin/IMSProg_database_update"
move_app "IMSProg Database Update.app"
}

# Run the functions to create the apps
create_imsprog_app > /dev/null
create_imsprog_editor_app > /dev/null
create_imsprog_database_update_app > /dev/null
49 changes: 49 additions & 0 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

bold=$(tput bold)
normal=$(tput sgr0)
files=()

if [[ "$OSTYPE" == "darwin"* ]]; then
CMAKE_INSTALL_PREFIX='/usr/local'
files+=(
"/Applications/IMSProg.app"
"/Applications/IMSProg Database Update.app"
"/Applications/IMSProg Editor.app")
else
CMAKE_INSTALL_PREFIX='/usr'
fi

files+=(
"${CMAKE_INSTALL_PREFIX}/bin/IMSProg"
"${CMAKE_INSTALL_PREFIX}/share/pixmaps"
"${CMAKE_INSTALL_PREFIX}/share/imsprog"
"${CMAKE_INSTALL_PREFIX}/share/doc/imsprog"
"${CMAKE_INSTALL_PREFIX}/bin/IMSProg_database_update"
"${CMAKE_INSTALL_PREFIX}/share/applications/IMSProg_database_update.desktop"
"${CMAKE_INSTALL_PREFIX}/share/man/man1/IMSProg.1.gz"
"${CMAKE_INSTALL_PREFIX}/share/man/man1/IMSProg_database_update.1.gz"
"${CMAKE_INSTALL_PREFIX}/share/metainfo/io.github.bigbigmdm.imsprog.metainfo.xml"
"${CMAKE_INSTALL_PREFIX}/share/metainfo/io.github.bigbigmdm.imsprog_database_update.metainfo.xml"
"${CMAKE_INSTALL_PREFIX}/bin/IMSProg_editor"
"${CMAKE_INSTALL_PREFIX}/share/man/man1/IMSProg_editor.1.gz"
"${CMAKE_INSTALL_PREFIX}/share/metainfo/io.github.bigbigmdm.imsprog_editor.metainfo.xml"
"${HOME}/.local/share/imsprog")

echo "${bold}Warning: This script will permanently delete the following files and directories:${normal}"

for file in "${files[@]}"; do
echo "${bold}\"$file\"${normal}"
done

read -rp "Are you sure you want to proceed? (Y/n): " confirm
confirm=${confirm:-y}

if [[ $confirm != "y" && $confirm != "Y" ]]; then
echo "Operation Canceled."
exit 1
fi

for file in "${files[@]}"; do
sudo rm -rf "$file"
done && echo Uninstall Complete
Loading