From 50548b3f86299b3339cad8967253e535f4d52ed6 Mon Sep 17 00:00:00 2001 From: illvart Date: Fri, 13 Nov 2020 19:27:46 +0700 Subject: [PATCH] New version v1.0.3 --- .editorconfig | 12 +++- README.md | 23 ++++--- setup-termux-alpine.sh => setup-termux-alpine | 69 +++++++++++-------- 3 files changed, 63 insertions(+), 41 deletions(-) rename setup-termux-alpine.sh => setup-termux-alpine (91%) mode change 100644 => 100755 diff --git a/.editorconfig b/.editorconfig index ebe3b38..bb0b634 100755 --- a/.editorconfig +++ b/.editorconfig @@ -2,16 +2,22 @@ root = true [*] -charset = utf-8 indent_style = space indent_size = 2 end_of_line = lf +charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[*.{md}] +[{*.sh,setup-termux-alpine}] +indent_size = 4 + +[*.json] +insert_final_newline = ignore + +[*.md] max_line_length = 0 trim_trailing_whitespace = false [LICENSE] -insert_final_newline = ignore +insert_final_newline = ignore \ No newline at end of file diff --git a/README.md b/README.md index cfd011e..75c0a87 100644 --- a/README.md +++ b/README.md @@ -27,21 +27,25 @@ Open [Termux](https://termux.com/) app, copy and paste the following command in Note: Required to install `git` and `ncurses-utils`, skip if already installed! ```bash -pkg install -y git ncurses-utils +pkg install -y git +pkg install -y ncurses-utils ``` ```bash cd $HOME \ - && git clone https://github.com/illvart/termux-alpine.git \ - && cd termux-alpine + && git clone -b master https://github.com/illvart/termux-alpine.git \ + && cd termux-alpine \ + && chmod +x setup-termux-alpine ``` +Or download from [GitHub Releases page](https://github.com/illvart/termux-alpine/releases) and extract. + ### Installation Installation [options](#options). ```bash -bash setup-termux-alpine.sh --setup-user +./setup-termux-alpine --setup-user ``` Please follow the output of the command above! @@ -67,7 +71,7 @@ To reinstall just typing a command like [installation](#installation) above, typ Or pass the command with [options](#options) example: ```bash -bash setup-termux-alpine.sh -S -F +./setup-termux-alpine -S -F ``` ### Uninstall @@ -76,14 +80,14 @@ Please note! Before uninstalling, recommended to backup the current installation ```bash cd ${HOME}/termux-alpine \ - && bash setup-termux-alpine.sh --uninstall + && ./setup-termux-alpine --uninstall ``` Or manually (isn't safe): ```bash rm -rf ${PREFIX}/bin/termux-alpine \ - ${HOME}/alpine + ${HOME}/.alpine ``` ## Upgrade @@ -93,17 +97,18 @@ Upgrade the installation script. ```bash rm -rf ${HOME}/termux-alpine \ && cd $HOME \ - && git clone https://github.com/illvart/termux-alpine.git \ + && git clone -b master https://github.com/illvart/termux-alpine.git \ && cd termux-alpine ``` ### Options ```bash -Usage: bash setup-termux-alpine.sh [options] +Usage: ./setup-termux-alpine [options] Options: --install-nodejs install nodejs-current, npm, and yarn +--install-python3 install python3 py3-pip, and py3-wheel -S, --setup-user setup a non-root user -F, --fake-kernel use a fake kernel -u, --uninstall full wipe the rootfs installation diff --git a/setup-termux-alpine.sh b/setup-termux-alpine old mode 100644 new mode 100755 similarity index 91% rename from setup-termux-alpine.sh rename to setup-termux-alpine index 6f76108..6381ef9 --- a/setup-termux-alpine.sh +++ b/setup-termux-alpine @@ -3,23 +3,18 @@ ## Copyright (c) 2020 illvart ## https://github.com/illvart/termux-alpine ## -## Credit to `Hax4us` `Termux` for source +## Licensed under MIT https://github.com/illvart/termux-alpine/blob/master/LICENSE ## - set -Eeuo pipefail source "utils.sh" -trap 'TRAP_ERR $? $LINENO $BASH_LINENO "$BASH_COMMAND" `printf "::%s" ${FUNCNAME[@]:-}`' ERR -trap TRAP_EXIT EXIT -trap "TRAP_SIGNAL $? $LINENO" HUP INT TERM - PROGRAM_NAME="$0" -PROGRAM_VERSION="1.0.2" +PROGRAM_VERSION="1.0.3" ## Executable distro name EXEC_NAME="termux-alpine" ## Location of extracted rootfs -ROOTFS_DIR=${HOME}/alpine +ROOTFS_DIR=${HOME}/.alpine ## Location of binary files TERMUX_BIN=${PREFIX}/bin ## Running at distro @@ -31,6 +26,10 @@ MIRROR_PATHNAME="${MIRROR_URL}/alpine/latest-stable/releases" ## Colorize distro name DISTRO_NAME="${BLUE}Alpine Linux${RST}" +trap 'TRAP_ERR $? $LINENO $BASH_LINENO "$BASH_COMMAND" `printf "::%s" ${FUNCNAME[@]:-}`' ERR +trap TRAP_EXIT EXIT +trap "TRAP_SIGNAL $? $LINENO" HUP INT TERM + ## Checking the architecture for URL paths function check_architecture() { task "Checking the architecture" @@ -80,7 +79,7 @@ function check_integrity_rootfs() { sha256sum --check ${ROOTFS}.sha256 || die "Downloaded the rootfs file was corrupted or half downloaded, but don't worry, just run again" } function decompress_rootfs() { - task "Decompress the rootfs file, please be patient" + task "Decompress the rootfs file, please be patient..." proot --kill-on-exit --link2symlink tar --warning=no-unknown-keyword --delay-directory-restore --preserve-permissions -zxf "$ROOTFS" --exclude="dev"||: sleep 1s rm -f $ROOTFS ${ROOTFS}.sha256 @@ -184,8 +183,8 @@ function create_resolv() { local resolv="${ROOTFS_DIR}/etc/resolv.conf" [ -f "$resolv" ] && cp -n ${resolv}{,.bak} cat <<- EOF > "$resolv" - nameserver 1.1.1.1 - nameserver 1.0.0.1 + nameserver 8.8.8.8 + nameserver 8.8.4.4 EOF } ## Creating /etc/hosts file @@ -222,6 +221,7 @@ function create_bashrc() { shopt -s checkwinsize cdspell extglob # some aliases + alias e='exit' alias c='clear' alias r='reset' alias la='ls -A' # show hidden files @@ -310,9 +310,9 @@ function update_at_distro() { fi ## packages to install - local pkg="bash bash-completion sudo tzdata nano curl wget git openssh" + local pkg="bash bash-completion sudo tzdata curl wget git openssh nano vim neofetch" local up="Update, upgrade system and installed packages" - local ins="Installing ($pkg)" + local ins="Installing $pkg" if ask "Disable progress bar for updating?" then @@ -334,11 +334,19 @@ function update_at_distro() { sed -i "s/bin\/sh/bin\/bash/g" $LAUNCH_DISTRO } -## Installing nodejs-current, npm, and yarn +## Installing nodejs function install_nodejs() { - task "Installing nodejs-current, npm, and yarn" + local pkg="nodejs-current npm yarn" + task "Installing $pkg" + + $LAUNCH_DISTRO "apk add --update --no-cache $pkg" +} +## Installing python3 +function install_python3() { + local pkg="python3 py3-pip py3-wheel" + task "Installing $pkg" - $LAUNCH_DISTRO "apk add --no-progress --no-cache nodejs-current npm yarn" + $LAUNCH_DISTRO "apk add --update --no-cache $pkg" } function username_prompt { @@ -386,8 +394,12 @@ function setup_user() { else $LAUNCH_DISTRO "echo -ne \"$username ALL=(ALL) ALL\" > /etc/sudoers.d/${username} && chmod 0440 /etc/sudoers.d/${username}" fi - $LAUNCH_DISTRO "cp /etc/bash.bashrc /home/${username}/.bashrc && chown -R $username:$username /home/${username}/.bashrc" - unset -v username password + local user_dir="/home/${username}" + ## copy /etc/bash.bashrc to ~/.bashrc + $LAUNCH_DISTRO "cp /etc/bash.bashrc ${user_dir}/.bashrc && chown -R $username:$username ${user_dir}/.bashrc" + ## mkdir ~/bin and ~/.local/bin + $LAUNCH_DISTRO "mkdir -p ${user_dir}/bin && chown -R $username:$username ${user_dir}/bin && mkdir -p ${user_dir}/.local/bin && chown -R $username:$username ${user_dir}/.local/bin" + unset -v username password user_dir unset -f username_prompt password_prompt } @@ -396,11 +408,8 @@ function set_timezone() { #local TZ=`$LAUNCH_DISTRO "printenv TZ"` [ ! -z "$timezone" ] && $LAUNCH_DISTRO "[ -e \"/usr/share/zoneinfo/$timezone\" ] && ln -snf /usr/share/zoneinfo/${timezone} /etc/localtime && echo -ne \"$timezone\" > /etc/timezone" } - ## Add a welcome message function add_welcome() { - task "Add a welcome message" - local motd="${ROOTFS_DIR}/etc/motd" if [ -f "$motd" ]; then cp -n ${motd}{,.bak} @@ -493,8 +502,8 @@ function completed() echo -e "Default shell: ${GREEN}/bin/bash${RST}" echo echo -e "Tips after installing:" - echo -e "${GREEN}bash ${PROGRAM_NAME} --uninstall${RST} to uninstall" - echo -e "${GREEN}bash ${PROGRAM_NAME} --help${RST} for more" + echo -e "${GREEN}${PROGRAM_NAME} --uninstall${RST} to uninstall" + echo -e "${GREEN}${PROGRAM_NAME} --help${RST} for more" echo echo -e "Made with ${COFFEE} by illvart" echo "https://github.com/illvart/termux-alpine" @@ -504,10 +513,11 @@ function completed() function help() { echo - echo -e "Usage: ${GREEN}bash ${PROGRAM_NAME}${RST} [options]" + echo -e "Usage: ${GREEN}${PROGRAM_NAME}${RST} [options]" echo echo "Options:" echo -e "--install-nodejs install nodejs-current, npm, and yarn" + echo -e "--install-python3 install python3 py3-pip, and py3-wheel" echo -e "-S, --setup-user setup a non-root user" echo -e "-F, --fake-kernel use a fake kernel" echo -e "-u, --uninstall full wipe the rootfs installation" @@ -516,7 +526,7 @@ function help() echo } -declare opt_other="" opt_help="" opt_version="" opt_uninstall="" opt_setup_user="" opt_fake_kernel="" opt_add_nodejs="" +declare opt_other="" opt_help="" opt_version="" opt_uninstall="" opt_setup_user="" opt_fake_kernel="" opt_install_nodejs="" opt_install_python3="" for opts in "$@"; do case $opts in @@ -525,7 +535,8 @@ for opts in "$@"; do -u|--uninstall) opt_uninstall=true; shift ;; -S|--setup-user) opt_setup_user=true; shift ;; -F|--fake-kernel) opt_fake_kernel=true; shift ;; - --install-nodejs) opt_add_nodejs=true; shift ;; + --install-nodejs) opt_install_nodejs=true; shift ;; + --install-python3) opt_install_python3=true; shift ;; *) opt_other=("$1") ;; esac done @@ -534,7 +545,7 @@ if [ "$opt_other" ]; then echo echo -e "${RED}Unknown options${RST} ${opt_other}" echo - echo -e "Run ${GREEN}bash ${PROGRAM_NAME} --help${RST} to see available options." + echo -e "Run ${GREEN}${PROGRAM_NAME} --help${RST} to see available options." echo exit 1 elif [ "$opt_help" ]; then @@ -570,8 +581,8 @@ else task "Updating $DISTRO_NAME and install some packages..." divider update_at_distro - divider - [ "$opt_add_nodejs" ] && install_nodejs + [ "$opt_install_nodejs" ] && install_nodejs + [ "$opt_install_python3" ] && install_python3 [ "$opt_setup_user" ] && setup_user set_timezone add_welcome