This commit is contained in:
Luk 2026-01-26 19:03:26 +08:00
parent 25632ab024
commit cbe9d7ef85
5 changed files with 50 additions and 12 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
echo "---------------------------------------------"
echo "User Name (leave blank for no change as $(git config --get user.name)"
echo "Set [user name] or leave blank for unchanged \"$(git config --get user.name)\""
read -p "***:: " UserName
if [ $UserName ]
then
@ -10,7 +10,7 @@ then
fi
echo "---------------------------------------------"
echo "User Email (leave blank for no change as $(git config --get user.email))"
echo "User Email (leave blank for unchanged $(git config --get user.email))"
read -p "***:: " UserEmail
if [ $UserEmail ]
then
@ -20,7 +20,7 @@ fi
echo "---------------------------------------------"
echo "如果 git 远程服务器的 ssl 证书过期,或者使用了自颁发的证书,连接时会出现验证错误 Cannot verify local issuer"
echo "Verify ssl? (true or false, blank for no change as $(git config --get http.sslVerify))"
echo "Verify ssl? (true, false, or leave blank for unchanged $(git config --get http.sslVerify))"
read -p "***:: " HttpSslVerify
if [ $HttpSslVerify ]
then
@ -29,7 +29,7 @@ then
fi
echo "---------------------------------------------"
echo "Store credential in cache or store? (leave blank for no change as $(git config --get credential.helper))"
echo "Store credential in [cache] or [store]? (leave blank for unchanged $(git config --get credential.helper))"
read -p "***:: " CredentialHelper
if [ $CredentialHelper ]
then
@ -38,7 +38,7 @@ then
fi
echo "---------------------------------------------"
echo "Store pull rebase to true or false? (leave blank for no change as $(git config --get pull.rebase))"
echo "Store pull rebase to [true] or [false]? (leave blank for unchanged $(git config --get pull.rebase))"
read -p "***:: " PullRebase
if [ $PullRebase ]
then
@ -47,7 +47,7 @@ then
fi
echo "---------------------------------------------"
echo "Set [path to global gitignore file] (leave blank for no change as $(git config --get core.excludesfile))"
echo "Set [path to global gitignore file] or leave blank for unchanged $(git config --get core.excludesfile)"
read -p "***:: " ExcludesFile
if [ $ExcludesFile ]
then
@ -58,7 +58,7 @@ else
fi
echo "---------------------------------------------"
echo "Set default branch since git 2.28 to master or main? (leave blank for no change as $(git config --get init.defaultbranch))"
echo "Set default branch since git 2.28 to master or main? (leave blank for unchanged $(git config --get init.defaultbranch))"
read -p "***:: " DefaultBranch
if [ $DefaultBranch ]
then
@ -67,7 +67,7 @@ then
fi
echo "---------------------------------------------"
echo "Set postBuffer size? Suggesting 157286400 (leave blank for no change as $(git config --get http.postBuffer))"
echo "Set postBuffer size? Suggesting 157286400 (leave blank for unchanged $(git config --get http.postBuffer))"
read -p "***:: " PostBufferSize
if [ $PostBufferSize ]
then

16
mac-create-vdisk.plist Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>mac-create-vdisk</string>
<key>ProgramArguments</key>
<array>
<string>/etc/mac-create-vdisk.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>

18
mac-create-vdisk.sh Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
DISKNAME=vdisk
DISKSIZE=33554432 # 磁盘扇区数,每个扇区大小是 512 字节n*1024*1024*1024/512 = n Gigabytes. Do NOT set the formula to DISKSIZE.
# 虚拟磁盘并不是一创建就把内存空间划走,而是等到真正写入了虚拟磁盘的时候,才会使用对应的内存空间,所以给虚拟磁盘分配大一点的空间是没有问题的
if [ -d /Volumes/$DISKNAME ]; then
echo 'Found /Volumes/$DISKNAME!'
else
DISKID=$(hdid -nomount ram://$DISKSIZE)
diskutil apfs create ${DISKID} $DISKNAME
fi
# copy this script to some public folder, e.g. `sudo cp this-script.sh /etc/`, because in my test, it doesn't work in /Users/...
# copy the corresponding plist file to /Library/LaunchDaemons/,
# optionally run `sudo launchctl load /Library/LaunchDaemons/my-launch-file.plist` immediately for test.

View File

@ -69,9 +69,6 @@ if [ -d "$HomePath" ]; then
# 由 root 指定新用户而创建的配置文件的 owner 是 root而不是新用户导致新用户无法读取该文件而密钥登录失败因此要重设 owner。
chown "$TheUser:$TheUser" "$HomePath/.ssh"
fi
if [ -f "$HomePath/.ssh/authorized_keys" ] || [ -L "$HomePath/.ssh/authorized_keys" ]; then
mv "$HomePath/.ssh/authorized_keys" "$HomePath/.ssh/authorized_keys.backup-$(date -u +%Y%m%dT%H%M%Sutc)"
fi
echo "::*** Append or link or omit [[$HomePath/.ssh/authorized_keys]] to config ssh server? [a] for append, [l] for link, [anything else] for omit:"
read -p "***:: " AuthorizedKeys
@ -84,9 +81,16 @@ if [ -d "$HomePath" ]; then
echo "--- Copying [[$NIXHOME/authorized_keys]] to [[$HomePath/.ssh/authorized_keys]] ..."
cat "$NIXHOME/.ssh/authorized_keys" >> "$HomePath/.ssh/authorized_keys"
chmod 600 "$HomePath/.ssh/authorized_keys"
else
exit 0
fi
echo
if [ -f "$HomePath/.ssh/authorized_keys" ] || [ -L "$HomePath/.ssh/authorized_keys" ]; then
mv "$HomePath/.ssh/authorized_keys" "$HomePath/.ssh/authorized_keys.backup-$(date -u +%Y%m%dT%H%M%Sutc)"
fi
fi
popd

View File

@ -125,7 +125,7 @@ esac
# others:
# \w shows absolute path, \W shows current folder.
if [ "$color_prompt" = yes ]; then
PS1='[\[\033[07;32m\]\t\[\033[00m\]#\[\033[07;35m\]\u\[\033[00m\]@\[\033[07;31m\]\h|$(uname)|$(uname -m)\[\033[00m\]::\[\033[07;34m\]\w\[\033[00m\]] '
PS1='[\[\033[07;32m\]\t\[\033[00m\]#\[\033[07;35m\]\u\[\033[00m\]@\[\033[07;31m\]\h=$(uname)=$(uname -m)\[\033[00m\]::\[\033[07;34m\]\w\[\033[00m\]] '
else
PS1='[\t#\u@\h($(uname)-$(uname -m)):\w] ' # \w shows absolute path, \W shows current folder.
fi