├── README.md ├── alpine.sh └── index.js /README.md: -------------------------------------------------------------------------------- 1 | # NetInstallAlpine 2 | A script to Net Install Alpine 3 | 4 | ## 系统要求 5 | - 支持Grub引导的Linux系统 6 | - 需提前安装Curl和OpenSSH 7 | 8 | ## 使用方法 9 | ``` 10 | sh <(curl -k 'https://cdn.jsdelivr.net/gh/52fancy/NetInstallAlpine/alpine.sh') 11 | ``` 12 | 13 | ## 自定义cloudflare文件上传接口 14 | - 新建Cloudflare Workers 和 Cloudflare KV 15 | - 在Cloudflare Workers ->设置 ->变量 ->KV 命名空间绑定 ->添加绑定 ->变量名称填写file ->KV 命名空间选择刚才新建的KV ->部署 16 | - 把index.js代码复制粘贴到Workers部署 17 | - 脚本密钥上传接口填写Workers域名即可 18 | 19 | ## 特别注意 OS<3.16.0 20 | 为了避免安装之后无法ssh登录服务器,请执行以下操作 21 | - 查看磁盘名称(例如:sda) 22 | ``` 23 | fdisk -l 24 | ``` 25 | 26 | - 挂载并允许root登录 27 | ``` 28 | mount /dev/sda3 /mnt 29 | sed -i "s/PermitRootLogin.*/PermitRootLogin yes/g" /mnt/etc/ssh/sshd_config 30 | umount /dev/sda3 31 | ``` 32 | 33 | - 重启即可 34 | ``` 35 | reboot 36 | ``` 37 | -------------------------------------------------------------------------------- /alpine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Check if user is root 4 | if [ "$(id -u)" != "0" ]; then 5 | echo "Error: You must be root to run this script" 6 | exit 1 7 | fi 8 | 9 | clear 10 | echo "+------------------------------------------------------------------------+" 11 | echo "| Alpine |" 12 | echo "+------------------------------------------------------------------------+" 13 | echo "| A script to Net Install Alpine |" 14 | echo "+------------------------------------------------------------------------+" 15 | echo "| Welcome to https://github.com/52Fancy |" 16 | echo "+------------------------------------------------------------------------+" 17 | 18 | read -p "请选择分支版本[默认latest-stable]:" branch 19 | branch=${branch:-latest-stable} 20 | echo "分支:${branch}" 21 | 22 | read -p "请选择密钥上传接口[默认file.io]:" loadKey 23 | loadKey=${loadKey:-https://file.io} 24 | echo "密钥上传接口:${loadKey}" 25 | 26 | read -p "请选择apk源[默认cdn]:" mirror 27 | mirror=${mirror:-https://dl-cdn.alpinelinux.org/alpine} 28 | echo "apk源:${mirror}" 29 | 30 | case "$(uname -m)" in 31 | x86_64) arch="x86_64" ;; 32 | i386|i686|x86) arch="x86" ;; 33 | armv8|armv8l|aarch64|arm64) arch="aarch64" ;; 34 | *) arch="$(uname -m)" ;; 35 | esac 36 | echo "系统平台:${arch}" 37 | 38 | read -p "是否开启VIRTUAL[y/n]:" flavor 39 | case "${flavor}" in 40 | y|Y|yes) flavor="virt"; echo "开启VIRTUAL" ;; 41 | *) flavor="lts"; echo "关闭VIRTUAL" ;; 42 | esac 43 | 44 | console=tty0 45 | yes | ssh-keygen -t ed25519 -N '' -f KEY 46 | if [ $? -ne 0 ]; then 47 | echo "请安装OpenSSH" 48 | exit 1 49 | fi 50 | ssh_key="$(curl -k -F "file=@KEY.pub" ${loadKey} | sed 's/.*"link":"//;s/".*//')" 51 | if [ $? -ne 0 ]; then 52 | echo "请安装Curl" 53 | exit 1 54 | fi 55 | 56 | version="$(curl -k ${mirror}/${branch}/releases/${arch}/latest-releases.yaml | grep version | sed -n 1p | sed 's/version: //g' | xargs echo -n)" 57 | if ! curl -k -f -# ${mirror}/${branch}/releases/${arch}/netboot/vmlinuz-${flavor} -o /boot/vmlinuz-${version}-netboot; then 58 | echo "Failed to download file!" 59 | exit 1 60 | fi 61 | 62 | if ! curl -k -f -# ${mirror}/${branch}/releases/${arch}/netboot/initramfs-${flavor} -o /boot/initramfs-${version}-netboot; then 63 | echo "Failed to download file!" 64 | exit 1 65 | fi 66 | 67 | cat > /etc/grub.d/40_custom << EOF 68 | #!/bin/sh 69 | exec tail -n +3 \$0 70 | # This file provides an easy way to add custom menu entries. Simply type the 71 | # menu entries you want to add after this comment. Be careful not to change 72 | # the 'exec tail' line above. 73 | menuentry 'Alpine' { 74 | linux /boot/vmlinuz-${version}-netboot alpine_repo="${mirror}/${branch}/main" modloop="${mirror}/${branch}/releases/${arch}/netboot/modloop-${flavor}" modules="loop,squashfs" initrd="initramfs-${version}-netboot" console="${console}" ssh_key="${ssh_key}" 75 | initrd /boot/initramfs-${version}-netboot 76 | } 77 | EOF 78 | 79 | if command -v grub-install >/dev/null 2>&1; then 80 | grub-mkconfig -o /boot/grub/grub.cfg 81 | grub-reboot Alpine 82 | elif command -v grub2-install >/dev/null 2>&1; then 83 | grub2-mkconfig -o /boot/grub2/grub.cfg 84 | grub2-reboot Alpine 85 | else 86 | echo "不支持当前系统" 87 | exit 1 88 | fi 89 | 90 | cat KEY 91 | echo "请自行下载或者保存私钥,然后重启服务器继续安装" 92 | echo "$(curl -k -F "file=@KEY" ${loadKey} | sed 's/.*"link":"//;s/".*//')" 93 | 94 | read -p "重启服务器[y/n]:" reboot 95 | if [ "${reboot}" = "y" ] || [ "${reboot}" = "yes" ] || [ "${reboot}" = "Y" ]; then 96 | reboot 97 | fi 98 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | export default { 2 | async fetch(request, env) { 3 | if (request.method == 'GET') { 4 | try { 5 | const code = request.url.split('/').pop(); 6 | if (code){ 7 | const value = await env.file.get(code) 8 | if (value == null) { 9 | return new Response("Value not found", {status: 404}) 10 | } 11 | return new Response(value) 12 | }else{ 13 | return new Response('Usage: curl -k -F "file=@文件" ' + request.url.slice(0, -1)) 14 | } 15 | }catch (e){ 16 | return new Response(e.message, {status: 500}) 17 | } 18 | } 19 | 20 | if (request.method == 'POST') { 21 | try { 22 | const formData = await request.formData() 23 | const file = formData.get('file') 24 | if (file){ 25 | const fileName = getName() 26 | await env.file.put(fileName, file.stream(), {expirationTtl: 300}) 27 | return new Response('"link":"' + request.url + fileName + '"' ) 28 | }else{ 29 | return new Response('Usage: curl -k -F "file=@文件" ' + request.url.slice(0, -1)) 30 | } 31 | }catch (e){ 32 | return new Response(e.message, {status: 500}) 33 | } 34 | } 35 | } 36 | } 37 | 38 | // 生成一个唯一的文件名 39 | function getName() { 40 | let randomString = ''; 41 | const alphabet = 'abcdefghijklmnopqrstuvwxyz' 42 | for (let i = 0; i < 5; i++) { 43 | randomString += alphabet.charAt(Math.floor(Math.random() * alphabet.length)) 44 | } 45 | return randomString + Date.now() 46 | } 47 | --------------------------------------------------------------------------------