Skip to content

Commit

Permalink
refering multiple Installation profiles sotred at /sdcard/profiles/
Browse files Browse the repository at this point in the history
NativeHelper.java: scans all the present profiles and create required
Installation profiles
LilDebi.java: layout and selection of Install Profile
InstallService.java: install the profile along with debian
lildebi.xml: layout for choosing the profile
strings.xml:
  • Loading branch information
myselfjivan committed Jul 20, 2015
1 parent 58c0a14 commit 3ec147e
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 1 deletion.
27 changes: 27 additions & 0 deletions res/layout/lildebi.xml
Expand Up @@ -41,6 +41,33 @@
android:layout_height="wrap_content"
android:text="@string/title_start" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/selectInstallationProfile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/select_profile" />

<Spinner
android:id="@+id/selectProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />

<TextView
android:id="@+id/selectedProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/selectProfile"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp" />
</LinearLayout>

<ScrollView
android:id="@+id/consoleScroll"
Expand Down
1 change: 1 addition & 0 deletions res/values/strings.xml
Expand Up @@ -69,5 +69,6 @@
<string name="pref_install_on_internal_storage_title">Install on Internal Storage</string>
<string name="install_in_internal_storage_summary">Install Debian into Internal Storage: /data/debian</string>
<string name="not_enough_space">Not enough space (&lt; 250MB)</string>
<string name="select_profile">Select Installation Profile</string>

</resources>
1 change: 1 addition & 0 deletions src/info/guardianproject/lildebi/InstallService.java
Expand Up @@ -99,6 +99,7 @@ public void run() {
command += "\\\n&& " + NativeHelper.app_bin + "/chroot " + NativeHelper.mnt
+ " " + NativeHelper.app_bin + "/complete-debian-setup.sh "
+ stdArgs;
command += "\\\n&& " + NativeHelper.app_profiles + "./"+ LilDebi.selProfile + stdArgs;
writeCommand(os, "cd " + NativeHelper.app_bin.getAbsolutePath());
writeCommand(os, command);
// Avoid keeping the resource mounted because of some failure
Expand Down
54 changes: 53 additions & 1 deletion src/info/guardianproject/lildebi/LilDebi.java
Expand Up @@ -20,8 +20,12 @@
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -33,7 +37,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;

public class LilDebi extends Activity implements OnCreateContextMenuListener {
public class LilDebi extends Activity implements OnCreateContextMenuListener, OnItemSelectedListener {
public static final String TAG = "LilDebi";

private static TextView statusTitle;
Expand All @@ -45,6 +49,12 @@ public class LilDebi extends Activity implements OnCreateContextMenuListener {

private Handler commandThreadHandler;
private LilDebiAction action;

public static TextView selectInstallationProfile;
public static Spinner spinnerForProfile;
public static TextView selectedProfileTextView;
public static String selProfile;
public static ArrayAdapter<String> adapter_state;

private boolean foundSU = false;
Thread findSUThread = new Thread() {
Expand All @@ -64,6 +74,15 @@ protected void onCreate(Bundle savedInstanceState) {
startStopButton = (Button) findViewById(R.id.startStopButton);
consoleScroll = (ScrollView) findViewById(R.id.consoleScroll);
consoleText = (TextView) findViewById(R.id.consoleText);
selectInstallationProfile = (TextView) findViewById(R.id.selectInstallationProfile);
selectedProfileTextView = (TextView) findViewById(R.id.selectedProfile);
spinnerForProfile = (Spinner) findViewById(R.id.selectProfile);
adapter_state = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, NativeHelper.myGenProfileList);
adapter_state
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerForProfile.setAdapter(adapter_state);
spinnerForProfile.setOnItemSelectedListener(this);

// All SU calls are blocking calls. libsuperuser doen't allow
// to make such blocking calls from Main Thread.
Expand Down Expand Up @@ -197,6 +216,9 @@ private void updateScreenStatus() {
statusText.setText(R.string.no_sdcard_status);
savedStatus = R.string.no_sdcard_status;
startStopButton.setVisibility(View.GONE);
spinnerForProfile.setVisibility(View.GONE);
selectedProfileTextView.setVisibility(View.GONE);
selectInstallationProfile.setVisibility(View.GONE);
return;
}

Expand All @@ -211,6 +233,9 @@ private void updateScreenStatus() {
statusText.setVisibility(View.VISIBLE);
statusText.setText(R.string.needs_superuser_message);
savedStatus = R.string.needs_superuser_message;
selectInstallationProfile.setVisibility(View.GONE);
spinnerForProfile.setVisibility(View.GONE);
selectedProfileTextView.setVisibility(View.GONE);
startStopButton.setVisibility(View.VISIBLE);
startStopButton.setText(R.string.get_superuser);
startStopButton.setOnClickListener(new View.OnClickListener() {
Expand All @@ -233,6 +258,9 @@ public void onClick(View view) {
statusText.setVisibility(View.VISIBLE);
statusText.setText(R.string.not_configured_message);
savedStatus = R.string.not_configured_message;
selectInstallationProfile.setVisibility(View.GONE);
spinnerForProfile.setVisibility(View.GONE);
selectedProfileTextView.setVisibility(View.GONE);
startStopButton.setVisibility(View.VISIBLE);
startStopButton.setText(R.string.title_configure);
startStopButton.setOnClickListener(new View.OnClickListener() {
Expand All @@ -248,6 +276,9 @@ public void onClick(View view) {
statusText.setVisibility(View.GONE);
statusText.setText(R.string.mounted_message);
savedStatus = R.string.mounted_message;
selectInstallationProfile.setVisibility(View.GONE);
spinnerForProfile.setVisibility(View.GONE);
selectedProfileTextView.setVisibility(View.GONE);
startStopButton.setVisibility(View.VISIBLE);
startStopButton.setText(R.string.title_stop);
startStopButton.setOnClickListener(new View.OnClickListener() {
Expand All @@ -263,6 +294,9 @@ public void onClick(View view) {
statusText.setVisibility(View.VISIBLE);
statusText.setText(R.string.not_mounted_message);
savedStatus = R.string.not_mounted_message;
selectInstallationProfile.setVisibility(View.GONE);
spinnerForProfile.setVisibility(View.GONE);
selectedProfileTextView.setVisibility(View.GONE);
startStopButton.setVisibility(View.VISIBLE);
startStopButton.setText(R.string.title_start);
startStopButton.setOnClickListener(new View.OnClickListener() {
Expand All @@ -285,6 +319,9 @@ public void onClick(View view) {
statusText.setVisibility(View.VISIBLE);
statusText.setText(R.string.not_installed_message);
savedStatus = R.string.not_installed_message;
selectInstallationProfile.setVisibility(View.VISIBLE);
spinnerForProfile.setVisibility(View.VISIBLE);
selectedProfileTextView.setVisibility(View.VISIBLE);
startStopButton.setVisibility(View.VISIBLE);
startStopButton.setText(R.string.install);
startStopButton.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -392,4 +429,19 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
}
// the saved state is restored in onCreate()

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
long arg3) {
spinnerForProfile.setSelection(position);
selProfile = (String) spinnerForProfile.getSelectedItem();
selectedProfileTextView.setText("Selected profile:" + selProfile);

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// overriden method not used

}
}
95 changes: 95 additions & 0 deletions src/info/guardianproject/lildebi/NativeHelper.java
Expand Up @@ -2,15 +2,20 @@

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Scanner;

import android.content.Context;
Expand All @@ -28,6 +33,7 @@ public class NativeHelper {
public static File app_bin;
public static File app_log;
public static File install_log;
public static File app_profiles;
public static File publicFiles;
public static File sh;
public static File install_conf;
Expand All @@ -43,10 +49,24 @@ public class NativeHelper {
public static boolean isInstallRunning = false;
public static boolean installInInternalStorage;
public static boolean limitTo4GB;

public static File file;
public static String profileName;
public static String generatedFileName;
public static List<String> myProfileList = new ArrayList<String>();
public static List<String> myGenProfileList = new ArrayList<String>();
public static String DIRECTORY_PATH = "/data/data/info.guardianproject.lildebi/app_profiles";
public static String Name;
public static String path_to_install_script;
public static String path_to_pre_start_script;
public static String path_to_post_start_script;
public static String gui_support;
public static String fileName;

public static void setup(Context context) {
app_bin = context.getDir("bin", Context.MODE_PRIVATE).getAbsoluteFile();
app_log = context.getDir("log", Context.MODE_PRIVATE).getAbsoluteFile();
app_profiles = context.getDir("profiles", Context.MODE_PRIVATE).getAbsoluteFile();
install_log = new File(app_log, "install.log");
// this is the same as android-8's getExternalFilesDir() but works on android-1
publicFiles = new File(Environment.getExternalStorageDirectory(),
Expand Down Expand Up @@ -93,6 +113,81 @@ && new File(NativeHelper.mnt + "/etc").exists()
installInInternalStorage = prefs.getBoolean(prefName, detectedInternalInstall);
if (installInInternalStorage)
NativeHelper.image_path = NativeHelper.mnt;
try {
File folder = new File("/sdcard/profiles/");

This comment has been minimized.

Copy link
@myselfjivan

myselfjivan Jul 20, 2015

Author Owner

profiles stored at /sdcard/profiles are
profile.txt and profile1.txt

This comment has been minimized.

Copy link
@myselfjivan

myselfjivan Jul 20, 2015

Author Owner

profile.txt contains

Name = ssh
path_to_install_script = /etc/bin
path_to_pre_start_script = /etc/bin/1
path_to_post_start_script = /etc/bin/2
gui_support = no

This comment has been minimized.

Copy link
@myselfjivan

myselfjivan Jul 20, 2015

Author Owner

profile1.txt contains

Name = apache2
path_to_install_script = /etc/bin
path_to_pre_start_script = /etc/bin/1
path_to_post_start_script = /etc/bin/2
gui_support = no

File[] listOfFiles = folder.listFiles();
int countOfProfiles=0;
for (File file : listOfFiles) {
if (file.isFile()) {
profileName = file.getName();
myProfileList.add(profileName);
Log.d("all profiles ", profileName);
countOfProfiles++;
}
}
String n[] = new String[countOfProfiles];
for (int i = 0; i < countOfProfiles; i++) {
n[i] = myProfileList.get(i) ;
Log.d("[i] value", n[i]);
Log.d("No. of profiles", ""+countOfProfiles);
Log.d("printing data for ", ""+n[i]);
file = new File("/sdcard/profiles/" + n[i]);
Log.d("file name", file.getPath());
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream(file);
prop.load(input);
Name = prop.getProperty("Name");
path_to_install_script = prop.getProperty("path_to_install_script");
path_to_install_script = prop.getProperty("path_to_pre_start_script");
path_to_post_start_script = prop.getProperty("path_to_post_start_script");
gui_support = prop.getProperty("gui_support");
Log.d("Name", Name);
File root = new File(DIRECTORY_PATH);
fileName = Name + ".sh";
File gpxfile = new File(root, fileName);
FileWriter writer;
writer = new FileWriter(gpxfile);
StringBuilder s = new StringBuilder();
s.append("export TERM=linux \n");
s.append("export HOME=/root \n");
s.append("export PATH=$app_bin:/usr/bin:/usr/sbin:/bin:/sbin:$PATH \n");
s.append("apt-get install "+ Name);

writer.append(s);
writer.flush();
writer.close();

Log.d("Name", Name);
Log.d("path_to_install_script", path_to_install_script);
Log.d("path_to_install_script", path_to_install_script);
Log.d("path_to_post_start_script", path_to_post_start_script);
Log.d("gui_support", gui_support);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}catch (Exception e) {
e.printStackTrace();
}
try {
File folder = new File(DIRECTORY_PATH);
File[] listOfFiles = folder.listFiles();
int countOfGeneratedFiles =0;
for (File file : listOfFiles) {
if (file.isFile()) {
generatedFileName = file.getName();
myGenProfileList.add(generatedFileName);
chmod(0755, new File(app_profiles, generatedFileName));
Log.d("all generated files ", generatedFileName);
countOfGeneratedFiles++;
}
}
Log.d("countOfGeneratedFiles", ""+countOfGeneratedFiles);
} catch (Exception e) {
e.printStackTrace();
}
}

public static boolean isStarted() {
Expand Down

0 comments on commit 3ec147e

Please sign in to comment.