forked from Acode-Foundation/Acode
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinit-alpine.sh
More file actions
198 lines (158 loc) · 4.86 KB
/
init-alpine.sh
File metadata and controls
198 lines (158 loc) · 4.86 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
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/share/bin:/usr/share/sbin:/usr/local/bin:/usr/local/sbin:/system/bin:/system/xbin:$PREFIX/local/bin
export PS1="\[\e[38;5;46m\]\u\[\033[39m\]@localhost \[\033[39m\]\w \[\033[0m\]\\$ "
export HOME=/home
export TERM=xterm-256color
required_packages="bash command-not-found tzdata wget"
missing_packages=""
for pkg in $required_packages; do
if ! apk info -e "$pkg" >/dev/null 2>&1; then
missing_packages="$missing_packages $pkg"
fi
done
if [ -n "$missing_packages" ]; then
echo -e "\e[34;1m[*] \e[0mInstalling important packages\e[0m"
apk update && apk upgrade
apk add $missing_packages
if [ $? -eq 0 ]; then
echo -e "\e[32;1m[+] \e[0mSuccessfully installed\e[0m"
fi
echo -e "\e[34m[*] \e[0mUse \e[32mapk\e[0m to install new packages\e[0m"
fi
if [ ! -f /linkerconfig/ld.config.txt ]; then
mkdir -p /linkerconfig
touch /linkerconfig/ld.config.txt
fi
if [ "$1" = "--installing" ]; then
echo "Configuring timezone..."
if [ -n "$ANDROID_TZ" ] && [ -f "/usr/share/zoneinfo/$ANDROID_TZ" ]; then
ln -sf "/usr/share/zoneinfo/$ANDROID_TZ" /etc/localtime
echo "$ANDROID_TZ" > /etc/timezone
echo "Timezone set to: $ANDROID_TZ"
else
echo "Failed to detect timezone"
fi
mkdir -p "$PREFIX/.configured"
echo "Installation completed."
exit 0
fi
if [ "$#" -eq 0 ]; then
echo "$$" > "$PREFIX/pid"
chmod +x "$PREFIX/axs"
if [ ! -e "$PREFIX/alpine/etc/acode_motd" ]; then
cat <<EOF > "$PREFIX/alpine/etc/acode_motd"
Welcome to Alpine Linux in Acode!
Working with packages:
- Search: apk search <query>
- Install: apk add <package>
- Uninstall: apk del <package>
- Upgrade: apk update && apk upgrade
EOF
fi
# Create acode CLI tool
if [ ! -e "$PREFIX/alpine/usr/local/bin/acode" ]; then
mkdir -p "$PREFIX/alpine/usr/local/bin"
cat <<'ACODE_CLI' > "$PREFIX/alpine/usr/local/bin/acode"
#!/bin/bash
# acode - Open files/folders in Acode editor
# Uses OSC escape sequences to communicate with the Acode terminal
usage() {
echo "Usage: acode [file/folder...]"
echo ""
echo "Open files or folders in Acode editor."
echo ""
echo "Examples:"
echo " acode file.txt # Open a file"
echo " acode . # Open current folder"
echo " acode ~/project # Open a folder"
echo " acode -h, --help # Show this help"
}
get_abs_path() {
local path="$1"
if [[ "$path" == /* ]]; then
realpath "$path" 2>/dev/null || echo "$path"
else
realpath "$path" 2>/dev/null || echo "$(pwd)/$path"
fi
}
open_in_acode() {
local path=$(get_abs_path "$1")
local type="file"
[[ -d "$path" ]] && type="folder"
# Send OSC 7777 escape sequence: \e]7777;cmd;type;path\a
# The terminal component will intercept and handle this
printf '\e]7777;open;%s;%s\a' "$type" "$path"
}
if [[ $# -eq 0 ]]; then
open_in_acode "."
exit 0
fi
for arg in "$@"; do
case "$arg" in
-h|--help)
usage
exit 0
;;
*)
if [[ -e "$arg" ]]; then
open_in_acode "$arg"
else
echo "Error: '$arg' does not exist" >&2
exit 1
fi
;;
esac
done
ACODE_CLI
chmod +x "$PREFIX/alpine/usr/local/bin/acode"
fi
# Create initrc if it doesn't exist
#initrc runs in bash so we can use bash features
if [ ! -e "$PREFIX/alpine/initrc" ]; then
cat <<'EOF' > "$PREFIX/alpine/initrc"
# Source rc files if they exist
if [ -f "/etc/profile" ]; then
source "/etc/profile"
fi
if [ -f "$HOME/.bashrc" ]; then
source "$HOME/.bashrc"
fi
if [ -f /etc/bash/bashrc ]; then
source /etc/bash/bashrc
fi
# Environment setup
export PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/share/bin:/usr/share/sbin:/usr/local/bin:/usr/local/sbin
export HOME=/home
export TERM=xterm-256color
SHELL=/bin/bash
export PIP_BREAK_SYSTEM_PACKAGES=1
# Display MOTD if available
if [ -s /etc/acode_motd ]; then
cat /etc/acode_motd
fi
# Command-not-found handler
command_not_found_handle() {
cmd="$1"
pkg=""
green="\e[1;32m"
reset="\e[0m"
pkg=$(apk search -x "cmd:$cmd" 2>/dev/null | awk -F'-[0-9]' '{print $1}' | head -n 1)
if [ -n "$pkg" ]; then
echo -e "The program '$cmd' is not installed.\nInstall it by executing:\n ${green}apk add $pkg${reset}" >&2
else
echo "The program '$cmd' is not installed and no package provides it." >&2
fi
return 127
}
EOF
fi
# Add PS1 only if not already present
if ! grep -q 'PS1=' "$PREFIX/alpine/initrc"; then
echo 'PS1="\[\033[1;32m\]\u\[\033[0m\]@localhost \w \$ "' >> "$PREFIX/alpine/initrc"
fi
chmod +x "$PREFIX/alpine/initrc"
#actual souce
#everytime a terminal is started initrc will run
"$PREFIX/axs" -c "bash --rcfile /initrc -i"
else
exec "$@"
fi