-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathchain.script
More file actions
executable file
·321 lines (240 loc) · 9.98 KB
/
chain.script
File metadata and controls
executable file
·321 lines (240 loc) · 9.98 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# --------------------------------- Debug -------------------------------------
debugsprite = Sprite();
// Print a message in the top left-hand corner
fun debug(text) {
debugsprite.SetImage(Image.Text(text, 0.8, 0.8, 0.8, 0.8));
}
# --------------------------------- Colors ------------------------------------
#
# WARNING : colors should be changed using the change-color.sh script
# to avoid issues and be consistent with the animation and other
# graphical elements.
// Background color components
BG_COLOR.red = 0.06666;
BG_COLOR.green = 0.06666;
BG_COLOR.blue = 0.06666;
// Main theme color components
MAIN_COLOR.red = 0.74509;
MAIN_COLOR.green = 0.19215;
MAIN_COLOR.blue = 0.26666;
// Secondary color components
SECONDARY_COLOR.red = 0.25490;
SECONDARY_COLOR.green = 0.25490;
SECONDARY_COLOR.blue = 0.25490;
# ----------------------------- Configuration ---------------------------------
// Font for boot message
MAIN_FONT = "NotoSans Bold 22";
// Font for password prompt
SECONDARY_FONT = "NotoSans Regular 16";
// Position of the animation in percentage of the screen dimensions
LOGO.center.x = 0.5;
LOGO.center.y = 0.5;
// Position of the boot message in percentage of the screen dimensions
BOOT_MESSAGE.center.x = 0.5;
BOOT_MESSAGE.center.y = 0.65;
// Position of the progress bar in percentage of the screen dimensions
BAR.center.x = 0.5;
BAR.center.y = 0.7;
// Position of the status message in percentage of the screen dimensions
STATUS.center.x = 0.5;
STATUS.center.y = 0.75;
// Position of the lock icon in percentage of the screen dimensions
LOCK.center.x = 0.5;
LOCK.center.y = 0.5;
// Position of the password prompt in percentage of the screen dimensions
PROMPT.center.x = 0.5;
PROMPT.center.y = 0.65;
// Placeholder in password prompt
PROMPT.placeholder = "Password";
// Character used to obfuscate password
PROMPT.bullet = "•";
# ------------------------------ Initialization -------------------------------
// Get screen dimensions
screen.width = Window.GetWidth();
screen.height = Window.GetHeight();
// Set background color
Window.SetBackgroundTopColor(BG_COLOR.red, BG_COLOR.green, BG_COLOR.blue);
Window.SetBackgroundBottomColor(BG_COLOR.red, BG_COLOR.green, BG_COLOR.blue);
// Initialize global state
process = Plymouth.GetMode();
flow = "run";
# ------------------------------- Animation -----------------------------------
#
# Set up and animate the logo
#
// Prepare animation
animation.length = 0;
animation.current_frame = 0;
animation.sprite = Sprite();
// Load every .png in ImageDir/animation in numerical order and store it
// in animation.images array. Doing this, we update animation.length to
// hold the count of frames loaded. Eventually, the while loop breaks
// as soon as it fails to load the next PNG.
while (1) {
local.image = Image("animation/" + animation.length + ".png");
if (!image) break;
animation.images[animation.length++] = image;
}
fun hide_animation() {
animation.sprite.SetOpacity(0);
}
fun show_animation() {
animation.sprite.SetOpacity(1);
}
fun update_animation() {
// Load image and update the animation sprite
current_image = animation.images[animation.current_frame];
animation.sprite.SetImage(current_image);
// When the images are all the same dimensions, it would be more
// efficient to set the sprite position once at initialization
// but in the case frames are not all the same size, we update it here
animation.sprite.SetX(LOGO.center.x * screen.width - current_image.GetWidth() / 2);
animation.sprite.SetY(LOGO.center.y * screen.height - current_image.GetHeight() / 2);
// Then update current frame and reset if necessary
animation.current_frame++;
if (animation.current_frame == animation.length) animation.current_frame = 0;
}
# ------------------------------- Message -------------------------------------
#
# Set up and display a message containing the nature of the boot sequence
#
if (process == "boot") boot_message.text = "Booting up";
if (process == "reboot") boot_message.text = "Rebooting";
if (process == "shutdown") boot_message.text = "Shutting down";
boot_message.sprite = Sprite();
boot_message.image = Image.Text(boot_message.text, MAIN_COLOR.red, MAIN_COLOR.green, MAIN_COLOR.blue, 1, MAIN_FONT);
boot_message.sprite.SetImage(boot_message.image);
boot_message.sprite.SetX(BOOT_MESSAGE.center.x * screen.width - boot_message.image.GetWidth() / 2);
boot_message.sprite.SetY(BOOT_MESSAGE.center.y * screen.height - boot_message.image.GetHeight() / 2);
fun hide_boot_message() {
boot_message.sprite.SetOpacity(0);
}
fun show_boot_message() {
boot_message.sprite.SetOpacity(1);
}
# ------------------------------ Progress Bar ---------------------------------
#
# Setting up and animating the progress bar during boot sequence
#
// Only load progress bar logic in boot sequence
if (process == "boot") {
// Load and set the progress bar background
bar.background.image = Image("bar-background.png");
bar.background.sprite = Sprite(bar.background.image);
bar.background.sprite.SetX(BAR.center.x * screen.width - bar.background.image.GetWidth() / 2);
bar.background.sprite.SetY(BAR.center.y * screen.height - bar.background.image.GetHeight() / 2);
// Load the progress bar and display it anchored to the left of the background bar
bar.image = Image("bar-progress.png");
bar.sprite = Sprite();
bar.sprite.SetX(BAR.center.x * screen.width - bar.background.image.GetWidth() / 2);
bar.sprite.SetY(BAR.center.y * screen.height - bar.background.image.GetHeight() / 2);
fun hide_boot_progress() {
bar.sprite.SetOpacity(0);
bar.background.sprite.SetOpacity(0);
}
fun show_boot_progress() {
bar.sprite.SetOpacity(1);
bar.background.sprite.SetOpacity(1);
}
fun boot_progress_callback(time, progress) {
// Grow the progress bar size with the current progress percent
// bar.sprite.SetImage(bar.image.Scale(progress * bar.image.GetWidth(), bar.image.GetHeight()));
bar.sprite.SetImage(bar.image.Crop(0, 0, progress * bar.image.GetWidth(), bar.image.GetHeight()));
}
Plymouth.SetBootProgressFunction(boot_progress_callback);
}
# ----------------------------- Status Update ---------------------------------
#
# Set up and display the status updates of the boot process
#
status_message.sprite = Sprite();
fun update_status_callback(status) {
status_message.image = Image.Text(status, SECONDARY_COLOR.red, SECONDARY_COLOR.green, SECONDARY_COLOR.blue, 1, SECONDARY_FONT);
status_message.sprite.SetImage(status_message.image);
status_message.sprite.SetX(STATUS.center.x * screen.width - status_message.image.GetWidth() / 2);
status_message.sprite.SetY(STATUS.center.y * screen.height - status_message.image.GetHeight() / 2);
}
fun root_mounted_callback() {
update_status_callback("Root successfully mounted");
}
Plymouth.SetUpdateStatusFunction(update_status_callback);
Plymouth.SetRootMountedFunction(root_mounted_callback);
# ---------------------------- Password dialog --------------------------------
#
# Setting up and displaying the password prompt for encrypted volumes
#
// Only load password prompt logic in boot sequence
if (process == "boot") {
// Load and place the lock icon
lock.image = Image("lock.png");
lock.width = lock.image.GetWidth();
lock.height = lock.image.GetHeight();
lock.sprite = Sprite(lock.image);
lock.sprite.SetX(LOCK.center.x * screen.width - lock.width / 2);
lock.sprite.SetY(LOCK.center.y * screen.height - lock.height / 2);
// Load and place the password prompt
prompt.image = Image("input.png");
prompt.sprite = Sprite(prompt.image);
prompt.sprite.SetX(PROMPT.center.x * screen.width - prompt.image.GetWidth() / 2);
prompt.sprite.SetY(PROMPT.center.y * screen.height - prompt.image.GetHeight() / 2);
// Initiate the bullet string
// We cannot set the position now as the image will change in size
bullets.sprite = Sprite();
// Make password dialog elements invisible
fun hide_password_screen() {
lock.sprite.SetOpacity(0);
prompt.sprite.SetOpacity(0);
bullets.sprite.SetOpacity(0);
}
// Make password dialog elements visible
fun show_password_screen() {
lock.sprite.SetOpacity(1);
prompt.sprite.SetOpacity(1);
bullets.sprite.SetOpacity(1);
}
fun display_password_callback(prompt, n_bullets) {
// Interrupt the normal flow
global.flow = "password";
show_password_screen();
hide_animation();
hide_boot_message();
hide_boot_progress();
// Create the string of bullets
bullets.string = "";
while (n_bullets--) bullets.string += PROMPT.bullet;
// Display placeholder text when necessary
if (!bullets.string) bullets.string = PROMPT.placeholder;
bullets.image = Image.Text(bullets.string, MAIN_COLOR.red, MAIN_COLOR.green, MAIN_COLOR.blue, 1, SECONDARY_FONT);
// Display bullets
bullets.sprite.SetImage(bullets.image);
bullets.sprite.SetX(PROMPT.center.x * screen.width - bullets.image.GetWidth() / 2);
bullets.sprite.SetY(PROMPT.center.y * screen.height - bullets.image.GetHeight() / 2);
}
Plymouth.SetDisplayPasswordFunction(display_password_callback);
}
#------------------------------ Display Normal --------------------------------
#
# Return to normal progress of the boot sequence
#
fun display_normal_callback() {
global.flow = "run";
hide_password_screen();
show_animation();
show_boot_message();
show_boot_progress();
}
Plymouth.SetDisplayNormalFunction(display_normal_callback);
# -------------------------------- Refresh ------------------------------------
#
# Main process to update the display
#
fun refresh_callback() {
if (global.flow == "run") update_animation();
}
Plymouth.SetRefreshFunction(refresh_callback);
#----------------------------------------- Quit --------------------------------
#
# Exit the process
#
fun quit_callback() {}
Plymouth.SetQuitFunction(quit_callback);