-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsys_windows.sh
More file actions
115 lines (100 loc) · 3.02 KB
/
Copy pathsys_windows.sh
File metadata and controls
115 lines (100 loc) · 3.02 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
#!/usr/bin/env bash
# Print Center of Terminal
center_text() {
text="$1"
columns="$(tput cols)"
printf "%*s\n" $(((${#text} + columns) / 2)) "$text"
}
center_color() {
local text="$1"
local columns
local visible_len
local offset
columns=$(tput cols)
visible_len=$(echo -e "$text" | sed 's/\x1B\[[0-9;]*[A-Za-z]//g' | wc -m)
offset=$(((columns - visible_len) / 2))
echo -e "$(printf "%*s%s\n" "$offset" "" "$text")"
}
# Space to center with an offset. For inputs
center_space() {
local offset=$1
columns="$(tput cols)"
printf "%*s" $(((${#text} + columns) / 2 - offset))
}
read_password() {
local prompt="$1"
local password=""
local char
# Print prompt without newline
printf "%s" "$prompt"
while IFS= read -r -s -n 1 char; do
# Enter ends input
if [[ $char == $'\0' || $char == $'\n' ]]; then
break
fi
# Handle backspace (ASCII 127)
if [[ $char == $'\177' ]]; then
if [ -n "$password" ]; then
password=${password%?}
# Move cursor back, erase *, move back again
printf '\b \b'
fi
else
password+=$char
printf '*'
fi
done
echo
REPLY="$password" # store in REPLY like `read` does
}
R='\033[1;31m' # RED
G='\033[1;32m' # GREEN
Y='\033[1;33m' # YELLOW
B='\033[1;34m' # BLUE
C='\033[1;36m' # CYAN
RESET='\033[0;0m'
echo -e '\n\n\n\n'
center_text 'REBOOT TO WINDOWS'
center_text '==================='
echo -e '\n'
logo=(
"${R} ${G} .oodMMMM"
"${R} ${G} .oodMMMMMMMMMMMM"
"${R} ..oodMMM ${G} MMMMMMMMMMMMMMMMMMM"
"${R} oodMMMMMMMMMMM ${G} MMMMMMMMMMMMMMMMMMM"
"${R} MMMMMMMMMMMMMM ${G} MMMMMMMMMMMMMMMMMMM"
"${R} MMMMMMMMMMMMMM ${G} MMMMMMMMMMMMMMMMMMM"
"${R} MMMMMMMMMMMMMM ${G} MMMMMMMMMMMMMMMMMMM"
"${R} MMMMMMMMMMMMMM ${G} MMMMMMMMMMMMMMMMMMM"
"${R} MMMMMMMMMMMMMM ${G} MMMMMMMMMMMMMMMMMMM"
""
"${C} MMMMMMMMMMMMMM ${Y} MMMMMMMMMMMMMMMMMMM"
"${C} MMMMMMMMMMMMMM ${Y} MMMMMMMMMMMMMMMMMMM"
"${C} MMMMMMMMMMMMMM ${Y} MMMMMMMMMMMMMMMMMMM"
"${C} MMMMMMMMMMMMMM ${Y} MMMMMMMMMMMMMMMMMMM"
"${C} MMMMMMMMMMMMMM ${Y} MMMMMMMMMMMMMMMMMMM"
"${C} '^^^^^^MMMMMMM ${Y} MMMMMMMMMMMMMMMMMMM"
"${C} ''''^^^ ${Y} ^^MMMMMMMMMMMMMMMMM"
"${C} ${Y} ''''^^^^^MMMM"
"${RESET}"
)
for line in "${logo[@]}"; do
center_color "$line"
done
# Activate sudo if not root
if ! sudo -n true 2>/dev/null; then
echo -e "\n\n"
center_color "[ Enter sudo password to continue, or ${R}Ctrl+C${RESET} to cancel ]"
echo -e -n "${G}"
# read -sp "$(center_text ' PASSWORD: ')" SUDO_PASSWORD
read_password "$(center_space 23) PASSWORD: "
SUDO_PASSWORD="$REPLY"
if [ -z "$SUDO_PASSWORD" ]; then exit 1; fi
if ! echo "$SUDO_PASSWORD" | sudo -S -v >/dev/null 2>&1; then
exit 1
fi
fi
# eg: 'Windows Boot Manager (on /dev/nvme0n1p1)'
windows_title=$(sudo grep -i windows /boot/grub/grub.cfg | cut -d "'" -f 2)
sudo grub-reboot "$windows_title"
sudo reboot