This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathenvironment.sh
183 lines (160 loc) · 3.86 KB
/
environment.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
## Winbuntu - The Ubuntu Linux Environment for Windows 10
## An awesome Linux environment that runs using WSL on Windows 10
##
## Author: Adam Thompson <[email protected]>
#####
# Color definitions
#####
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
#####
# The environment configuration
#####
typeset -A config # init array
config=( # set default values in config array
[gitRepo]="https://github.com/serialphotog/winbuntu-config.git"
[workingDir]="/tmp/winbuntu/"
[guiCommand]="i3"
)
#####
# Global Vars
#####
SESSION_CONF_PATH='/etc/dbus-1/session.conf'
#####
# Installer Functions
#####
# Installs git on the system
function install_git()
{
echo "Installing git..."
sudo -s apt-get -y install git
if type "git" > /dev/null; then
echo -e "${GREEN}Git successfully installed${NC}"
fi
}
# Installs Xterm
function install_xterm()
{
echo "Installing xterm..."
sudo -s apt-get -y install xterm
if type "xterm" > /dev/null; then
echo -e "${GREEN}Xterm successfully installed${NC}"
fi
}
#####
# Core Functions
#####
# Checks that required apps are present
function check_required_apps()
{
if ! type "git" > /dev/null; then
echo -e "${RED}Git not found${NC}"
install_git
else
echo -e "${GREEN}Found git${NC}"
fi
if ! type "xterm" > /dev/null; then
echo -e "${RED}Xterm not found${NC}"
install_xterm
else
echo -e "${GREEN}Found Xterm${NC}"
fi
}
# Clones our configuration repository
function clone_setup()
{
# Make sure the working directory exists
mkdir -p ${config[workingDir]}
git clone ${config[gitRepo]} ${config[workingDir]}
}
# Installs required packages from repo file
function install_packages()
{
# Check that PACKAGES file exists
if [ -f ${config[workingDir]}/PACKAGES ]; then
echo -e "${GREEN}Found PACKAGES file. Installing...${NC}"
for i in `cat ${config[workingDir]}/PACKAGES`
do
if ! dpkg-query -W -f='${Status} ${Version}\n' ${i} | grep "^install ok" > /dev/null ; then
echo "Installing package ${i}"
sudo apt-get install -y ${i}
else
echo "Pakcage ${i} is already installed. Skipping..."
fi
done
else
echo -e "${RED}No PACKAGES file found. Skipping package installation...${NC}"
fi
}
# Installs the dotfiles
function dotfiles()
{
if [ -d ${config[workingDir]}dotfiles ]; then
cp -rf ${config[workingDir]}dotfiles/. ~/
else
echo -e "${RED}Dotfiles dir not found. Skipping..."
fi
}
# Run all config scripts in scripts dir
function run_scripts()
{
if [ -d ${config[workingDir]}scripts ]; then
echo -e "${GREEN}Found scripts directory. Running...${NC}"
for script in ${config[workingDir]}scripts/*
do
chmod +x $script
$script
done
else
echo -e "${RED}No scripts directory found. Skipping...${NC}"
fi
}
# Launches the GUI interface
function gui()
{
if [ -z "${config[guiCommand]//}" ]; then
echo -e "${RED}No gui command specified. Skipping...${NC}"
else
DISPLAY=localhost:0 exec ${config[guiCommand]}
fi
}
# Applies the dbus fix
function dbus_fix()
{
# Delete old session.conf if exists
if [ -e $SESSION_CONF_PATH ]; then
sudo rm $SESSION_CONF_PATH
fi
#Download new session.conf and apply fix
SESSION_CONF_GIST='https://gist.githubusercontent.com/serialphotog/444917d8e8e327d873cc5bf1a0fa2232/raw/ea271023ae692d9e1eff875531fd90f543935eaf/winbuntu-session.conf'
curl -k $SESSION_CONF_GIST > '/tmp/session.conf'
sudo -s cp '/tmp/session.conf' $SESSION_CONF_PATH
}
# Checks if the dbus fix has been applied
function check_dbus_fix()
{
DBUS_FIX='<listen>tcp:host=localhost,port=0</listen>'
if [ -e $SESSION_CONF_PATH ] && grep -q $DBUS_FIX $SESSION_CONF_PATH; then
echo -e "${GREEN}Detected dbus fix.${NC}"
else
echo -e "${RED}No dbus fix found. Applying it now...${NC}"
dbus_fix
fi
}
# The main runtime
function main()
{
check_required_apps
clone_setup
install_packages
dotfiles
run_scripts
check_dbus_fix
gui
}
#####
# Run the environment setup
#####
main