mirror of
https://git.stupid.fish/teidesu/scripts.git
synced 2025-07-27 18:22:10 +10:00
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { readFile } from 'node:fs/promises'
|
|
import { join } from 'node:path'
|
|
import plist from 'plist'
|
|
import { z } from 'zod'
|
|
import { $ } from 'zx'
|
|
import { ffetch } from '../../utils/fetch.ts'
|
|
|
|
const latestVerInfo = await ffetch('https://api.github.com/repos/forkgram/tdesktop/releases/latest').parsedJson(
|
|
z.object({
|
|
tag_name: z.string().transform(v => v.replace(/^v/, '')),
|
|
assets: z.array(z.object({
|
|
name: z.string(),
|
|
browser_download_url: z.string(),
|
|
})),
|
|
}),
|
|
)
|
|
|
|
const INSTALL_PATH = '/Applications/Forkgram.app'
|
|
|
|
console.log('latest version:', latestVerInfo.tag_name)
|
|
|
|
const installedPlist = await readFile(join(INSTALL_PATH, 'Contents/Info.plist'), 'utf8')
|
|
const installedPlistParsed = z.object({
|
|
CFBundleShortVersionString: z.string(),
|
|
}).parse(plist.parse(installedPlist))
|
|
|
|
console.log('installed version:', installedPlistParsed.CFBundleShortVersionString)
|
|
|
|
if (installedPlistParsed.CFBundleShortVersionString === latestVerInfo.tag_name) {
|
|
console.log('✅ no update needed')
|
|
process.exit(0)
|
|
}
|
|
|
|
const arm64Asset = latestVerInfo.assets.find(asset => asset.name === 'Forkgram.macOS.no.auto-update_arm64.zip')
|
|
if (!arm64Asset) {
|
|
console.error('❌ no arm64 asset found')
|
|
process.exit(1)
|
|
}
|
|
|
|
console.log('installing new version...')
|
|
await $`curl -L ${arm64Asset.browser_download_url} -o /tmp/forkgram.zip`
|
|
await $`unzip -o /tmp/forkgram.zip -d /tmp/forkgram`
|
|
await $`kill -9 $(pgrep -f /Applications/Forkgram.app/Contents/MacOS/Telegram)`
|
|
await $`rm -rf ${INSTALL_PATH}`
|
|
await $`mv /tmp/forkgram/Telegram.app ${INSTALL_PATH}`
|
|
await $`rm -rf /tmp/forkgram`
|
|
await $`xattr -cr ${INSTALL_PATH}`
|
|
|
|
await $`open ${INSTALL_PATH}`
|
|
|
|
console.log('✅ done')
|