Browse Source

Start support for unattended installs.

Issue 1319


git-svn-id: http://svn.dmdirc.com/trunk@4172 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Shane Mc Cormack 16 years ago
parent
commit
243120c1ac

+ 23
- 24
src/com/dmdirc/installer/Installer.java View File

35
  * @author Shane Mc Cormack
35
  * @author Shane Mc Cormack
36
  */
36
  */
37
 public abstract class Installer extends Thread {
37
 public abstract class Installer extends Thread {
38
-    
38
+	
39
 	/** Types of shortcut. */
39
 	/** Types of shortcut. */
40
 	public static enum ShortcutType {
40
 	public static enum ShortcutType {
41
-        /** Desktop shortcut. */
42
-        DESKTOP,
43
-        /** Menu (start/k/etc) shortcut. */
44
-        MENU,
45
-        /** Quick launch shortcut. */
46
-        QUICKLAUNCH,
47
-        /** The actual uninstaller (not a shortcut, as far as I can tell). */
48
-        UNINSTALLER,
49
-        /** Associate DMDirc with the irc:// protocol (not a shortcut). */
50
-        PROTOCOL;
51
-    }
41
+		/** Desktop shortcut. */
42
+		DESKTOP,
43
+		/** Menu (start/k/etc) shortcut. */
44
+		MENU,
45
+		/** Quick launch shortcut. */
46
+		QUICKLAUNCH,
47
+		/** The actual uninstaller (not a shortcut, as far as I can tell). */
48
+		UNINSTALLER,
49
+		/** Associate DMDirc with the irc:// protocol (not a shortcut). */
50
+		PROTOCOL;
51
+	}
52
 	
52
 	
53
 	/** Step where things happen. */
53
 	/** Step where things happen. */
54
 	protected StepInstall step;
54
 	protected StepInstall step;
55
-    
55
+	
56
 	/**
56
 	/**
57
 	 * Create a new Installer.
57
 	 * Create a new Installer.
58
 	 */
58
 	 */
59
 	public Installer() {
59
 	public Installer() {
60
 		super("Installer-Thread");
60
 		super("Installer-Thread");
61
-	}    
61
+	}
62
 	
62
 	
63
 	/**
63
 	/**
64
 	 * Get the default install location.
64
 	 * Get the default install location.
65
-     * 
66
-     * @return The default install location
65
+	 *
66
+	 * @return The default install location
67
 	 */
67
 	 */
68
 	public abstract String defaultInstallLocation();
68
 	public abstract String defaultInstallLocation();
69
 	
69
 	
80
 	/**
80
 	/**
81
 	 * This step performs the installation, via the StepInstall step.
81
 	 * This step performs the installation, via the StepInstall step.
82
 	 */
82
 	 */
83
-    @Override
83
+	@Override
84
 	public final void run() {
84
 	public final void run() {
85
 		step.performInstall(this);
85
 		step.performInstall(this);
86
 	}
86
 	}
107
 		try {
107
 		try {
108
 			final File dir = new File(".");
108
 			final File dir = new File(".");
109
 			final FilenameFilter filter = new FilenameFilter() {
109
 			final FilenameFilter filter = new FilenameFilter() {
110
-                /** {@inheritDoc} */
111
-                @Override
110
+				/** {@inheritDoc} */
111
+				@Override
112
 				public boolean accept(final File dir, final String name) {
112
 				public boolean accept(final File dir, final String name) {
113
 					return name.charAt(0) != '.' && validFile(name);
113
 					return name.charAt(0) != '.' && validFile(name);
114
 				}
114
 				}
160
 	 * Based on http://www.exampledepot.com/egs/java.io/CopyFile.html
160
 	 * Based on http://www.exampledepot.com/egs/java.io/CopyFile.html
161
 	 *
161
 	 *
162
 	 * @param srcFile Original file
162
 	 * @param srcFile Original file
163
-     * @param dstFile New file
164
-     * @throws java.io.IOException If an exception occurs while copying
163
+	 * @param dstFile New file
164
+	 * @throws java.io.IOException If an exception occurs while copying
165
 	 */
165
 	 */
166
 	protected final void copyFile(final String srcFile, final String dstFile) throws IOException {
166
 	protected final void copyFile(final String srcFile, final String dstFile) throws IOException {
167
 		if (new File(srcFile).exists()) {
167
 		if (new File(srcFile).exists()) {
184
 	 * @param location Location where app was installed to.
184
 	 * @param location Location where app was installed to.
185
 	 */
185
 	 */
186
 	public void postInstall(final String location) {
186
 	public void postInstall(final String location) {
187
-        // Nothing to do by default, installers may override
188
-    }
189
-    
187
+		// Nothing to do by default, installers may override
188
+	}
190
 }
189
 }

+ 3
- 3
src/com/dmdirc/installer/LinuxInstaller.java View File

47
 	 * @param filename File to check
47
 	 * @param filename File to check
48
 	 * @return true If the file should be copied, else false.
48
 	 * @return true If the file should be copied, else false.
49
 	 */
49
 	 */
50
-    @Override
50
+	@Override
51
 	public boolean validFile(final String filename) {
51
 	public boolean validFile(final String filename) {
52
 		return (!filename.equalsIgnoreCase("setup.sh") &&
52
 		return (!filename.equalsIgnoreCase("setup.sh") &&
53
 		        !filename.equalsIgnoreCase("getjre.sh") &&
53
 		        !filename.equalsIgnoreCase("getjre.sh") &&
56
 	}
56
 	}
57
 
57
 
58
 	/** {@inheritDoc} */
58
 	/** {@inheritDoc} */
59
-    @Override
59
+	@Override
60
 	public String defaultInstallLocation() {
60
 	public String defaultInstallLocation() {
61
 		String result = "";
61
 		String result = "";
62
 		if (CLIParser.getCLIParser().getParamNumber("-directory") > 0) {
62
 		if (CLIParser.getCLIParser().getParamNumber("-directory") > 0) {
78
 	 * @param shortcutType Type of shortcut to check
78
 	 * @param shortcutType Type of shortcut to check
79
 	 * @return True if this OS supports a given shortcut Type
79
 	 * @return True if this OS supports a given shortcut Type
80
 	 */
80
 	 */
81
-    @Override
81
+	@Override
82
 	public boolean supportsShortcut(final ShortcutType shortcutType) {
82
 	public boolean supportsShortcut(final ShortcutType shortcutType) {
83
 		switch (shortcutType) {
83
 		switch (shortcutType) {
84
 			case QUICKLAUNCH:
84
 			case QUICKLAUNCH:

+ 21
- 14
src/com/dmdirc/installer/Main.java View File

42
  * @author Shane Mc Cormack
42
  * @author Shane Mc Cormack
43
  */
43
  */
44
 public final class Main implements WizardListener {
44
 public final class Main implements WizardListener {
45
-
46
-    /** Wizard dialog. */
45
+	
46
+	/** Wizard dialog. */
47
 	private static WizardFrame wizardDialog;
47
 	private static WizardFrame wizardDialog;
48
 	
48
 	
49
 	/** Installer. */
49
 	/** Installer. */
51
 	
51
 	
52
 	/** CLI Parser. */
52
 	/** CLI Parser. */
53
 	private static CLIParser cli = CLIParser.getCLIParser();
53
 	private static CLIParser cli = CLIParser.getCLIParser();
54
-
54
+	
55
 	/**
55
 	/**
56
 	 * Creates and Displays the Installer wizard.
56
 	 * Creates and Displays the Installer wizard.
57
 	 */
57
 	 */
68
 		}
68
 		}
69
 		
69
 		
70
 		setWizardFrame(new WizardFrame(releaseName + " Installer", new ArrayList<Step>(), this));
70
 		setWizardFrame(new WizardFrame(releaseName + " Installer", new ArrayList<Step>(), this));
71
-        wizardDialog.setIconImage(IconManager.getIconManager().getImage("icon"));
71
+		wizardDialog.setIconImage(IconManager.getIconManager().getImage("icon"));
72
 		wizardDialog.setPreferredSize(new Dimension(400, 350));
72
 		wizardDialog.setPreferredSize(new Dimension(400, 350));
73
 		wizardDialog.addWizardListener(this);
73
 		wizardDialog.addWizardListener(this);
74
 
74
 
77
 		if (osName.startsWith("Mac OS")) {
77
 		if (osName.startsWith("Mac OS")) {
78
 			wizardDialog.addStep(new StepError("Sorry, OSX Installation should be done using the downloadable dmg file, not this installer.\n\n"));
78
 			wizardDialog.addStep(new StepError("Sorry, OSX Installation should be done using the downloadable dmg file, not this installer.\n\n"));
79
 		} else {
79
 		} else {
80
-			wizardDialog.addStep(new StepSettings());
81
-			wizardDialog.addStep(new StepConfirm(wizardDialog));
80
+			if (CLIParser.getCLIParser().getParamNumber("-unattended") == 0) {
81
+				wizardDialog.addStep(new StepSettings());
82
+				wizardDialog.addStep(new StepConfirm(wizardDialog));
83
+			}
82
 			wizardDialog.addStep(new StepInstall(wizardDialog));
84
 			wizardDialog.addStep(new StepInstall(wizardDialog));
83
 		}
85
 		}
84
 	}
86
 	}
85
-    
87
+		
86
 	/**
88
 	/**
87
 	 * Called when the wizard finishes.
89
 	 * Called when the wizard finishes.
88
 	 */
90
 	 */
89
-    @Override
91
+	@Override
90
 	public void wizardFinished() {
92
 	public void wizardFinished() {
91
 		final Thread temp = myInstaller;
93
 		final Thread temp = myInstaller;
92
 		myInstaller = null;
94
 		myInstaller = null;
97
 	/**
99
 	/**
98
 	 * Called when the wizard is cancelled.
100
 	 * Called when the wizard is cancelled.
99
 	 */
101
 	 */
100
-    @Override
102
+	@Override
101
 	public void wizardCancelled() {	
103
 	public void wizardCancelled() {	
102
 		if (wizardDialog.getCurrentStep() != 3 && JOptionPane.showConfirmDialog(wizardDialog, "Are you sure you want to cancel?", "Cancel confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
104
 		if (wizardDialog.getCurrentStep() != 3 && JOptionPane.showConfirmDialog(wizardDialog, "Are you sure you want to cancel?", "Cancel confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
103
 			wizardDialog.dispose();
105
 			wizardDialog.dispose();
104
 		}
106
 		}
105
-	}    
107
+	}
106
 	
108
 	
107
 	/**
109
 	/**
108
 	 * Get the Installer object for this OS.
110
 	 * Get the Installer object for this OS.
109
-     * 
110
-     * @return The installer for this OS
111
+	 *
112
+	 * @return The installer for this OS
111
 	 */
113
 	 */
112
 	public static synchronized Installer getInstaller() {
114
 	public static synchronized Installer getInstaller() {
113
 		if (myInstaller == null) {
115
 		if (myInstaller == null) {
133
 		cli.add(new BooleanParam((char) 0, "isroot", "Installing as Root"));
135
 		cli.add(new BooleanParam((char) 0, "isroot", "Installing as Root"));
134
 		cli.add(new StringParam('r', "release", "Release Name"));
136
 		cli.add(new StringParam('r', "release", "Release Name"));
135
 		cli.add(new StringParam('d', "directory", "Default install directory"));
137
 		cli.add(new StringParam('d', "directory", "Default install directory"));
138
+		cli.add(new BooleanParam('u', "unattended", "Perform an unattended installation"));
139
+		cli.add(new BooleanParam((char) 0, "no-shortcut-desktop", "Don't offer a desktop shortcut as the default"));
140
+		cli.add(new BooleanParam((char) 0, "no-shortcut-menu", "Don't offer a menu shortcut as the default"));
141
+		cli.add(new BooleanParam((char) 0, "no-shortcut-quicklaunch", "Don't offer a quick launch shortcut as the default"));
142
+		cli.add(new BooleanParam((char) 0, "no-shortcut-protocol", "Don't offer to handle irc:// links as the default"));
136
 	}
143
 	}
137
 	
144
 	
138
 	/**
145
 	/**
158
 
165
 
159
 	/**
166
 	/**
160
 	 * Run the installer.
167
 	 * Run the installer.
161
-     * 
162
-     * @param args Command line arguments
168
+	 *
169
+	 * @param args Command line arguments
163
 	 */
170
 	 */
164
 	public static void main(final String[] args) {
171
 	public static void main(final String[] args) {
165
 		setupCLIParser();
172
 		setupCLIParser();

+ 6
- 3
src/com/dmdirc/installer/StepInstall.java View File

22
 
22
 
23
 package com.dmdirc.installer;
23
 package com.dmdirc.installer;
24
 
24
 
25
+import com.dmdirc.installer.cliparser.CLIParser;
25
 import com.dmdirc.installer.Installer.ShortcutType;
26
 import com.dmdirc.installer.Installer.ShortcutType;
26
 import com.dmdirc.ui.swing.dialogs.wizard.Step;
27
 import com.dmdirc.ui.swing.dialogs.wizard.Step;
27
 import com.dmdirc.ui.swing.dialogs.wizard.StepListener;
28
 import com.dmdirc.ui.swing.dialogs.wizard.StepListener;
92
 	 */
93
 	 */
93
 	public void performInstall(final Installer myInstaller) {
94
 	public void performInstall(final Installer myInstaller) {
94
 		infoLabel.setText("Beginning Install..\n");
95
 		infoLabel.setText("Beginning Install..\n");
95
-		final String location = ((StepSettings) Main.getWizardFrame().getStep(1)).getInstallLocation();
96
+		
97
+		final boolean isUnattended = (CLIParser.getCLIParser().getParamNumber("-unattended") == 0);
98
+		final StepSettings settings = (isUnattended) ? new StepSettings() : ((StepSettings) Main.getWizardFrame().getStep(1));
99
+		
100
+		final String location = settings.getInstallLocation();
96
 
101
 
97
 		addText("Installing files to: "+location);
102
 		addText("Installing files to: "+location);
98
 		if (!myInstaller.doSetup(location)) {
103
 		if (!myInstaller.doSetup(location)) {
102
 			return;
107
 			return;
103
 		}
108
 		}
104
 
109
 
105
-		StepSettings settings = ((StepSettings) Main.getWizardFrame().getStep(1));
106
-
107
 		if (Main.getInstaller().supportsShortcut(ShortcutType.MENU)) {
110
 		if (Main.getInstaller().supportsShortcut(ShortcutType.MENU)) {
108
 			if (settings.getShortcutMenuState()) {
111
 			if (settings.getShortcutMenuState()) {
109
 				addText("Setting up "+Main.getInstaller().getMenuName()+" shortcut");
112
 				addText("Setting up "+Main.getInstaller().getMenuName()+" shortcut");

+ 5
- 4
src/com/dmdirc/installer/StepSettings.java View File

22
 
22
 
23
 package com.dmdirc.installer;
23
 package com.dmdirc.installer;
24
 
24
 
25
+import com.dmdirc.installer.cliparser.CLIParser;
25
 import com.dmdirc.installer.Installer.ShortcutType;
26
 import com.dmdirc.installer.Installer.ShortcutType;
26
 import com.dmdirc.ui.swing.dialogs.wizard.Step;
27
 import com.dmdirc.ui.swing.dialogs.wizard.Step;
27
 import com.dmdirc.ui.swing.components.TextLabel;
28
 import com.dmdirc.ui.swing.components.TextLabel;
79
 //		infoLabel.setBackground(getBackground());
80
 //		infoLabel.setBackground(getBackground());
80
 		infoLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, SMALL_BORDER, 0));
81
 		infoLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, SMALL_BORDER, 0));
81
 
82
 
82
-		shortcutMenu.setSelected(true);
83
-		shortcutDesktop.setSelected(true);
84
-		shortcutQuick.setSelected(true);
85
-		shortcutProtocol.setSelected(true);
83
+		shortcutMenu.setSelected((CLIParser.getCLIParser().getParamNumber("-no-shortcut-menu") == 0));
84
+		shortcutDesktop.setSelected((CLIParser.getCLIParser().getParamNumber("-no-shortcut-desktop") == 0));
85
+		shortcutQuick.setSelected((CLIParser.getCLIParser().getParamNumber("-no-shortcut-quicklaunch") == 0));
86
+		shortcutProtocol.setSelected((CLIParser.getCLIParser().getParamNumber("-no-shortcut-protocol") == 0));
86
 
87
 
87
 		constraints.weightx = 1.0;
88
 		constraints.weightx = 1.0;
88
 		constraints.fill = constraints.BOTH;
89
 		constraints.fill = constraints.BOTH;

+ 3
- 3
src/com/dmdirc/installer/StreamReader.java View File

28
 import java.io.InputStreamReader;
28
 import java.io.InputStreamReader;
29
 
29
 
30
 public class StreamReader extends Thread {
30
 public class StreamReader extends Thread {
31
-    
31
+	
32
 	/** This is the Input Stream we are reading */
32
 	/** This is the Input Stream we are reading */
33
 	private final InputStream stream;
33
 	private final InputStream stream;
34
 	
34
 	
66
 		}
66
 		}
67
 	}
67
 	}
68
 
68
 
69
-    /** {@inheritDoc} */
70
-    @Override
69
+	/** {@inheritDoc} */
70
+	@Override
71
 	public void run() {
71
 	public void run() {
72
 		final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
72
 		final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
73
 		try {
73
 		try {

Loading…
Cancel
Save