#!/bin/bash

if [[ ! `id -u` == '0' ]];then
	echo 'Run this as root!'
	exit 1
fi

echo 'Welcome to use Network magician.'
echo 'Please follow the prompts to modify the display text of the 2G 3G 4G network.'
echo 'Or follow the prompts to restore the display text of the 2G 3G 4G network.'

sleep 1

Version=`sw_vers -productVersion`
echo 'To restore the display text of the 2G 3G 4G network, press 1 and press Enter; to modify the display text of the 2G 3G 4G network, press 2 and press Enter.'
read -p 'Please select an option:' choice
if [[ $choice == '1' ]];then
	echo 'Restoring...'
	if [[ ${Version} == 11.* ]];then
		for i in /System/Library/Frameworks/UIKit.framework/*/Localizable.strings
		do
			plutil -key 2X -string 2X $i
			plutil -key 3G -string 3G $i
			plutil -key 4G -string 4G $i
		done
	elif [[ ${Version} == 12.* ]];then
		for i in /System/Library/PrivateFrameworks/UIKitCore.framework/*/Localizable.strings
		do
			plutil -key 2X -string 2X $i
			plutil -key 3G -string 3G $i
			plutil -key 4G -string 4G $i
		done
	else
		echo 'Invalid system version detected, maybe something wrong?'
	fi
	echo 'Cleaning Cache...'
	rm -rf /var/mobile/Library/Caches/com.apple.UIStatusBar/*
	echo 'Done, device will respring now :)'
	sleep 2
	killall -9 SpringBoard
elif [[ $choice == '2' ]];then
	read -p 'Please select a display text for the 2G network; if you do not want to modify it, please press Enter directly:' choice2X
	read -p 'Please select a display text for the 3G network; if you do not want to modify it, please press Enter directly:' choice3G
	read -p 'Please select a display text for the 4G network; if you do not want to modify it, please press Enter directly:' choice4G
	echo 'Selecting...'
	if [[ ${Version} == 11.* ]];then
		for i in /System/Library/Frameworks/UIKit.framework/*/Localizable.strings
		do
			if [ $choice2X ];then
				plutil -key 2X -string $choice2X $i
			fi
			if [ $choice3G ];then
				plutil -key 3G -string $choice3G $i
			fi
			if [ $choice4G ];then
				plutil -key 4G -string $choice4G $i
			fi
		done
	elif [[ ${Version} == 12.* ]];then
		for i in /System/Library/PrivateFrameworks/UIKitCore.framework/*/Localizable.strings
		do
			if [ $choice2X ];then
				plutil -key 2X -string $choice2X $i
			fi
			if [ $choice3G ];then
				plutil -key 3G -string $choice3G $i
			fi
			if [ $choice4G ];then
				plutil -key 4G -string $choice4G $i
			fi
		done
	else
		echo 'Invalid system version detected, maybe something wrong?'
	fi
	echo 'Cleaning Cache...'
	rm -rf /var/mobile/Library/Caches/com.apple.UIStatusBar/*
	echo 'Done, device will respring now :)'
	sleep 2
	if [[ -f /usr/bin/sbreload ]];then
		sbreload
	else
		killall -9 backboardd
	fi
else
	echo 'Invalid parameters, you may have no idea what you are doing, now exit.'
	sleep 2
	exit 1
fi
