summarylogtreecommitdiffstats
path: root/install_java_jce_ustrength
blob: 497278b41e106b11296f2a79153375f3bb4e1026 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash

# The affected files:
# dabfcb23d7bf9bf5a201c3f6ea9bfb2c  local_policy.jar
# ef6e8eae7d1876d7f05d765d2c2e0529  US_export_policy.jar

# Internal variables
md5_this_localpolicy=dabfcb23d7bf9bf5a201c3f6ea9bfb2c
md5_this_uspolicy=ef6e8eae7d1876d7f05d765d2c2e0529
jcedir=/usr/share/java/java-jce_ustrength
jresecuritydir=/usr/lib/jvm/default-runtime/lib/security
_ext=java-jce_ustrength.backup

# 1 = Root
# 0 = other ID
check_root(){
	if [ ${UID} -eq 0 ]; then
		return 1
	fi
	return 0
}

# 0 = Unlimited Strength JCE Policy already installed
# 1 = Original JCE Policy installed
# 2 = Destination files don't exist
check_destinationfiles(){
	if [ ! -e "${jresecuritydir}/US_export_policy.jar" -o ! -e "${jresecuritydir}/local_policy.jar" ];
	then
		return 2
	fi
	md5_uspolicy=$(md5sum ${jresecuritydir}/US_export_policy.jar | cut -d " " -f 1)
	md5_localpolicy=$(md5sum ${jresecuritydir}/local_policy.jar | cut -d " " -f 1)
	if [ "${md5_uspolicy}" == "${md5_this_uspolicy}" -a \
	     "${md5_localpolicy}" == "${md5_this_localpolicy}" ]; then
	     return 0
        fi
	return 1
}

install(){
	check_destinationfiles
	not_installed=$?
	if [ "${not_installed}" -eq "1" ]; then
		check_root
		isroot=$?
		if [ "${isroot}" -eq "0" ]; then
			echo "You must be root for doing this operation."
			exit 1
		fi
		echo -n "Installing Unlimited Strength JCE files..."
		cp ${jresecuritydir}/US_export_policy.jar ${jresecuritydir}/US_export_policy.jar.${_ext} || return 1
		cp ${jresecuritydir}/local_policy.jar ${jresecuritydir}/local_policy.jar.${_ext} || return 1
		cp ${jcedir}/US_export_policy.jar ${jresecuritydir}/ || return 1
		cp ${jcedir}/local_policy.jar ${jresecuritydir}/ || return 1
		echo " installed."
	else 
		echo "Unlimited Strength JCE files already installed."
	fi
}

uninstall(){
	check_destinationfiles
	not_installed=$?
	if [ "$not_installed" -eq "0" ]; then
		check_root
		isroot=$?
		if [ "${isroot}" -eq "0" ]; then
			echo "You must be root for doing this operation."
			exit 0
		fi
		echo -n "Uninstalling Unlimited Strength JCE files..."
		if [ ! -e "${jresecuritydir}/US_export_policy.jar.${_ext}" -a \
		     ! -e "${jresecuritydir}/local_policy.jar.${_ext}" ]; then
		     echo "Previous backup of the files doesn't exist!"
		     echo "For uninstall, reinstall the jre package."
		     exit 0
		fi

		mv ${jresecuritydir}/US_export_policy.jar.${_ext} ${jresecuritydir}/US_export_policy.jar || return 1
		mv ${jresecuritydir}/local_policy.jar.${_ext} ${jresecuritydir}/local_policy.jar || return 1
		echo " uninstalled."
	else 
		if [ -e "${jresecuritydir}/US_export_policy.jar.${_ext}" -a \
		     -e "${jresecuritydir}/local_policy.jar.${_ext}" ]; then
		     check_root
		     isroot=$?
		     if [ "${isroot}" -eq "0" ]; then
			echo "You must be root for doing this operation."
			exit 1
	      	     fi
		     echo -n "Deleting old regular JCE files backup..."
		     rm ${jresecuritydir}/US_export_policy.jar.${_ext} || return 1
		     rm ${jresecuritydir}/local_policy.jar.${_ext} || return 1
		     echo  " deleted."
		fi

		if [ "${not_installed}" -eq "1" ]; then
			echo "Regular JCE files already installed."
		fi
	fi
}

case "$1" in
	install) install
		 ;;
	uninstall) uninstall
		   ;;
	*) echo "Usage $0: {install|uninstall}"
	   ;;
esac
exit 0