This repository has been archived by the owner on Apr 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
anarchy-chroot.sh
103 lines (93 loc) · 3.42 KB
/
anarchy-chroot.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
#!/usr/bin/env bash
###############################################################
### Anarchy Linux Install Script
### anarchy-chroot.sh
###
### Copyright (C) 2017 Dylan Schacht
###
### By: Dylan Schacht (deadhead)
### Email: [email protected]
### Webpage: https://anarchylinux.org
###
### Any questions, comments, or bug reports may be sent to above
### email address. Enjoy, and keep on using Arch.
###
### License: GPL v2.0
###############################################################
anarchy_chroot() {
local char=
local input=
local -a history=( )
local -i histindex=0
trap ctrl_c INT
working_dir=$(</tmp/chroot_dir.var)
while (true)
do
echo -n "${Yellow}<${Red}root${Yellow}@${Green}${hostname}-chroot${Yellow}>: $working_dir>${Red}# ${ColorOff}" ; while IFS= read -r -n 1 -s char
do
if [ "${char}" == $'\x1b' ]; then
while IFS= read -r -n 2 -s rest
do
char+="${rest}"
break
done
fi
if [ "${char}" == $'\x1b[D' ]; then
pos=-1
elif [ "${char}" == $'\x1b[C' ]; then
pos=1
elif [[ ${char} == $'\177' ]]; then
input="${input%?}"
echo -ne "\r\033[K${Yellow}<${Red}root${Yellow}@${Green}${hostname}-chroot${Yellow}>: ${working_dir}>${Red}# ${ColorOff}${input}"
## User input up
elif [ "${char}" == $'\x1b[A' ]; then
if [ ${histindex} -gt 0 ]; then
histindex+=-1
input=$(echo -ne "${history[$histindex]}")
echo -ne "\r\033[K${Yellow}<${Red}root${Yellow}@${Green}${hostname}-chroot${Yellow}>: ${working_dir}>${Red}# ${ColorOff}${history[$histindex]}"
fi
## User input down
elif [ "${char}" == $'\x1b[B' ]; then
if [ ${histindex} -lt $((${#history[@]} - 1)) ]; then
histindex+=1
input=$(echo -ne "${history[$histindex]}")
echo -ne "\r\033[K${Yellow}<${Red}root${Yellow}@${Green}${hostname}-chroot${Yellow}>: ${working_dir}>${Red}# ${ColorOff}${history[$histindex]}"
fi
### Newline
elif [ -z "${char}" ]; then
echo
history+=( "${input}" )
histindex=${#history[@]}
break
else
echo -n "${char}"
input+="${char}"
fi
done
if [ "${input}" == "anarchy" ] || [ "${input}" == "exit" ]; then
rm /tmp/chroot_dir.var &> /dev/null
clear
break
elif (<<<"${input}" grep "^cd " &> /dev/null); then
ch_dir=$(<<<"${input}" cut -c4-)
arch-chroot "${ARCH}" /bin/bash -c "cd ${working_dir} ; cd ${ch_dir} ; pwd > /etc/chroot_dir.var"
mv "${ARCH}"/etc/chroot_dir.var /tmp/
working_dir=$(</tmp/chroot_dir.var)
elif (<<<"${input}" grep "^help" &> /dev/null); then
echo -e "${arch_chroot_msg}"
else
arch-chroot "${ARCH}" /bin/bash -c "cd ${working_dir} ; ${input}"
fi
input=
done
}
ctrl_c() {
echo
echo "${Red} Exiting and cleaning up..."
sleep 0.5
unset input
rm /tmp/chroot_dir.var &> /dev/null
clear
reboot_system
}
# vim: ai:ts=4:sw=4:et