├── LICENSE
├── README.md
├── TermuxAlpine.sh
├── docs
└── images
│ ├── .empty
│ ├── alpinelinux-logo.svg
│ └── ss.png
└── finaltouchup.sh
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 LOKESH PANDEY
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TermuxAlpine
2 |
3 | #### _powered by_
4 |
5 | 
6 |
7 | 
8 |
9 |
10 | This Termux bash setup shell script will attempt to set Alpine Linux up in your Termux environment.
11 |
12 | ## _Steps For Installation_
13 | 1. First go to home directory
14 | `cd $HOME`
15 | 2. Get the script
16 | `curl -LO https://raw.githubusercontent.com/Hax4us/TermuxAlpine/master/TermuxAlpine.sh`
17 | 3. Execute the script
18 | `bash TermuxAlpine.sh`
19 | 4. Start Alpine
20 | `startalpine`
21 | 5. For exit just execute
22 | `exit`
23 |
24 | ## _Steps For First Time Use (Recommended)_
25 | 1. Update Alpine
26 | `apk update`
27 | 2. Now you can install any package by
28 | `apk add package_name`
29 |
30 | ## Size Comparision
31 | Size | Alpine | Arch | Ubuntu
32 | --- | --- | --- | ---
33 | before installation | Around 1 MB 😱 | Around 400 MB | Around 35 MB
34 | after installation | Around 80 MB | Around 2000 MB | Around 1200 MB
35 |
36 | #### here is full usage details of apk https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management
37 |
38 |
39 | Comments are welcome at https://github.com/Hax4us/TermuxAlpine/issues ✍
40 |
41 | Pull requests are welcome at https://github.com/Hax4us/TermuxAlpine/pulls ✍
42 |
--------------------------------------------------------------------------------
/TermuxAlpine.sh:
--------------------------------------------------------------------------------
1 | #!/data/data/com.termux/files/usr/bin/bash -e
2 | # Copyright ©2019 by Hax4Us. All rights reserved.
3 | #
4 | # Email : lkpandey950@gmail.com
5 | ################################################################################
6 |
7 | # colors
8 |
9 | red='\033[1;31m'
10 | yellow='\033[1;33m'
11 | blue='\033[1;34m'
12 | reset='\033[0m'
13 |
14 |
15 | # Destination Path
16 |
17 | DESTINATION=${PREFIX}/share/TermuxAlpine
18 | choice=""
19 | if [ -d ${DESTINATION} ]; then
20 | printf "${red}[!] ${yellow}Alpine is already installed\nDo you want to reinstall ? (type \"y\" for yes or \"n\" for no) :${reset} "
21 | read choice
22 | if [ "${choice}" = "y" ]; then
23 | rm -rf ${DESTINATION}
24 | elif [ "${choice}" = "n" ]; then
25 | exit 1
26 | else
27 | printf "${red}[!] Wrong input${reset}"
28 | exit 1
29 | fi
30 |
31 | fi
32 | mkdir ${DESTINATION}
33 | cd ${DESTINATION}
34 |
35 | # Utility function for Unknown Arch
36 |
37 | unknownarch() {
38 | printf "$red"
39 | echo "[*] Unknown Architecture :("
40 | printf "$reset"
41 | exit 1
42 | }
43 |
44 | # Utility function for detect system
45 |
46 | checksysinfo() {
47 | printf "$blue [*] Checking host architecture ..."
48 | case $(getprop ro.product.cpu.abi) in
49 | arm64-v8a)
50 | SETARCH=aarch64
51 | ;;
52 | armeabi|armeabi-v7a)
53 | SETARCH=armhf
54 | ;;
55 | x86|i686)
56 | SETARCH=x86
57 | ;;
58 | x86_64)
59 | SETARCH=x86_64
60 | ;;
61 | *)
62 | unknownarch
63 | ;;
64 | esac
65 | }
66 |
67 | # Check if required packages are present
68 |
69 | checkdeps() {
70 | printf "${blue}\n"
71 | echo " [*] Updating apt cache..."
72 | apt update -y &> /dev/null
73 | echo " [*] Checking for all required tools..."
74 |
75 | for i in proot bsdtar curl; do
76 | if [ -e ${PREFIX}/bin/$i ]; then
77 | echo " • $i is OK"
78 | else
79 | echo "Installing ${i}..."
80 | apt install -y $i || {
81 | printf "$red"
82 | echo " ERROR: check your internet connection or apt\n Exiting..."
83 | printf "$reset"
84 | exit 1
85 | }
86 | fi
87 | done
88 | }
89 |
90 | # URLs of all possibls architectures
91 |
92 | seturl() {
93 | ALPINE_VER=$(curl -s http://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/$SETARCH/latest-releases.yaml | grep -m 1 -o version.* | sed -e 's/[^0-9.]*//g' -e 's/-$//')
94 | if [ -z "$ALPINE_VER" ] ; then
95 | exit 1
96 | fi
97 | ALPINE_URL="http://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/$SETARCH/alpine-minirootfs-$ALPINE_VER-$SETARCH.tar.gz"
98 | }
99 |
100 | # Utility function to get tar file
101 |
102 | gettarfile() {
103 | printf "$blue [*] Getting tar file...$reset\n\n"
104 | seturl $SETARCH
105 | curl --progress-bar -L --fail --retry 4 -O "$ALPINE_URL"
106 | rootfs="alpine-minirootfs-$ALPINE_VER-$SETARCH.tar.gz"
107 | }
108 |
109 | # Utility function to get SHA
110 |
111 | getsha() {
112 | printf "\n${blue} [*] Getting SHA ... $reset\n\n"
113 | curl --progress-bar -L --fail --retry 4 -O "${ALPINE_URL}.sha256"
114 | }
115 |
116 | # Utility function to check integrity
117 |
118 | checkintegrity() {
119 | printf "\n${blue} [*] Checking integrity of file...\n"
120 | echo " [*] The script will immediately terminate in case of integrity failure"
121 | printf ' '
122 | sha256sum -c ${rootfs}.sha256 || {
123 | printf "$red Sorry :( to say your downloaded linux file was corrupted or half downloaded, but don't worry, just rerun my script\n${reset}"
124 | exit 1
125 | }
126 | }
127 |
128 | # Utility function to extract tar file
129 |
130 | extract() {
131 | printf "$blue [*] Extracting... $reset\n\n"
132 | proot --link2symlink -0 bsdtar -xpf $rootfs 2> /dev/null || :
133 | }
134 |
135 | # Utility function for login file
136 |
137 | createloginfile() {
138 | bin=${PREFIX}/bin/startalpine
139 | cat > $bin <<- EOM
140 | #!/data/data/com.termux/files/usr/bin/bash -e
141 | unset LD_PRELOAD
142 | # thnx to @j16180339887 for DNS picker
143 | addresolvconf ()
144 | {
145 | android=\$(getprop ro.build.version.release)
146 | if [ \${android%%.*} -lt 8 ]; then
147 | [ \$(command -v getprop) ] && getprop | sed -n -e 's/^\[net\.dns.\]: \[\(.*\)\]/\1/p' | sed '/^\s*$/d' | sed 's/^/nameserver /' > \${PREFIX}/share/TermuxAlpine/etc/resolv.conf
148 | fi
149 | }
150 | addresolvconf
151 | exec proot --link2symlink -0 -r \${PREFIX}/share/TermuxAlpine/ -b /dev/ -b /sys/ -b /proc/ -b /sdcard -b /storage -b \$HOME -w /home /usr/bin/env TMPDIR=/tmp HOME=/home PREFIX=/usr SHELL=/bin/sh TERM="\$TERM" LANG=\$LANG PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/sh --login
152 | EOM
153 |
154 | chmod 700 $bin
155 | }
156 |
157 | # Utility function to touchup Alpine
158 |
159 | finalwork() {
160 | [ ! -e ${DESTINATION}/finaltouchup.sh ] && curl --silent -LO https://raw.githubusercontent.com/Hax4us/TermuxAlpine/master/finaltouchup.sh
161 | if [ "${MOTD}" = "ON" ]; then
162 | bash ${DESTINATION}/finaltouchup.sh --add-motd
163 | else
164 | bash ${DESTINATION}/finaltouchup.sh
165 | fi
166 | rm ${DESTINATION}/finaltouchup.sh
167 | }
168 |
169 |
170 |
171 | # Utility function for cleanup
172 |
173 | cleanup() {
174 | if [ -d ${DESTINATION} ]; then
175 | rm -rf ${DESTINATION}
176 | else
177 | printf "$red not installed so not removed${reset}\n"
178 | exit
179 | fi
180 | if [ -e ${PREFIX}/bin/startalpine ]; then
181 | rm ${PREFIX}/bin/startalpine
182 | printf "$yellow uninstalled :) ${reset}\n"
183 | exit
184 | else
185 | printf "$red not installed so not removed${reset}\n"
186 | fi
187 | }
188 |
189 | printline() {
190 | printf "${blue}\n"
191 | echo " #------------------------------------------#"
192 | }
193 |
194 | usage() {
195 | printf "${yellow}\nUsage: ${green}bash TermuxAlpine.sh [option]\n${blue} --uninstall uninstall alpine\n --add-motd create motd file\n${reset}\n"
196 | }
197 |
198 | # Start
199 |
200 | MOTD="OFF"
201 | EXTRAARGS="default"
202 | if [ ! -z "$1" ]
203 | then
204 | EXTRAARGS=$1
205 | fi
206 | if [ "$EXTRAARGS" = "--uninstall" ]; then
207 | cleanup
208 | exit 1
209 | elif [ "$EXTRAARGS" = "--add-motd" ]; then
210 | MOTD="ON"
211 | elif [ $# -ge 1 ]
212 | then
213 | usage
214 | exit 1
215 | fi
216 | printf "\n${yellow} You are going to install Alpine in termux ;) Cool\n press ENTER to continue\n"
217 | read enter
218 |
219 | checksysinfo
220 | checkdeps
221 | gettarfile
222 | getsha
223 | checkintegrity
224 | extract
225 | createloginfile
226 |
227 | printf "$blue [*] Configuring Alpine For You ..."
228 | finalwork
229 | printline
230 | printf "\n${yellow} Now you can enjoy a very small (just 1 MB!) Linux environment in your Termux :)\n Don't forget to star my work\n"
231 | printline
232 | printline
233 | printf "\n${blue} [*] Email :${yellow} lkpandey950@gmail.com\n"
234 | printf "$blue [*] Website :${yellow} https://hax4us.com\n"
235 | printf "$blue [*] YouTube :${yellow} https://youtube.com/hax4us\n"
236 | printline
237 | printf "$red \n NOTE : $yellow use ${red}--uninstall${yellow} option for uninstall\n"
238 | printline
239 | printf "$reset"
240 |
--------------------------------------------------------------------------------
/docs/images/.empty:
--------------------------------------------------------------------------------
1 | .
2 |
--------------------------------------------------------------------------------
/docs/images/alpinelinux-logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/docs/images/ss.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hax4us/TermuxAlpine/6c5d10ca41273fccc2370cb969b94211018ba3e3/docs/images/ss.png
--------------------------------------------------------------------------------
/finaltouchup.sh:
--------------------------------------------------------------------------------
1 | #!/data/data/com.termux/files/usr/bin/bash
2 | addprofile()
3 | {
4 | cat > ${PREFIX}/share/TermuxAlpine/etc/profile <<- EOM
5 | export CHARSET=UTF-8
6 | export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
7 | export PAGER=less
8 | export PS1='[\u@\h \W]\\$ '
9 | umask 022
10 | for script in /etc/profile.d/*.sh ; do
11 | if [ -r \$script ] ; then
12 | . \$script
13 | fi
14 | done
15 | EOM
16 | }
17 |
18 | addmotd() {
19 | cat > ${PREFIX}/share/TermuxAlpine/etc/profile.d/motd.sh <<- EOM
20 | printf "\n\033[1;34mWelcome to Alpine Linux in Termux! Enjoy!\033[0m\033[1;34m
21 | Chat: \033[0m\033[mhttps://gitter.im/termux/termux/\033[0m\033[1;34m
22 | Help: \033[0m\033[34minfo \033[0m\033[mand \033[0m\033[34mman \033[0m\033[1;34m
23 | Portal: \033[0m\033[mhttps://wiki.termux.com/wiki/Community\033[0m\033[1;34m
24 |
25 | Install a package: \033[0m\033[34mapk add \033[0m\033[1;34m
26 | More information: \033[0m\033[34mapk --help\033[0m\033[1;34m
27 | Search packages: \033[0m\033[34mapk search \033[0m\033[1;34m
28 | Upgrade packages: \033[0m\033[34mapk upgrade \n\033[0m \n"
29 | EOM
30 | }
31 |
32 | updrepos() {
33 | cp ${PREFIX}/share/TermuxAlpine/etc/apk/repositories ${PREFIX}/share/TermuxAlpine/etc/apk/repositories.bak
34 | cat > ${PREFIX}/share/TermuxAlpine/etc/apk/repositories <<- EOM
35 | http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/
36 | http://dl-cdn.alpinelinux.org/alpine/latest-stable/community/
37 | http://dl-cdn.alpinelinux.org/alpine/edge/testing/
38 | EOM
39 | }
40 | # thnx to @j16180339887 for DNS picker
41 | addresolvconf ()
42 | {
43 | printf "nameserver 8.8.8.8\nnameserver 8.8.4.4" > ${PREFIX}/share/TermuxAlpine/etc/resolv.conf
44 | }
45 | android=$(getprop ro.build.version.release)
46 | addprofile
47 | if [ "${1}" = "--add-motd" ]; then
48 | addmotd
49 | fi
50 | if [ ${android%%.*} -ge 8 ]; then
51 | addresolvconf
52 | fi
53 | updrepos
54 |
--------------------------------------------------------------------------------