install (5999B)
1 #!/bin/sh 2 # OUTDATED: USE Makefile 3 printf 'This script is outdated... Makefile is the future\n' 4 exit 2 5 # 6 # Install packages and config files to your machine. 7 # 8 CWD="${PWD}" 9 PACKAGES="$(sed -e 's/#.*//g' -e '/^\s*$/d' "packages.arch" | tr '\n' ' ')" 10 PACKAGES_PIP="ueberzug" 11 #PACKAGES_PIP="$(sed -e 's/#.*//g' -e '/^\s*$/d' "packages.pip" | tr '\n' ' ')" 12 13 CONFIG_LIST=".local .config .kshrc .mkshrc" 14 CONFIG_DEST="${HOME}" 15 CONFIG_BACK="${HOME}/.dotfiles.bak" 16 17 run_as_root() { 18 if [ "$(id -u)" -eq 0 ]; then 19 $@ 20 else 21 if command -v doas >/dev/null; then 22 doas $@ 23 elif command -v sudo >/dev/null; then 24 sudo $@ 25 else 26 su -c $@ 27 fi 28 fi 29 } 30 31 config_user() { 32 if [ "${1}" = "live" ]; then 33 CONFIG_DEST="${2}/etc/skel" 34 CONFIG_BACK="" 35 fi 36 printf "\033[32m[INFO] \033[36mConfiguring:\033[0m\n" 37 for CONFIG in ${CONFIG_LIST}; do 38 [ -r "$CONFIG" ] || continue; 39 FILE_SUFFIX="" 40 [ "$(file "$CONFIG" | sed 's/.* //g')" = "directory" ] && FILE_SUFFIX="/*" 41 if [ "${CONFIG_BACK}" ]; then 42 printf "\033[32m[INFO] \033[33mBacking '%s'\t->\t'%s'...\033[0m\n" \ 43 "${CONFIG}${FILE_SUFFIX}" "${CONFIG_BACK}/${CONFIG}" 44 for FILE in $(find "${CONFIG}" -type f); do 45 FILE_DIR="$(dirname "$FILE")" 46 if [ -f "${CONFIG_DEST}/${FILE}" ] && [ ! "$(diff "${CONFIG_DEST}/${FILE}" "${FILE}")" ] ; then 47 [ -d "${CONFIG_BACK}/${FILE_DIR}" ] || \ 48 mkdir -p "${CONFIG_BACK}/${FILE_DIR}" 49 cp "${FILE}" "${CONFIG_BACK}/${FILE_DIR}" 50 fi 51 done 52 fi 53 if [ "${CONFIG_DEST}" ]; then 54 printf "\033[32m[INFO] \033[34mCopying '%s'\t->\t'%s'...\033[0m\n" \ 55 "${CONFIG}${FILE_SUFFIX}" "${CONFIG_DEST}/${CONFIG}" 56 for FILE in $(find "${CONFIG}" -type f); do 57 FILE_DIR="$(dirname "$FILE")" 58 [ -d "${CONFIG_DEST}/${FILE_DIR}" ] || \ 59 mkdir -p "${CONFIG_DEST}/${FILE_DIR}" 60 cp "${FILE}" "${CONFIG_DEST}/${FILE}" 61 done 62 fi 63 done 64 65 mkdir -p "${CONFIG_DEST}/.local/share" 66 cd "${CONFIG_DEST}/.local/share" 67 for FILE in $(find . -name "*.tar.gz"); do 68 FILE="$(basename "$FILE")" 69 printf "\033[32m[INFO] \033[35mExtracting '%s'...\033[0m\n" "${CONFIG_DEST}/.local/share/$FILE" 70 tar -xzf "$FILE" 71 done 72 73 printf "\033[36m[QUES] Do you want to install Mahdi's suckless programs?: [y/N] \033[0m" 74 read ASK 75 case "$ASK" in 76 [Yy]|[Yy][Ee][Ss]) 77 [ -d "${CONFIG_DEST}/.local/src" ] || mkdir -p "${CONFIG_DEST}/.local/src" 78 for PROJ in dwm st dmenu tabbed slock; do 79 cd "${CONFIG_DEST}/.local/src" 80 [ -d "$PROJ" ] && (mkdir -p "${CONFIG_BACK}/.local/src" && mv "$PROJ" "${CONFIG_BACK}/.local/src") 81 git clone "git://mahdi.pw/${PROJ}.git" 82 cd "${PROJ}" 83 run_as_root make install 84 done 85 ;; 86 esac 87 88 printf "\033[32m[DONE] \033[36mConfiguration has been done.\033[0m\n" 89 } 90 91 config_repo() { 92 printf "\033[32m[INFO] \033[36mUpdating:\033[0m\n" 93 for CONFIG in ${CONFIG_LIST}; do 94 FILE_SUFFIX="" 95 [ "$(file "$CONFIG" | sed 's/.* //g')" = "directory" ] && FILE_SUFFIX="/*" 96 if [ "${CONFIG_DEST}" ]; then 97 [ -r "${CONFIG_DEST}/${CONFIG}" ] || continue; 98 #printf "\033[32m[INFO] \033[34mUpdating '%s'\t->\t'%s'...\033[0m\n" \ 99 # "${CONFIG_DEST}/${CONFIG}${FILE_SUFFIX}" "${CONFIG}" 100 for FILE in $(find "${CONFIG}" -type f); do 101 FILE_DIR="$(dirname "$FILE")" 102 [ -r "${CONFIG_DEST}/${FILE}" ] || continue; 103 printf "\033[32m[INFO] \033[34mUpdating '%s'\t->\t'%s'...\033[0m\n" \ 104 "${CONFIG_DEST}/${FILE}" "${FILE}" 105 cp -f "${CONFIG_DEST}/${FILE}" "${FILE}" 106 done 107 fi 108 done 109 110 cd "${CONFIG_DEST}/.local/share" 111 printf "\033[32m[INFO] \033[35mCompressing '%s' -> '%s'...\033[0m\n" \ 112 "${CONFIG_DEST}/.local/share/fonts/*" "${CONFIG_DEST}/.local/share/fonts.tar.gz" 113 tar -czf "fonts.tar.gz" "fonts" 114 printf "\033[32m[INFO] \033[34mUpdating '%s' -> '%s'...\033[0m\n" \ 115 "${CONFIG_DEST}/.local/share/fonts.tar.gz" "${CWD}/.local/share/fonts.tar.gz" 116 cp -f "${CONFIG_DEST}/.local/share/fonts.tar.gz" "${CWD}/.local/share/fonts.tar.gz" 117 cd "${CONFIG_DEST}/.local/share" 118 printf "\033[32m[INFO] \033[35mCompressing '%s' -> '%s'...\033[0m\n" \ 119 "${CONFIG_DEST}/.local/share/icons/*" "${CONFIG_DEST}/.local/share/icons.tar.gz" 120 tar -czf "icons.tar.gz" "icons" 121 printf "\033[32m[INFO] \033[34mUpdating '%s' -> '%s'...\033[0m\n" \ 122 "${CONFIG_DEST}/.local/share/icons.tar.gz" "${CWD}/.local/share/icons.tar.gz" 123 cp -f "${CONFIG_DEST}/.local/share/icons.tar.gz" "${CWD}/.local/share/icons.tar.gz" 124 125 printf "\033[32m[DONE] \033[36mUpdate has been done.\033[0m\n" 126 } 127 128 case "$1" in 129 [Ll]|[Ll][Ii][Vv][Ee]) 130 MOUNT="${2:-/mnt}" 131 pacstrap "${MOUNT}" ${PACKAGES} 132 arch-chroot "${MOUNT}" sh -c "pip install ${PACKAGES_PIP}" 133 config_user "live" "${MOUNT}" 134 ;; 135 [Ii]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]) 136 run_as_root pacman -Syq --needed --color=auto ${PACKAGES} 137 run_as_root pip install -q ${PACKAGES_PIP} 138 ;; 139 [Cc]|[Cc][Oo][Nn][Ff]|[Cc][Oo][Nn][Ff][Ii][Gg]) 140 config_user 141 ;; 142 [Cc][Rr]) 143 config_repo 144 ;; 145 *) 146 run_as_root pacman -Syq --needed --color=auto ${PACKAGES} || (printf "\033[31m[ERROR] This script can't run without a successful package manager installation.\033[0m\n" && exit 2) 147 run_as_root pip install -q ${PACKAGES_PIP} || (printf "\033[31m[ERROR] This script can't run without a successful package manager installation.\033[0m\n" && exit 2) 148 config_user 149 ;; 150 esac